--- Markdown.pl.orig Mon Jul 25 23:47:02 2005 +++ Markdown_dl.pl Thu Oct 6 23:11:14 2005 @@ -22,6 +22,7 @@ #use utf8; #binmode( STDOUT, ":utf8" ); # c.f.: http://acis.openlib.org/dev/perl-unicode-struggle.html +use Jcode; # # Global default settings: @@ -267,10 +268,22 @@ $text = _UnescapeSpecialChars($text); + use Jcode; + my $ten1 = jcode("¡¤")->utf8; + my $maru1 = jcode("¡¥")->utf8; + my $ten2 = jcode("¡¢")->utf8; + my $maru2 = jcode("¡£")->utf8; + $text =~ s/$ten1/$ten2/g; + $text =~ s/$maru1/$maru2/g; + + for my $level ( 3, 2, 1 ) { + $text =~ s|.*\S.*\n)+) # $3 = defined term + \n? + [ ]{0,$less_than_tab}:[ ]+ # colon starting definition + ) + (?s:.+?) + ( # $4 + \z + | + \n{2,} + (?=\S) + (?! # Negative lookahead for another term + [ ]{0,$less_than_tab} + (?: \S.*\n )+? # defined term + \n? + [ ]{0,$less_than_tab}:[ ]+ # colon starting definition + ) + (?! # Negative lookahead for another definition + [ ]{0,$less_than_tab}:[ ]+ # colon starting definition + ) + ) + ) + }mx; + + $text =~ s{(?:(?<=\n\n)|\A\n?)$whole_list}{ + # Re-usable patterns to match list item bullets and number markers: + my $list = $1; + $list =~ s/^\s+//s; + $list =~ s/\s+$//s; + my $result = _ProcessDefListItems($list); + + $result = "
\n$result\n
"; + $result . "\n\n"; + }mexg; + return $text; +} + +sub _ProcessDefListItems +{ +# +# Process the contents of a single ordered or unordered list, splitting it +# into individual list items. +# + my $list_str = shift; + my $less_than_tab = $g_tab_width - 1; + + # trim trailing blank lines: + $list_str =~ s/\n{2,}\\z/\n/g; + + # Process definition terms. + $list_str =~ s{ + (?:\n\n+|\A\n?) # leading line + ( # definition terms = $1 + [ ]{0,$less_than_tab} # leading whitespace + (?![:][ ]|[ ]) # negative lookahead for a definition + # mark (colon) or more whitespace. + (?: \S.* \n)+? # actual term (not whitespace). + ) + (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed + # with a definition mark. + }{ + my $terms = $1; + $terms =~ s/^\s+//s; + $terms =~ s/\s+$//s; + my @terms = split /\n/, $terms; + my $text = ''; + foreach my $term (@terms) { + $term =~ s/^\s+//s; + $term =~ s/\s+$//s; + $term = _RunSpanGamut($term); + $text .= "\n
" . $term . "
\n"; + } + $text; + }exmg; + + + # Process actual definitions. + $list_str =~ s{ + \n(\n+)? # leading line = $1 + [ ]{0,$less_than_tab} # whitespace before colon + [:][ ]+ # definition mark (colon) + ((?s:.+?)) # definition text = $2 + (?= \n+ # stop at next definition mark, + (?: # next term or end of text + [ ]{0,$less_than_tab} [:][ ] | +
| \z + ) | \z + ) + }{ + my $leading_line = $1; + my $def = $2; + + if ($leading_line or $def =~ /\n{2,}/) { + $def = _RunBlockGamut(_Outdent($def . "\n\n")); + $def = "\n". $def ."\n"; + } + else { + $def =~ s/\s+$//s; + $def = _RunSpanGamut(_Outdent($def)); + } + "\n
" . $def . "
\n"; + }exmg; + + return $list_str; +} +