Browse Source

Markdown.pl: recognize top-level lists better

The change in version 1.0.1 to fix "a bug where lines in the
middle of hard-wrapped paragraphs, which lines look like the
start of a list item, would accidentally trigger the creation
of a list," broke things like this:

  For example:
  * broken
  * microphone

That will now be recognized as a list again.  The heuristic is
now when two lines in a row start with the same type of list
marker then recognize that as a list even when the first item
doesn't appear to start its own paragraph.

Additionally if the second line is at the next indent level
then the two lines may have different kinds of list markers
and still be recognized.

All previously recognized lists are still recognized.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 7 years ago
parent
commit
b62cef825e
  1. 21
      Markdown.pl

21
Markdown.pl

@ -923,7 +923,9 @@ sub _DoLists {
# Form HTML ordered (numbered) and unordered (bulleted) lists.
#
my $text = shift;
my $less_than_indent = $opt{indent_width} - 1;
my $indent = $opt{indent_width};
my $less_than_indent = $indent - 1;
my $less_than_double_indent = 2 * $indent - 1;
# Re-usable pattern to match any entirel ul or ol list:
my $whole_list = qr{
@ -964,6 +966,10 @@ sub _DoLists {
# pattern will never change, and when this optimization isn't on, we run
# afoul of the reaper. Thus, the slightly redundant code to that uses two
# static s/// patterns rather than one conditional pattern.
#
# Note: (kjm) With the addition of the two-of-the-same-kind-in-a-row-
# starts-a-list-at-the-top-level rule the two patterns really are somewhat
# different now.
if ($g_list_level) {
$text =~ s{
@ -982,7 +988,18 @@ sub _DoLists {
}
else {
$text =~ s{
(?:(?<=\n\n)|\A\n?)
(?: (?<=\n\n) |
\A\n? |
(?:(?<=\n) # two of the same kind of marker lines
(?=[ ]{0,$less_than_indent}$marker_ul[ ].*\n
[ ]{0,$less_than_indent}$marker_ul[ ])) |
(?:(?<=\n) # in a row will start a list
(?=[ ]{0,$less_than_indent}$marker_ol[ ].*\n
[ ]{0,$less_than_indent}$marker_ol[ ])) |
(?:(?<=\n) # or any marker and a sublist marker
(?=[ ]{0,$less_than_indent}$marker_any[ ].*\n
[ ]{$indent,$less_than_double_indent}$marker_any[ ]))
)
$whole_list
}{
my $list = $1;

Loading…
Cancel
Save