Browse Source

Markdown.pl: carefully handle nested italics and bold

Be very careful to make sure that this:

    open **FILE*** with *write*

Does not turn into the broken:

    open <strong>FILE<em></strong> with *write</em>

But instead turns into the correct:

    open <strong>FILE*</strong> with <em>write</em>

Handle italics inside bold by nesting a callout that finishes
up by "hiding" any leftover bold/italics markup characters.

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

23
Markdown.pl

@ -2001,11 +2001,30 @@ sub _EncodeCode {
sub _DoItalicsAndBoldAndStrike {
my $text = shift;
my $doital1 = sub {
my $text = shift;
$text =~ s{ \* (?=\S) (.+?) (?<=\S) \* }
{<em>$1</em>}gsx;
# We've got to encode any of these remaining to
# avoid conflicting with other italics and bold.
$text =~ s!([*])!$g_escape_table{$1}!g;
$text;
};
my $doital2 = sub {
my $text = shift;
$text =~ s{ (?<!\w) _ (?=\S) (.+?) (?<=\S) _ (?!\w) }
{<em>$1</em>}gsx;
# We've got to encode any of these remaining to
# avoid conflicting with other italics and bold.
$text =~ s!([_])!$g_escape_table{$1}!g;
$text;
};
# <strong> must go first:
$text =~ s{ \*\* (?=\S) (.+?[*_]*) (?<=\S) \*\* }
{<strong>$1</strong>}gsx;
{"<strong>".&$doital1($1)."</strong>"}gsex;
$text =~ s{ (?<!\w) __ (?=\S) (.+?[*_]*) (?<=\S) __ (?!\w) }
{<strong>$1</strong>}gsx;
{"<strong>".&$doital2($1)."</strong>"}gsex;
$text =~ s{ ~~ (?=\S) (.+?[*_]*) (?<=\S) ~~ }
{<strike>$1</strike>}gsx;

Loading…
Cancel
Save