Keep wrapped list items in their bullet instead of orphaning the continuation
This commit is contained in:
@@ -134,6 +134,7 @@ function vv_docs_markdown(string $md, array $vars): string {
|
|||||||
$inCode = false;
|
$inCode = false;
|
||||||
$para = [];
|
$para = [];
|
||||||
$quote = [];
|
$quote = [];
|
||||||
|
$li = [];
|
||||||
|
|
||||||
$flushPara = function () use (&$para, &$out, $inline) {
|
$flushPara = function () use (&$para, &$out, $inline) {
|
||||||
if (!$para) return;
|
if (!$para) return;
|
||||||
@@ -145,7 +146,15 @@ function vv_docs_markdown(string $md, array $vars): string {
|
|||||||
$out .= '<blockquote>' . $inline(implode(' ', $quote)) . "</blockquote>\n";
|
$out .= '<blockquote>' . $inline(implode(' ', $quote)) . "</blockquote>\n";
|
||||||
$quote = [];
|
$quote = [];
|
||||||
};
|
};
|
||||||
$closeList = function () use (&$list, &$out) {
|
// A list item is buffered rather than emitted on sight, because markdown wraps: a bullet
|
||||||
|
// whose text runs onto the next line is one item, not an item followed by a paragraph.
|
||||||
|
$flushLi = function () use (&$li, &$out, $inline) {
|
||||||
|
if (!$li) return;
|
||||||
|
$out .= '<li>' . $inline(implode(' ', $li)) . "</li>\n";
|
||||||
|
$li = [];
|
||||||
|
};
|
||||||
|
$closeList = function () use (&$list, &$out, &$flushLi) {
|
||||||
|
$flushLi();
|
||||||
if ($list) { $out .= "</$list>\n"; $list = null; }
|
if ($list) { $out .= "</$list>\n"; $list = null; }
|
||||||
};
|
};
|
||||||
$closeTable = function () use (&$inTable, &$out) {
|
$closeTable = function () use (&$inTable, &$out) {
|
||||||
@@ -211,16 +220,23 @@ function vv_docs_markdown(string $md, array $vars): string {
|
|||||||
if (preg_match('/^[-*]\s+(.*)$/', $t, $m)) {
|
if (preg_match('/^[-*]\s+(.*)$/', $t, $m)) {
|
||||||
$flushPara();
|
$flushPara();
|
||||||
if ($list !== 'ul') { $closeList(); $out .= "<ul>\n"; $list = 'ul'; }
|
if ($list !== 'ul') { $closeList(); $out .= "<ul>\n"; $list = 'ul'; }
|
||||||
$out .= '<li>' . $inline($m[1]) . "</li>\n";
|
else { $flushLi(); }
|
||||||
|
$li[] = $m[1];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (preg_match('/^\d+\.\s+(.*)$/', $t, $m)) {
|
if (preg_match('/^\d+\.\s+(.*)$/', $t, $m)) {
|
||||||
$flushPara();
|
$flushPara();
|
||||||
if ($list !== 'ol') { $closeList(); $out .= "<ol>\n"; $list = 'ol'; }
|
if ($list !== 'ol') { $closeList(); $out .= "<ol>\n"; $list = 'ol'; }
|
||||||
$out .= '<li>' . $inline($m[1]) . "</li>\n";
|
else { $flushLi(); }
|
||||||
|
$li[] = $m[1];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lazy continuation: plain text directly under an open list item belongs to that item.
|
||||||
|
// Without this a wrapped bullet renders as a bullet plus an orphan paragraph, which is
|
||||||
|
// how the first version of this shipped.
|
||||||
|
if ($list && $li) { $li[] = $t; continue; }
|
||||||
|
|
||||||
$para[] = $t;
|
$para[] = $t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user