PHP code example of kraenzle-ritter / markdown-to-tei

1. Go to this page and download the library: Download kraenzle-ritter/markdown-to-tei library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kraenzle-ritter / markdown-to-tei example snippets



MarkdownToTei\Converter;
use MarkdownToTei\Config\ConversionConfig;

$config = new ConversionConfig();
$converter = new Converter($config);

$markdown = "# Title\n\nThis is a [supplied text] with **important** text.";
$teiXml = $converter->convert($markdown);

echo $teiXml;


// Configure TEI metadata
$config->setTeiSetting('title', 'My Document');
$config->setTeiSetting('author', 'Author Name');
$config->setTeiSetting('language', 'en');

// Add custom conventions
$config->addConvention('page_break', [
    'pattern' => '/\|p\.(\d+)\|/',
    'replacement' => '<pb n="$1"/>',
    'type' => 'regex'
]);

// Custom HTML to TEI mappings
$config->addMapping('h1', 'head[@type="chapter"]');

$tei = $converter->convert($markdown);

foreach ($converter->getWarnings() as $warning) {
    $logger->notice($warning);   // e.g. no mapping for element "h4", emitted as <div type="h4">
}