Fixing handling of list items with span-level content so that nested lists aren't passed through the span gamut.

This more principled approach should have no effect on the output other than prevent line breaks from appearing between the text of a list item and its nested list. It has become somewhat necessary after adding `hard_wrap`.
This commit is contained in:
Michel Fortin 2016-08-29 16:19:22 -04:00
parent 7f07fcacea
commit 8623708448
3 changed files with 17 additions and 9 deletions

View file

@ -1175,8 +1175,7 @@ class Markdown implements MarkdownInterface {
} else {
// Recursion for sub-lists:
$item = $this->doLists($this->outdent($item));
$item = preg_replace('/\n+$/', '', $item);
$item = $this->runSpanGamut($item);
$item = $this->formParagraphs($item, false);
}
return "<li>" . $item . "</li>\n";
@ -1476,10 +1475,11 @@ class Markdown implements MarkdownInterface {
/**
* Parse paragraphs
*
* @param string $text String to process with HTML <p> tags
* @param string $text String to process in paragraphs
* @param boolean $wrap_in_p Whether paragraphs should be wrapped in <p> tags
* @return string
*/
protected function formParagraphs($text) {
protected function formParagraphs($text, $wrap_in_p = true) {
// Strip leading and trailing lines:
$text = preg_replace('/\A\n+|\n+\z/', '', $text);
@ -1490,8 +1490,10 @@ class Markdown implements MarkdownInterface {
if (!preg_match('/^B\x1A[0-9]+B$/', $value)) {
// Is a paragraph.
$value = $this->runSpanGamut($value);
$value = preg_replace('/^([ ]*)/', "<p>", $value);
$value .= "</p>";
if ($wrap_in_p) {
$value = preg_replace('/^([ ]*)/', "<p>", $value);
$value .= "</p>";
}
$grafs[$key] = $this->unhash($value);
} else {
// Is a block.

View file

@ -1505,10 +1505,11 @@ class MarkdownExtra extends \Michelf\Markdown {
/**
* Parse text into paragraphs
* @param string $text String to process with html <p> tags
* @param string $text String to process in paragraphs
* @param boolean $wrap_in_p Whether paragraphs should be wrapped in <p> tags
* @return string HTML output
*/
protected function formParagraphs($text) {
protected function formParagraphs($text, $wrap_in_p = true) {
// Strip leading and trailing lines:
$text = preg_replace('/\A\n+|\n+\z/', '', $text);
@ -1520,7 +1521,7 @@ class MarkdownExtra extends \Michelf\Markdown {
// Check if this should be enclosed in a paragraph.
// Clean tag hashes & block tag hashes are left alone.
$is_p = !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value);
$is_p = $wrap_in_p && !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value);
if ($is_p) {
$value = "<p>$value</p>";

View file

@ -181,6 +181,11 @@ Current Version:
to the standard Markdown syntax these newlines are ignored unless they a
preceded by two spaces. Thanks to Jonathan Cohlmeyer for the implementation.
* Improved the parsing of list items to fix problematic cases that came to
light with the addition of `hard_wrap`. This should have no effect on the
output except span-level list items that ended with two spaces (and thus
ended with a line break).
* Added a `code_span_content_func` configuration variable which takes a
function that will convert the content of the code span to HTML. This can
be useful to implement syntax highlighting. Although contrary to its