Browse Source

Whitespace, formatting and miscellaneous cleanup

Cleanup whitespace throughout the code and Markdown sources.

Fix the formatting of the POD documentation so it looks nice
when formatted as either text or html.

Tidy up the license and copyright information.

Retain '<' and '>' around "auto" links.

Avoid using tabs when producing nested <blockquote>...</blockquote>
content.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 8 years ago
parent
commit
ee99f95215
  1. 4
      LICENSE
  2. 132
      Markdown.pl
  3. 10
      README
  4. 6
      basics.md
  5. 18
      syntax.md

4
LICENSE

@ -1,5 +1,5 @@
Copyright (C) 2004, John Gruber
Copyright (C) 2015, Kyle J. McKay
Copyright (C) 2004 John Gruber
Copyright (C) 2015,2016,2017 Kyle J. McKay
All rights reserved.
Redistribution and use in source and binary forms, with or without

132
Markdown.pl

@ -4,27 +4,37 @@
# Markdown -- A text-to-HTML conversion tool for web writers
#
# Copyright (C) 2004 John Gruber
# Copyright (C) 2015,2016 Kyle J. McKay
# Copyright (C) 2015,2016,2017 Kyle J. McKay
# All rights reserved.
# License is Modified BSD (aka 3-clause BSD) License\n";
# See LICENSE file (or <https://opensource.org/licenses/BSD-3-Clause>)
#
package Markdown;
require 5.006_000;
use strict;
use warnings;
use vars qw($COPYRIGHT $VERSION @ISA @EXPORT_OK);
BEGIN {*COPYRIGHT =
\"Copyright (C) 2004 John Gruber
Copyright (C) 2015,2016,2017 Kyle J. McKay
All rights reserved.
";
*VERSION = \"1.0.4+" # Sun 05 Jun 2016+
}
close(DATA) if fileno(DATA);
require Exporter;
use Digest::MD5 qw(md5_hex);
use File::Basename qw(basename);
use vars qw($VERSION @ISA @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(Markdown);
$INC{__PACKAGE__.'.pm'} = $INC{basename(__FILE__)} unless exists $INC{__PACKAGE__.'.pm'};
$VERSION = '1.0.4';
# Sun 05 Jun 2016
## Disabled; causes problems under Perl 5.6.1:
# use utf8;
@ -58,7 +68,7 @@ $g_nested_brackets = qr{
# Table of hash values for escaped characters:
my %g_escape_table;
foreach my $char (split //, "\\\`*_{}[]()>#+-.!~") {
foreach my $char (split //, "\\\`*_~{}[]()>#+-.!") {
$g_escape_table{$char} = md5_hex($char);
}
@ -213,9 +223,9 @@ elsif (!caller) {
exec 'perldoc', $0;
}
if ($cli_opts{'version'}) { # Version info
print "\nThis is Markdown, version $VERSION.\n";
print "Copyright (C) 2004 John Gruber\n";
print "Copyright (C) 2015 Kyle J. McKay\n";
print "\nThis is Markdown, version $VERSION.\n", $COPYRIGHT;
print "License is Modified BSD (aka 3-clause BSD) License\n";
print "<https://opensource.org/licenses/BSD-3-Clause>\n";
exit 0;
}
if ($cli_opts{'shortversion'}) { # Just the version number string.
@ -891,7 +901,7 @@ sub _DoLists {
# We use a different prefix before nested lists than top-level lists.
# See extended comment in _ProcessListItems().
#
# Note: There's a bit of duplication here. My original implementation
# Note: (jg) There's a bit of duplication here. My original implementation
# created a scalar regex pattern as the conditional result of the test on
# $g_list_level, and then only ran the $text =~ s{...}{...}egmx
# substitution once, using the scalar as the pattern. This worked,
@ -1169,14 +1179,14 @@ sub _DoBlockQuotes {
$bq =~ s/^[ \t]+$//mg; # trim whitespace-only lines
$bq = _RunBlockGamut($bq); # recurse
$bq =~ s/^/ /g;
$bq =~ s/^/ /mg;
# These leading spaces screw with <pre> content, so we need to fix that:
$bq =~ s{
(\s*<pre>.+?</pre>)
(\s*)(<pre>.+?</pre>)
}{
my $pre = $1;
my ($indent, $pre) = ($1, $2);
$pre =~ s/^ //mg;
$pre;
$indent.$pre;
}egsx;
"<blockquote>\n$bq\n</blockquote>\n\n";
@ -1243,8 +1253,7 @@ sub _EncodeAmpsAndAngles {
sub _EncodeBackslashEscapes {
#
# Parameter: String.
# Returns: The string, with after processing the following backslash
# escape sequences.
# Returns: String after processing the following backslash escape sequences.
#
local $_ = shift;
@ -1273,7 +1282,7 @@ sub _EncodeBackslashEscapes {
sub _DoAutoLinks {
my $text = shift;
$text =~ s{<((https?|ftp):[^'\042>\s]+)>}{<a href="$1">$1</a>}gi;
$text =~ s{<((https?|ftp):[^'\042>\s]+)>}{&lt;<a href="$1">$1</a>&gt;}gi;
# Email addresses: <address@domain.foo>
$text =~ s{
@ -1286,7 +1295,7 @@ sub _DoAutoLinks {
)
>
}{
_EncodeEmailAddress( _UnescapeSpecialChars($1) );
"&lt;"._EncodeEmailAddress( _UnescapeSpecialChars($1) )."&gt;";
}egix;
return $text;
@ -1449,8 +1458,7 @@ __DATA__
=head1 NAME
B<Markdown>
Markdown.pl - convert Markdown format text files to HTML
=head1 SYNOPSIS
@ -1471,8 +1479,8 @@ specifically to serve as a front-end to (X)HTML. You can use span-level
HTML tags anywhere in a Markdown document, and you can use block level
HTML tags (like <div> and <table> as well).
For more information about Markdown's syntax, see the `basics.text`
and `syntax.text` files included with `Markdown.pl`.
For more information about Markdown's syntax, see the F<basics.md>
and F<syntax.md> files included with F<Markdown.pl>.
=head1 OPTIONS
@ -1481,7 +1489,7 @@ Use "--" to end switch parsing. For example, to open a file named "-z", use:
Markdown.pl -- -z
=over 4
=over
=item B<--html4tags>
@ -1526,53 +1534,91 @@ Display Markdown's help.
=head1 VERSION HISTORY
See the readme file for detailed release notes for this version.
Z<> See the F<README> file for detailed release notes for this version.
1.0.4 - 05 Jun 2016
=over
1.0.3 - 06 Sep 2015
=item Z<> 1.0.4 - 05 Jun 2016
1.0.2 - 03 Sep 2015
=item Z<> 1.0.3 - 06 Sep 2015
1.0.1 - 14 Dec 2004
=item Z<> 1.0.2 - 03 Sep 2015
1.0 - 28 Aug 2004
=item Z<> 1.0.1 - 14 Dec 2004
=item Z<> 1.0.0 - 28 Aug 2004
=back
=head1 AUTHORS
John Gruber
http://daringfireball.net
http://daringfireball.net/projects/markdown/
=over
=item John Gruber
=item L<http://daringfireball.net>
PHP port and other contributions by Michel Fortin
http://michelf.com
=item L<http://daringfireball.net/projects/markdown/>
Additional enhancements and tweaks by Kyle J. McKay
mackyle<at>gmail.com
=item E<160>
=back
=over
=item PHP port and other contributions by Michel Fortin
=item L<http://michelf.com>
=item E<160>
=back
=over
=item Additional enhancements and tweaks by Kyle J. McKay
=item mackyle<at>gmail.com
=back
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2003-2004 John Gruber
Copyright (C) 2015,2016 Kyle J. McKay
All rights reserved.
=over
=item Copyright (C) 2003-2004 John Gruber
=item Copyright (C) 2015,2016 Kyle J. McKay
=item All rights reserved.
=back
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
=over
=item *
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
=item *
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name "Markdown" nor the names of its contributors may
=item *
Neither the name "Markdown" nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
=back
This software is provided by the copyright holders and contributors "as
is" and any express or implied warranties, including, but not limited
to, the implied warranties of merchantability and fitness for a

10
README

@ -23,7 +23,7 @@ script -- which means it can also be used as a text filter in BBEdit
(or any other application that supporst filters written in Perl).
Full documentation of Markdown's syntax and configuration options is
available in the basics.text and syntax.text files.
available in the `basics.md` and `syntax.md` files.
(Note: this readme file and the basics and syntax files are formatted
in Markdown.)
@ -152,7 +152,7 @@ publish the raw Markdown-formatted text without translation into
Use the `--html4tags` command-line switch to produce HTML output from a
Unix-style command line. E.g.:
% perl Markdown.pl --html4tags foo.text
% perl Markdown.pl --html4tags foo.txt
Type `perldoc Markdown.pl`, or read the POD documentation within the
Markdown.pl source code for more information.
@ -302,8 +302,8 @@ Version History
which isn't valid. (Thanks to Michel Fortin for the fix.)
+ Added a new substitution in `_EncodeCode()`: s/\$/&#036;/g; This
is only for the benefit of Blosxom users, because Blosxom
+ Added a new substitution in `_EncodeCode()`: `s/\$/&#036;/g`;
this is only for the benefit of Blosxom users, because Blosxom
(sometimes?) interpolates Perl scalars in your article bodies.
+ Fixed problem for links defined with urls that include parens, e.g.:
@ -333,7 +333,7 @@ Copyright and License
---------------------
Copyright (C) 2003-2004 John Gruber
Copyright (C) 2015 Kyle J. McKay
Copyright (C) 2015-2017 Kyle J. McKay
All rights reserved.
Redistribution and use in source and binary forms, with or without

6
basics.md

@ -4,7 +4,7 @@ Markdown: Basics
<ul id="ProjectSubmenu">
<li><a class="selected" title="Markdown Basics">Basics</a></li>
<li><a href="syntax.html" title="Markdown Syntax Documentation">Syntax</a></li>
<li><a href="License.html" title="License Information">License</a></li>
<li><a href="LICENSE.html" title="License Information">License</a></li>
</ul>
@ -23,10 +23,10 @@ web application that allows you type your own Markdown-formatted text
and translate it to XHTML.
**Note:** This document is itself written using Markdown; you
can [see the source for it by adding '.text' to the URL] [src].
can [see the source for it by adding `.md` to the URL] [src].
[s]: syntax.html "Markdown Syntax"
[src]: basics.text
[src]: basics.md
## Paragraphs, Headers, Blockquotes ##

18
syntax.md

@ -30,12 +30,12 @@ Markdown: Syntax
**Note:** This document is itself written using Markdown; you
can [see the source for it by adding '.text' to the URL][src].
can [see the source for it by adding `.md` to the URL][src].
[b]: basics.html "Markdown Basics"
[src]: syntax.text
[src]: syntax.md
* * *
- - - - -
<h2 id="overview">Overview</h2>
@ -174,7 +174,7 @@ terrible format for writing about HTML syntax, because every single `<`
and `&` in your example code needs to be escaped.)
* * *
- - - - -
<h2 id="block">Block Elements</h2>
@ -579,7 +579,7 @@ following lines will produce a horizontal rule:
---------------------------------------
* * *
- - - - -
<h2 id="span">Span Elements</h2>
@ -754,7 +754,7 @@ E.g., this input:
__double underscores__
~~strike through~~
~~double tildes~~
will produce:
@ -786,7 +786,6 @@ escape it:
\*this text is surrounded by literal asterisks\*
<h3 id="code">Code</h3>
To indicate a span of code, wrap it with backtick quotes (`` ` ``).
@ -842,7 +841,6 @@ to produce:
equivalent of <code>&amp;mdash;</code>.</p>
<h3 id="img">Images</h3>
Admittedly, it's fairly difficult to devise a "natural" syntax for
@ -880,7 +878,7 @@ dimensions of an image; if this is important to you, you can simply
use regular HTML `<img>` tags.
* * *
- - - - -
<h2 id="misc">Miscellaneous</h2>
@ -934,6 +932,7 @@ Markdown provides backslash escapes for the following characters:
` backtick
* asterisk
_ underscore
~ tilde
{} curly braces
[] square brackets
() parentheses
@ -942,4 +941,3 @@ Markdown provides backslash escapes for the following characters:
- minus sign (hyphen)
. dot
! exclamation mark

Loading…
Cancel
Save