Browse Source

Markdown.pl: clean up whitespace issues

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

100
Markdown.pl

@ -38,9 +38,9 @@ my $g_tab_width = 4;
# "Mastering Regular Expressions", 2nd Ed., pp. 328-331. # "Mastering Regular Expressions", 2nd Ed., pp. 328-331.
my $g_nested_brackets; my $g_nested_brackets;
$g_nested_brackets = qr{ $g_nested_brackets = qr{
(?> # Atomic matching (?> # Atomic matching
[^\[\]]+ # Anything other than brackets [^\[\]]+ # Anything other than brackets
| |
\[ \[
(??{ $g_nested_brackets }) # Recursive set of nested brackets (??{ $g_nested_brackets }) # Recursive set of nested brackets
\] \]
@ -129,7 +129,7 @@ unless ($@) {
my $ctx = shift; my $ctx = shift;
my $raw = 0; my $raw = 0;
if (defined $ctx) { if (defined $ctx) {
my $output = $ctx->stash('markdown_output'); my $output = $ctx->stash('markdown_output');
if (defined $output && $output =~ m/^html/i) { if (defined $output && $output =~ m/^html/i) {
$g_empty_element_suffix = ">"; $g_empty_element_suffix = ">";
$ctx->stash('markdown_output', ''); $ctx->stash('markdown_output', '');
@ -164,7 +164,7 @@ unless ($@) {
my $text = shift; my $text = shift;
my $ctx = shift; my $ctx = shift;
if (defined $ctx) { if (defined $ctx) {
my $output = $ctx->stash('markdown_output'); my $output = $ctx->stash('markdown_output');
if (defined $output && $output eq 'html') { if (defined $output && $output eq 'html') {
$g_empty_element_suffix = ">"; $g_empty_element_suffix = ">";
} }
@ -242,8 +242,8 @@ sub Markdown {
# Standardize line endings: # Standardize line endings:
$text =~ s{\r\n}{\n}g; # DOS to Unix $text =~ s{\r\n}{\n}g; # DOS to Unix
$text =~ s{\r}{\n}g; # Mac to Unix $text =~ s{\r}{\n}g; # Mac to Unix
# Make sure $text ends with a couple of newlines: # Make sure $text ends with a couple of newlines:
$text .= "\n\n"; $text .= "\n\n";
@ -324,11 +324,11 @@ sub _HashHTMLBlocks {
my $block_tags_b = qr/p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math/; my $block_tags_b = qr/p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math/;
# First, look for nested blocks, e.g.: # First, look for nested blocks, e.g.:
# <div> # <div>
# <div> # <div>
# tags for inner block must be indented. # tags for inner block must be indented.
# </div> # </div>
# </div> # </div>
# #
# The outermost tags must start at the left margin for this to match, and # The outermost tags must start at the left margin for this to match, and
# the inner nested divs must be indented. # the inner nested divs must be indented.
@ -370,7 +370,7 @@ sub _HashHTMLBlocks {
"\n\n" . $key . "\n\n"; "\n\n" . $key . "\n\n";
}egmx; }egmx;
# Special case just for <hr />. It was easier to make a special case than # Special case just for <hr />. It was easier to make a special case than
# to make the other regex more complicated. # to make the other regex more complicated.
$text =~ s{ $text =~ s{
(?: (?:
(?<=\n\n) # Starting after a blank line (?<=\n\n) # Starting after a blank line
@ -381,7 +381,7 @@ sub _HashHTMLBlocks {
[ ]{0,$less_than_tab} [ ]{0,$less_than_tab}
<(hr) # start tag = $2 <(hr) # start tag = $2
\b # word break \b # word break
([^<>])*? # ([^<>])*? #
/?> # the matching end tag /?> # the matching end tag
[ \t]* [ \t]*
(?=\n{2,}|\Z) # followed by a blank line or end of document (?=\n{2,}|\Z) # followed by a blank line or end of document
@ -489,8 +489,8 @@ sub _EscapeSpecialChars {
my $tokens ||= _TokenizeHTML($text); my $tokens ||= _TokenizeHTML($text);
$text = ''; # rebuild $text from the tokens $text = ''; # rebuild $text from the tokens
# my $in_pre = 0; # Keep track of when we're inside <pre> or <code> tags. # my $in_pre = 0; # Keep track of when we're inside <pre> or <code> tags.
# my $tags_to_skip = qr!<(/?)(?:pre|code|kbd|script|math)[\s>]!; # my $tags_to_skip = qr!<(/?)(?:pre|code|kbd|script|math)[\s>]!;
foreach my $cur_token (@$tokens) { foreach my $cur_token (@$tokens) {
if ($cur_token->[0] eq "tag") { if ($cur_token->[0] eq "tag") {
@ -573,9 +573,9 @@ sub _DoAnchors {
($g_nested_brackets) # link text = $2 ($g_nested_brackets) # link text = $2
\] \]
\( # literal paren \( # literal paren
[ \t]* [ \t]*
<?(.*?)>? # href = $3 <?(.*?)>? # href = $3
[ \t]* [ \t]*
( # $4 ( # $4
(['"]) # quote char = $5 (['"]) # quote char = $5
(.*?) # Title = $6 (.*?) # Title = $6
@ -587,8 +587,8 @@ sub _DoAnchors {
my $result; my $result;
my $whole_match = $1; my $whole_match = $1;
my $link_text = $2; my $link_text = $2;
my $url = $3; my $url = $3;
my $title = $6; my $title = $6;
$url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid $url =~ s! \* !$g_escape_table{'*'}!gx; # We've got to encode these to avoid
$url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold. $url =~ s! _ !$g_escape_table{'_'}!gx; # conflicting with italics/bold.
@ -675,9 +675,9 @@ sub _DoImages {
(.*?) # alt text = $2 (.*?) # alt text = $2
\] \]
\( # literal paren \( # literal paren
[ \t]* [ \t]*
<?(\S+?)>? # src url = $3 <?(\S+?)>? # src url = $3
[ \t]* [ \t]*
( # $4 ( # $4
(['"]) # quote char = $5 (['"]) # quote char = $5
(.*?) # title = $6 (.*?) # title = $6
@ -690,10 +690,10 @@ sub _DoImages {
my $result; my $result;
my $whole_match = $1; my $whole_match = $1;
my $alt_text = $2; my $alt_text = $2;
my $url = $3; my $url = $3;
my $title = ''; my $title = '';
if (defined($6)) { if (defined($6)) {
$title = $6; $title = $6;
} }
$alt_text =~ s/"/&quot;/g; $alt_text =~ s/"/&quot;/g;
@ -721,7 +721,7 @@ sub _DoHeaders {
# Setext-style headers: # Setext-style headers:
# Header 1 # Header 1
# ======== # ========
# #
# Header 2 # Header 2
# -------- # --------
# #
@ -916,7 +916,7 @@ sub _ProcessListItems {
sub _DoCodeBlocks { sub _DoCodeBlocks {
# #
# Process Markdown `<pre><code>` blocks. # Process Markdown `<pre><code>` blocks.
# #
my $text = shift; my $text = shift;
@ -949,27 +949,27 @@ sub _DoCodeBlocks {
sub _DoCodeSpans { sub _DoCodeSpans {
# #
# * Backtick quotes are used for <code></code> spans. # * Backtick quotes are used for <code></code> spans.
# #
# * You can use multiple backticks as the delimiters if you want to # * You can use multiple backticks as the delimiters if you want to
# include literal backticks in the code span. So, this input: # include literal backticks in the code span. So, this input:
# #
# Just type ``foo `bar` baz`` at the prompt. # Just type ``foo `bar` baz`` at the prompt.
# #
# Will translate to: # Will translate to:
# #
# <p>Just type <code>foo `bar` baz</code> at the prompt.</p> # <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
# #
# There's no arbitrary limit to the number of backticks you # There's no arbitrary limit to the number of backticks you
# can use as delimters. If you need three consecutive backticks # can use as delimters. If you need three consecutive backticks
# in your code, use four for delimiters, etc. # in your code, use four for delimiters, etc.
# #
# * You can use spaces to get literal backticks at the edges: # * You can use spaces to get literal backticks at the edges:
# #
# ... type `` `bar` `` ... # ... type `` `bar` `` ...
# #
# Turns to: # Turns to:
# #
# ... type <code>`bar`</code> ... # ... type <code>`bar`</code> ...
# #
@ -982,10 +982,10 @@ sub _DoCodeSpans {
\1 # Matching closer \1 # Matching closer
(?!`) (?!`)
@ @
my $c = "$2"; my $c = "$2";
$c =~ s/^[ \t]*//g; # leading whitespace $c =~ s/^[ \t]*//g; # leading whitespace
$c =~ s/[ \t]*$//g; # trailing whitespace $c =~ s/[ \t]*$//g; # trailing whitespace
$c = _EncodeCode($c); $c = _EncodeCode($c);
"<code>$c</code>"; "<code>$c</code>";
@egsx; @egsx;
@ -1009,9 +1009,9 @@ sub _EncodeCode {
# (Blosxom interpolates Perl variables in article bodies.) # (Blosxom interpolates Perl variables in article bodies.)
{ {
no warnings 'once'; no warnings 'once';
if (defined($blosxom::version)) { if (defined($blosxom::version)) {
s/\$/&#036;/g; s/\$/&#036;/g;
} }
} }
@ -1126,10 +1126,10 @@ sub _EncodeAmpsAndAngles {
# Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin: # Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
# http://bumppo.net/projects/amputator/ # http://bumppo.net/projects/amputator/
$text =~ s/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/&amp;/g; $text =~ s/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/&amp;/g;
# Encode naked <'s # Encode naked <'s
$text =~ s{<(?![a-z/?\$!])}{&lt;}gi; $text =~ s{<(?![a-z/?\$!])}{&lt;}gi;
return $text; return $text;
} }
@ -1416,8 +1416,8 @@ See the readme file for detailed release notes for this version.
=head1 COPYRIGHT AND LICENSE =head1 COPYRIGHT AND LICENSE
Copyright (c) 2003-2004 John Gruber Copyright (c) 2003-2004 John Gruber
<http://daringfireball.net/> <http://daringfireball.net/>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

Loading…
Cancel
Save