' . $this->renderInline(trim(implode(' ', $paragraph)), $context) . '

'; $paragraph = []; }; $closeList = function () use (&$html, &$listType): void { if ('' === $listType) { return; } $html[] = ''; $listType = ''; }; foreach ($lines as $line) { if (preg_match('/^\s*```/', $line)) { if ($codeFence) { $html[] = '
' . esc_html(implode("\n", $code)) . '
'; $code = []; $codeFence = false; } else { $flushParagraph(); $closeList(); $codeFence = true; } continue; } if ($codeFence) { $code[] = $line; continue; } if ('' === trim($line)) { $flushParagraph(); $closeList(); continue; } if (preg_match('/^(#{1,6})\s+(.+)$/', $line, $matches)) { $flushParagraph(); $closeList(); $level = strlen($matches[1]); $text = trim($matches[2]); $id = sanitize_title(wp_strip_all_tags($text)); $html[] = sprintf('%s', $level, esc_attr($id), $this->renderInline($text, $context), $level); continue; } if (preg_match('/^\s*[-*]\s+(.+)$/', $line, $matches)) { $flushParagraph(); if ('ul' !== $listType) { $closeList(); $html[] = '