Skip to content

Commit

Permalink
Tap stops after list markers properly computed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkende committed Apr 6, 2024
1 parent 2cabfaa commit 2bac801
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Revision history for pmarkdown and the Markdown::Perl module.
- Improvement to the support of the original markdown syntax.
- Bugfixes:
- Do not make a list loose when it is followed by blank lines.
- Tab stops after list markers are properly computed.

1.01 - 2024-04-05

Expand Down
8 changes: 6 additions & 2 deletions lib/Markdown/Perl/BlockParser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,13 @@ sub _do_list_item {
# There is a note in the spec on thematic breaks that are not list items,
# it’s not exactly clear what is intended, and there are no examples.
my ($indent_outside, $marker, $text, $digits, $symbol) = @+{qw(indent marker text digits symbol)};
my $indent_marker = length($indent_outside) + length($marker);
my $type = $marker =~ m/[-+*]/ ? 'ul' : 'ol';
my $text_indent = indent_size($text);
# The $indent_marker is passed in case the text starts with tabs, to properly
# compute the tab stops. This is better than nothing but won’t work inside
# other container blocks. In all cases, using tabs instead of space should not
# be encouraged.
my $text_indent = indent_size($text, $indent_marker);
# When interrupting a paragraph, the rules are stricter.
my $mode = $this->get_lists_can_interrupt_paragraph;
if (@{$this->{paragraph}}) {
Expand All @@ -622,7 +627,6 @@ sub _do_list_item {
my $first_line_blank = $text =~ m/^[ \t]*$/;
my $discard_text_indent = $first_line_blank || indented(4 + 1, $text); # 4 + 1 is an indented code block, plus the required space after marker.
my $indent_inside = $discard_text_indent ? 1 : $text_indent;
my $indent_marker = length($indent_outside) + length($marker);
my $indent = $indent_inside + $indent_marker;
my $cond = sub {
if ($first_line_blank && m/^[ \t]*$/) {
Expand Down
9 changes: 9 additions & 0 deletions lib/Markdown/Perl/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,21 @@ sub remove_prefix_spaces {
}

# Return the indentation of the given text
# indent_size($str, $prev_indent)
#
# Sets pos($_[0]) to the first non-whitespace character.
# $prev_indent can be passed if the $str is not the beginning of the logical
# line, to properly compute the tab stops.
# TODO: this feature is used when parsing list_items, but could be used in many
# other places too.
sub indent_size { ## no critic (RequireArgUnpacking)
pos($_[0]) = 0;
my $t = () = $_[0] =~ m/\G( {0,3}\t| {4})/gc; # Forcing list context.
$_[0] =~ m/\G( *)/g;
my $s = length($1); ## no critic (ProhibitCaptureWithoutTest)
if (substr($_[0], 0, 1) eq "\t" && @_ > 1) {
$s -= $_[1] % 4;
}
return $t * 4 + $s;
}

Expand Down
1 change: 1 addition & 0 deletions t/303-lists.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ sub run {
}

is(run("* a\n* b\n* c\n\n\nfoo"), "<ul>\n<li>a</li>\n<li>b</li>\n<li>c</li>\n</ul>\n<p>foo</p>\n", 'list is tight');
is(run("1.\tfoo\n\n\tbar"), "<ol>\n<li><p>foo</p>\n<p>bar</p>\n</li>\n</ol>\n", 'indent_with_tabs_after_marker');

done_testing;
2 changes: 1 addition & 1 deletion t/902-markdown-test-suite.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use MmdTest;
use Test2::V0;

# TODO: remove these todos.
my %opt = (todo => [16, 18, 20, 21, 22]);
my %opt = (todo => [16, 18, 21, 22]);

while ($_ = shift) {
$opt{test_num} = shift @ARGV if /^-n$/;
Expand Down

0 comments on commit 2bac801

Please sign in to comment.