Browse Source

Markdown.pl: improve atx-style header handling

Treat more than 6 consecutive '#'s as not a header.

Allow blank headers to be recognized which can be used for
spacers and/or formatting breaks.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 5 years ago
parent
commit
4be5dfd8e3
  1. 13
      Markdown.pl

13
Markdown.pl

@ -1364,7 +1364,7 @@ sub _MakeAnchorId {
sub _GetNewAnchorId { sub _GetNewAnchorId {
my $link = _strip(lc(shift)); my $link = _strip(lc(shift));
return '' if defined($g_anchors{$link}); return '' if $link eq "" || defined($g_anchors{$link});
my $id = _MakeAnchorId($link); my $id = _MakeAnchorId($link);
return '' unless $id; return '' unless $id;
$g_anchors{$link} = '#'.$id; $g_anchors{$link} = '#'.$id;
@ -1444,15 +1444,16 @@ sub _DoHeaders {
$text =~ s{ $text =~ s{
^(\#{1,6}) # $1 = string of #'s ^(\#{1,6}) # $1 = string of #'s
[ ]* [ ]*
(.+?) # $2 = Header text ((?:(?:(?<![#])[^\s]|[^#\s]).*?)?) # $2 = Header text
[ ]* [ ]*
\#* # optional closing #'s (not counted)
\n+ \n+
}{ }{
my $h = $2;
my $h_level = length($1); my $h_level = length($1);
my $id = _GetNewAnchorId($h); my $h = $2;
&$geth1($h) if $h_level == 1; $h =~ s/#+$//;
$h =~ s/\s+$//;
my $id = $h eq "" ? "" : _GetNewAnchorId($h);
&$geth1($h) if $h_level == 1 && $h ne "";
$id = " id=\"$id\"" if $id ne ""; $id = " id=\"$id\"" if $id ne "";
"<h$h_level$id>" . _RunSpanGamut($h) . "</h$h_level>\n\n"; "<h$h_level$id>" . _RunSpanGamut($h) . "</h$h_level>\n\n";
}egmx; }egmx;

Loading…
Cancel
Save