transformer = $transformer ?: new ShortcodeTransformer(); } public function render(string $adoc, array $context = []): string { $lines = preg_split('/\R/', $adoc) ?: []; $html = ''; $paragraph = []; $listOpen = false; $codeOpen = false; $code = []; $flushParagraph = function () use (&$html, &$paragraph, $context): void { if (! $paragraph) { return; } $text = implode(' ', array_map('trim', $paragraph)); $html .= '
' . $this->transformer->transformInline($text, $context) . '
' . "\n"; $paragraph = []; }; $closeList = static function () use (&$html, &$listOpen): void { if ($listOpen) { $html .= "\n"; $listOpen = false; } }; foreach ($lines as $line) { $trimmed = trim($line); if ('----' === $trimmed) { $flushParagraph(); $closeList(); if ($codeOpen) { $html .= '' . esc_html(implode("\n", $code)) . '' . "\n";
$code = [];
$codeOpen = false;
} else {
$codeOpen = true;
}
continue;
}
if ($codeOpen) {
$code[] = $line;
continue;
}
if ('' === $trimmed) {
$flushParagraph();
$closeList();
continue;
}
if (preg_match('/^:[A-Za-z0-9_-]+:\s*/', $trimmed)) {
continue;
}
if (preg_match('/^(={1,6})\s+(.+)$/', $trimmed, $matches)) {
$flushParagraph();
$closeList();
$level = min(6, strlen($matches[1]));
$html .= sprintf('