s around
# "paragraphs" that are wrapped in non-block-level tags, such as anchors,
# phrase emphasis, and spans. The list of tags we're looking for is
# hard-coded:
my $block_tags = qr{
(?:
p | div | h[1-6] | blockquote | pre | table |
dl | ol | ul | script | noscript | form |
fieldset | iframe | math | ins | del
)
}x;
my $tag_attrs = qr{
(?: # Match one attr name/value pair
\s+ # There needs to be at least some whitespace
# before each attribute name.
[\w.:_-]+ # Attribute name
\s*=\s*
(?:
".+?" # "Attribute value"
|
'.+?' # 'Attribute value'
|
[^\s]+? # AttributeValue (HTML5)
)
)* # Zero or more
}x;
my $empty_tag = qr{< \w+ $tag_attrs \s* />}oxms;
my $open_tag = qr{< $block_tags $tag_attrs \s* >}oxms;
my $close_tag = undef; # let Text::Balanced handle this
my $prefix_pattern = undef; # Text::Balanced
my $markdown_attr = qr{ \s* markdown \s* = \s* (['"]) (.*?) \1 }xs;
use Text::Balanced qw(gen_extract_tagged);
my $extract_block = gen_extract_tagged($open_tag, $close_tag, $prefix_pattern, { ignore => [$empty_tag] });
my @chunks;
# parse each line, looking for block-level HTML tags
while ($text =~ s{^(([ ]{0,$less_than_tab}<)?.*\n)}{}m) {
my $cur_line = $1;
if (defined $2) {
# current line could be start of code block
my ($tag, $remainder, $prefix, $opening_tag, $text_in_tag, $closing_tag) = $extract_block->($cur_line . $text);
if ($tag) {
if ($options->{interpret_markdown_on_attribute} and $opening_tag =~ s/$markdown_attr//i) {
my $markdown = $2;
if ($markdown =~ /^(1|on|yes)$/) {
# interpret markdown and reconstruct $tag to include the interpreted $text_in_tag
my $wrap_in_p_tags = $opening_tag =~ /^<(div|iframe)/;
$tag = $prefix . $opening_tag . "\n"
. $self->_RunBlockGamut($text_in_tag, {wrap_in_p_tags => $wrap_in_p_tags})
. "\n" . $closing_tag
;
} else {
# just remove the markdown="0" attribute
$tag = $prefix . $opening_tag . $text_in_tag . $closing_tag;
}
}
my $key = _md5_utf8($tag);
$self->{_html_blocks}{$key} = $tag;
push @chunks, "\n\n" . $key . "\n\n";
$text = $remainder;
}
else {
# No tag match, so toss $cur_line into @chunks
push @chunks, $cur_line;
}
}
else {
# current line could NOT be start of code block
push @chunks, $cur_line;
}
}
push @chunks, $text; # whatever is left
$text = join '', @chunks;
return $text;
}
sub _HashHR {
my ($self, $text) = @_;
my $less_than_tab = $self->{tab_width} - 1;
$text =~ s{
(?:
(?<=\n\n) # Starting after a blank line
| # or
\A\n? # the beginning of the doc
)
( # save in $1
[ ]{0,$less_than_tab}
<(hr) # start tag = $2
\b # word break
([^<>])*? #
/?> # the matching end tag
[ \t]*
(?=\n{2,}|\Z) # followed by a blank line or end of document
)
}{
my $key = _md5_utf8($1);
$self->{_html_blocks}{$key} = $1;
"\n\n" . $key . "\n\n";
}egx;
return $text;
}
sub _HashHTMLComments {
my ($self, $text) = @_;
my $less_than_tab = $self->{tab_width} - 1;
# Special case for standalone HTML comments:
$text =~ s{
(?:
(?<=\n\n) # Starting after a blank line
| # or
\A\n? # the beginning of the doc
)
( # save in $1
[ ]{0,$less_than_tab}
(?s:
)
[ \t]*
(?=\n{2,}|\Z) # followed by a blank line or end of document
)
}{
my $key = _md5_utf8($1);
$self->{_html_blocks}{$key} = $1;
"\n\n" . $key . "\n\n";
}egx;
return $text;
}
sub _HashPHPASPBlocks {
my ($self, $text) = @_;
my $less_than_tab = $self->{tab_width} - 1;
# PHP and ASP-style processor instructions (…?> and <%…%>)
$text =~ s{
(?:
(?<=\n\n) # Starting after a blank line
| # or
\A\n? # the beginning of the doc
)
( # save in $1
[ ]{0,$less_than_tab}
(?s:
<([?%]) # $2
.*?
\2>
)
[ \t]*
(?=\n{2,}|\Z) # followed by a blank line or end of document
)
}{
my $key = _md5_utf8($1);
$self->{_html_blocks}{$key} = $1;
"\n\n" . $key . "\n\n";
}egx;
return $text;
}
sub _RunBlockGamut {
#
# These are all the transformations that form block-level
# tags like paragraphs, headers, and list items.
#
my ($self, $text, $options) = @_;
# Do headers first, as these populate cross-refs
$text = $self->_DoHeaders($text);
# Do Horizontal Rules:
my $less_than_tab = $self->{tab_width} - 1;
$text =~ s{^[ ]{0,$less_than_tab}(\*[ ]?){3,}[ \t]*$}{\n
tags around block-level tags.
$text = $self->_HashHTMLBlocks($text);
# Special case just for
).
$text = $self->_DoAutoLinks($text);
$text = $self->_EncodeAmpsAndAngles($text);
$text = $self->_DoItalicsAndBold($text);
# FIXME - Is hard coding space here sane, or does this want to be related to tab width?
# Do hard breaks:
$text =~ s/ {2,}\n/
{empty_element_suffix}\n/g;
return $text;
}
sub _EscapeSpecialChars {
my ($self, $text) = @_;
my $tokens ||= $self->_TokenizeHTML($text);
$text = ''; # rebuild $text from the tokens
# my $in_pre = 0; # Keep track of when we're inside or tags.
# my $tags_to_skip = qr!<(/?)(?:pre|code|kbd|script|math)[\s>]!;
foreach my $cur_token (@$tokens) {
if ($cur_token->[0] eq "tag") {
# Within tags, encode * and _ so they don't conflict
# with their use in Markdown for italics and strong.
# We're replacing each such character with its
# corresponding MD5 checksum value; this is likely
# overkill, but it should prevent us from colliding
# with the escape values by accident.
$cur_token->[1] =~ s! \* !$g_escape_table{'*'}!ogx;
$cur_token->[1] =~ s! _ !$g_escape_table{'_'}!ogx;
$text .= $cur_token->[1];
} else {
my $t = $cur_token->[1];
$t = $self->_EncodeBackslashEscapes($t);
$text .= $t;
}
}
return $text;
}
sub _EscapeSpecialCharsWithinTagAttributes {
#
# Within tags -- meaning between < and > -- encode [\ ` * _] so they
# don't conflict with their use in Markdown for code, italics and strong.
# We're replacing each such character with its corresponding MD5 checksum
# value; this is likely overkill, but it should prevent us from colliding
# with the escape values by accident.
#
my ($self, $text) = @_;
my $tokens ||= $self->_TokenizeHTML($text);
$text = ''; # rebuild $text from the tokens
foreach my $cur_token (@$tokens) {
if ($cur_token->[0] eq "tag") {
$cur_token->[1] =~ s! \\ !$g_escape_table{'\\'}!gox;
$cur_token->[1] =~ s{ (?<=.)?code>(?=.) }{$g_escape_table{'`'}}gox;
$cur_token->[1] =~ s! \* !$g_escape_table{'*'}!gox;
$cur_token->[1] =~ s! _ !$g_escape_table{'_'}!gox;
}
$text .= $cur_token->[1];
}
return $text;
}
sub _DoAnchors {
#
# Turn Markdown link shortcuts into XHTML tags.
#
my ($self, $text) = @_;
#
# First, handle reference-style links: [link text] [id]
#
$text =~ s{
( # wrap whole match in $1
\[
($g_nested_brackets) # link text = $2
\]
[ ]? # one optional space
(?:\n[ ]*)? # one optional newline followed by spaces
\[
(.*?) # id = $3
\]
)
}{
my $whole_match = $1;
my $link_text = $2;
my $link_id = lc $3;
if ($link_id eq "") {
$link_id = lc $link_text; # for shortcut links like [this][].
}
$link_id =~ s{[ ]*\n}{ }g; # turn embedded newlines into spaces
$self->_GenerateAnchor($whole_match, $link_text, $link_id);
}xsge;
#
# Next, inline-style links: [link text](url "optional title")
#
$text =~ s{
( # wrap whole match in $1
\[
($g_nested_brackets) # link text = $2
\]
\( # literal paren
[ \t]*
($g_nested_parens) # href = $3
[ \t]*
( # $4
(['"]) # quote char = $5
(.*?) # Title = $6
\5 # matching quote
[ \t]* # ignore any spaces/tabs between closing quote and )
)? # title is optional
\)
)
}{
my $result;
my $whole_match = $1;
my $link_text = $2;
my $url = $3;
my $title = $6;
$self->_GenerateAnchor($whole_match, $link_text, undef, $url, $title);
}xsge;
#
# Last, handle reference-style shortcuts: [link text]
# These must come last in case you've also got [link test][1]
# or [link test](/foo)
#
$text =~ s{
( # wrap whole match in $1
\[
([^\[\]]+) # link text = $2; can't contain '[' or ']'
\]
)
}{
my $result;
my $whole_match = $1;
my $link_text = $2;
(my $link_id = lc $2) =~ s{[ ]*\n}{ }g; # lower-case and turn embedded newlines into spaces
$self->_GenerateAnchor($whole_match, $link_text, $link_id);
}xsge;
return $text;
}
sub _GenerateAnchor {
# FIXME - Fugly, change to named params?
my ($self, $whole_match, $link_text, $link_id, $url, $title, $attributes) = @_;
my $result;
$attributes = '' unless defined $attributes;
if ( !defined $url && defined $self->{_urls}{$link_id}) {
$url = $self->{_urls}{$link_id};
}
if (!defined $url) {
return $whole_match;
}
$url =~ s! \* !$g_escape_table{'*'}!gox; # We've got to encode these to avoid
$url =~ s! _ !$g_escape_table{'_'}!gox; # conflicting with italics/bold.
$url =~ s{^<(.*)>$}{$1}; # Remove <>'s surrounding URL, if present
$result = qq{{_titles}{$link_id} ) {
$title = $self->{_titles}{$link_id};
}
if ( defined $title ) {
$title =~ s/"/"/g;
$title =~ s! \* !$g_escape_table{'*'}!gox;
$title =~ s! _ !$g_escape_table{'_'}!gox;
$result .= qq{ title="$title"};
}
$result .= "$attributes>$link_text";
return $result;
}
sub _DoImages {
#
# Turn Markdown image shortcuts into
tags.
#
my ($self, $text) = @_;
#
# First, handle reference-style labeled images: ![alt text][id]
#
$text =~ s{
( # wrap whole match in $1
!\[
(.*?) # alt text = $2
\]
[ ]? # one optional space
(?:\n[ ]*)? # one optional newline followed by spaces
\[
(.*?) # id = $3
\]
)
}{
my $result;
my $whole_match = $1;
my $alt_text = $2;
my $link_id = lc $3;
if ($link_id eq '') {
$link_id = lc $alt_text; # for shortcut links like ![this][].
}
$self->_GenerateImage($whole_match, $alt_text, $link_id);
}xsge;
#
# Next, handle inline images: 
# Don't forget: encode * and _
$text =~ s{
( # wrap whole match in $1
!\[
(.*?) # alt text = $2
\]
\( # literal paren
[ \t]*
($g_nested_parens) # src url - href = $3
[ \t]*
( # $4
(['"]) # quote char = $5
(.*?) # title = $6
\5 # matching quote
[ \t]*
)? # title is optional
\)
)
}{
my $result;
my $whole_match = $1;
my $alt_text = $2;
my $url = $3;
my $title = '';
if (defined($6)) {
$title = $6;
}
$self->_GenerateImage($whole_match, $alt_text, undef, $url, $title);
}xsge;
return $text;
}
sub _GenerateImage {
# FIXME - Fugly, change to named params?
my ($self, $whole_match, $alt_text, $link_id, $url, $title, $attributes) = @_;
my $result;
$attributes = '' unless defined $attributes;
$alt_text ||= '';
$alt_text =~ s/"/"/g;
# FIXME - how about >
if ( !defined $url && defined $self->{_urls}{$link_id}) {
$url = $self->{_urls}{$link_id};
}
# If there's no such link ID, leave intact:
return $whole_match unless defined $url;
$url =~ s! \* !$g_escape_table{'*'}!ogx; # We've got to encode these to avoid
$url =~ s! _ !$g_escape_table{'_'}!ogx; # conflicting with italics/bold.
$url =~ s{^<(.*)>$}{$1}; # Remove <>'s surrounding URL, if present
if (!defined $title && length $link_id && defined $self->{_titles}{$link_id} && length $self->{_titles}{$link_id}) {
$title = $self->{_titles}{$link_id};
}
$result = qq{
{empty_element_suffix};
return $result;
}
sub _DoHeaders {
my ($self, $text) = @_;
# Setext-style headers:
# Header 1
# ========
#
# Header 2
# --------
#
$text =~ s{ ^(.+)[ \t]*\n=+[ \t]*\n+ }{
$self->_GenerateHeader('1', $1);
}egmx;
$text =~ s{ ^(.+)[ \t]*\n-+[ \t]*\n+ }{
$self->_GenerateHeader('2', $1);
}egmx;
# atx-style headers:
# # Header 1
# ## Header 2
# ## Header 2 with closing hashes ##
# ...
# ###### Header 6
#
my $l;
$text =~ s{
^(\#{1,6}) # $1 = string of #'s
[ \t]*
(.+?) # $2 = Header text
[ \t]*
\#* # optional closing #'s (not counted)
\n+
}{
my $h_level = length($1);
$self->_GenerateHeader($h_level, $2);
}egmx;
return $text;
}
sub _GenerateHeader {
my ($self, $level, $id) = @_;
return "" . $self->_RunSpanGamut($id) . "\n\n";
}
sub _DoLists {
#
# Form HTML ordered (numbered) and unordered (bulleted) lists.
#
my ($self, $text) = @_;
my $less_than_tab = $self->{tab_width} - 1;
# Re-usable patterns to match list item bullets and number markers:
my $marker_ul = qr/[*+-]/;
my $marker_ol = qr/\d+[.]/;
my $marker_any = qr/(?:$marker_ul|$marker_ol)/;
# Re-usable pattern to match any entirel ul or ol list:
my $whole_list = qr{
( # $1 = whole list
( # $2
[ ]{0,$less_than_tab}
(${marker_any}) # $3 = first list item marker
[ \t]+
)
(?s:.+?)
( # $4
\z
|
\n{2,}
(?=\S)
(?! # Negative lookahead for another list item marker
[ \t]*
${marker_any}[ \t]+
)
)
)
}mx;
# 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
# created a scalar regex pattern as the conditional result of the test on
# $self->{_list_level}, and then only ran the $text =~ s{...}{...}egmx
# substitution once, using the scalar as the pattern. This worked,
# everywhere except when running under MT on my hosting account at Pair
# Networks. There, this caused all rebuilds to be killed by the reaper (or
# perhaps they crashed, but that seems incredibly unlikely given that the
# same script on the same server ran fine *except* under MT. I've spent
# more time trying to figure out why this is happening than I'd like to
# admit. My only guess, backed up by the fact that this workaround works,
# is that Perl optimizes the substition when it can figure out that the
# pattern will never change, and when this optimization isn't on, we run
# afoul of the reaper. Thus, the slightly redundant code to that uses two
# static s/// patterns rather than one conditional pattern.
if ($self->{_list_level}) {
$text =~ s{
^
$whole_list
}{
my $list = $1;
my $marker = $3;
my $list_type = ($marker =~ m/$marker_ul/) ? "ul" : "ol";
# Turn double returns into triple returns, so that we can make a
# paragraph for the last item in a list, if necessary:
$list =~ s/\n{2,}/\n\n\n/g;
my $result = ( $list_type eq 'ul' ) ?
$self->_ProcessListItemsUL($list, $marker_ul)
: $self->_ProcessListItemsOL($list, $marker_ol);
$result = $self->_MakeList($list_type, $result, $marker);
$result;
}egmx;
}
else {
$text =~ s{
(?:(?<=\n\n)|\A\n?)
$whole_list
}{
my $list = $1;
my $marker = $3;
my $list_type = ($marker =~ m/$marker_ul/) ? "ul" : "ol";
# Turn double returns into triple returns, so that we can make a
# paragraph for the last item in a list, if necessary:
$list =~ s/\n{2,}/\n\n\n/g;
my $result = ( $list_type eq 'ul' ) ?
$self->_ProcessListItemsUL($list, $marker_ul)
: $self->_ProcessListItemsOL($list, $marker_ol);
$result = $self->_MakeList($list_type, $result, $marker);
$result;
}egmx;
}
return $text;
}
sub _MakeList {
my ($self, $list_type, $content, $marker) = @_;
if ($list_type eq 'ol' and $self->{trust_list_start_value}) {
my ($num) = $marker =~ /^(\d+)[.]/;
return "\n" . $content . "
\n";
}
return "<$list_type>\n" . $content . "$list_type>\n";
}
sub _ProcessListItemsOL {
#
# Process the contents of a single ordered list, splitting it
# into individual list items.
#
my ($self, $list_str, $marker_any) = @_;
# The $self->{_list_level} global keeps track of when we're inside a list.
# Each time we enter a list, we increment it; when we leave a list,
# we decrement. If it's zero, we're not in a list anymore.
#
# We do this because when we're not inside a list, we want to treat
# something like this:
#
# I recommend upgrading to version
# 8. Oops, now this line is treated
# as a sub-list.
#
# As a single paragraph, despite the fact that the second line starts
# with a digit-period-space sequence.
#
# Whereas when we're inside a list (or sub-list), that line will be
# treated as the start of a sub-list. What a kludge, huh? This is
# an aspect of Markdown's syntax that's hard to parse perfectly
# without resorting to mind-reading. Perhaps the solution is to
# change the syntax rules such that sub-lists must start with a
# starting cardinal number; e.g. "1." or "a.".
$self->{_list_level}++;
# trim trailing blank lines:
$list_str =~ s/\n{2,}\z/\n/;
$list_str =~ s{
(\n)? # leading line = $1
(^[ \t]*) # leading whitespace = $2
($marker_any) [ \t]+ # list marker = $3
((?s:.+?) # list item text = $4
(\n{1,2}))
(?= \n* (\z | \2 ($marker_any) [ \t]+))
}{
my $item = $4;
my $leading_line = $1;
my $leading_space = $2;
if ($leading_line or ($item =~ m/\n{2,}/)) {
$item = $self->_RunBlockGamut($self->_Outdent($item), {wrap_in_p_tags => 1});
}
else {
# Recursion for sub-lists:
$item = $self->_DoLists($self->_Outdent($item));
chomp $item;
$item = $self->_RunSpanGamut($item);
}
"" . $item . "\n";
}egmxo;
$self->{_list_level}--;
return $list_str;
}
sub _ProcessListItemsUL {
#
# Process the contents of a single unordered list, splitting it
# into individual list items.
#
my ($self, $list_str, $marker_any) = @_;
# The $self->{_list_level} global keeps track of when we're inside a list.
# Each time we enter a list, we increment it; when we leave a list,
# we decrement. If it's zero, we're not in a list anymore.
#
# We do this because when we're not inside a list, we want to treat
# something like this:
#
# I recommend upgrading to version
# 8. Oops, now this line is treated
# as a sub-list.
#
# As a single paragraph, despite the fact that the second line starts
# with a digit-period-space sequence.
#
# Whereas when we're inside a list (or sub-list), that line will be
# treated as the start of a sub-list. What a kludge, huh? This is
# an aspect of Markdown's syntax that's hard to parse perfectly
# without resorting to mind-reading. Perhaps the solution is to
# change the syntax rules such that sub-lists must start with a
# starting cardinal number; e.g. "1." or "a.".
$self->{_list_level}++;
# trim trailing blank lines:
$list_str =~ s/\n{2,}\z/\n/;
$list_str =~ s{
(\n)? # leading line = $1
(^[ \t]*) # leading whitespace = $2
($marker_any) [ \t]+ # list marker = $3
((?s:.+?) # list item text = $4
(\n{1,2}))
(?= \n* (\z | \2 ($marker_any) [ \t]+))
}{
my $item = $4;
my $leading_line = $1;
my $leading_space = $2;
if ($leading_line or ($item =~ m/\n{2,}/)) {
$item = $self->_RunBlockGamut($self->_Outdent($item), {wrap_in_p_tags => 1});
}
else {
# Recursion for sub-lists:
$item = $self->_DoLists($self->_Outdent($item));
chomp $item;
$item = $self->_RunSpanGamut($item);
}
"" . $item . "\n";
}egmxo;
$self->{_list_level}--;
return $list_str;
}
sub _DoCodeBlocks {
#
# Process Markdown code blocks (indented with 4 spaces or 1 tab):
# * outdent the spaces/tab
# * encode <, >, & into HTML entities
# * escape Markdown special characters into MD5 hashes
# * trim leading and trailing newlines
#
my ($self, $text) = @_;
$text =~ s{
(?:\n\n|\A)
( # $1 = the code block -- one or more lines, starting with a space/tab
(?:
(?:[ ]{$self->{tab_width}} | \t) # Lines must start with a tab or a tab-width of spaces
.*\n+
)+
)
((?=^[ ]{0,$self->{tab_width}}\S)|\Z) # Lookahead for non-space at line-start, or end of doc
}{
my $codeblock = $1;
my $result; # return value
$codeblock = $self->_EncodeCode($self->_Outdent($codeblock));
$codeblock = $self->_Detab($codeblock);
$codeblock =~ s/\A\n+//; # trim leading newlines
$codeblock =~ s/\n+\z//; # trim trailing newlines
$result = "\n\n" . $codeblock . "\n
\n\n";
$result;
}egmx;
return $text;
}
sub _DoCodeSpans {
#
# * Backtick quotes are used for
spans.
#
# * You can use multiple backticks as the delimiters if you want to
# include literal backticks in the code span. So, this input:
#
# Just type ``foo `bar` baz`` at the prompt.
#
# Will translate to:
#
# Just type foo `bar` baz
at the prompt.
#
# There's no arbitrary limit to the number of backticks you
# can use as delimters. If you need three consecutive backticks
# in your code, use four for delimiters, etc.
#
# * You can use spaces to get literal backticks at the edges:
#
# ... type `` `bar` `` ...
#
# Turns to:
#
# ... type `bar`
...
#
my ($self, $text) = @_;
$text =~ s@
(?_EncodeCode($c);
"$c
";
@egsx;
return $text;
}
sub _EncodeCode {
#
# Encode/escape certain characters inside Markdown code runs.
# The point is that in code, these characters are literals,
# and lose their special Markdown meanings.
#
my $self = shift;
local $_ = shift;
# Encode all ampersands; HTML entities are not
# entities within a Markdown code span.
s/&/&/g;
# Encode $'s, but only if we're running under Blosxom.
# (Blosxom interpolates Perl variables in article bodies.)
{
no warnings 'once';
if (defined($blosxom::version)) {
s/\$/$/g;
}
}
# Do the angle bracket song and dance:
s! < !<!gx;
s! > !>!gx;
# Now, escape characters that are magic in Markdown:
s! \* !$g_escape_table{'*'}!ogx;
s! _ !$g_escape_table{'_'}!ogx;
s! { !$g_escape_table{'{'}!ogx;
s! } !$g_escape_table{'}'}!ogx;
s! \[ !$g_escape_table{'['}!ogx;
s! \] !$g_escape_table{']'}!ogx;
s! \\ !$g_escape_table{'\\'}!ogx;
return $_;
}
sub _DoItalicsAndBold {
my ($self, $text) = @_;
# Handle at beginning of lines:
$text =~ s{ ^(\*\*|__) (?=\S) (.+?[*_]*) (?<=\S) \1 }
{$2}gsx;
$text =~ s{ ^(\*|_) (?=\S) (.+?) (?<=\S) \1 }
{$2}gsx;
# must go first:
$text =~ s{ (?<=\W) (\*\*|__) (?=\S) (.+?[*_]*) (?<=\S) \1 }
{$2}gsx;
$text =~ s{ (?<=\W) (\*|_) (?=\S) (.+?) (?<=\S) \1 }
{$2}gsx;
# And now, a second pass to catch nested strong and emphasis special cases
$text =~ s{ (?<=\W) (\*\*|__) (?=\S) (.+?[*_]*) (?<=\S) \1 }
{$2}gsx;
$text =~ s{ (?<=\W) (\*|_) (?=\S) (.+?) (?<=\S) \1 }
{$2}gsx;
return $text;
}
sub _DoBlockQuotes {
my ($self, $text) = @_;
$text =~ s{
( # Wrap whole match in $1
(
^[ \t]*>[ \t]? # '>' at the start of a line
.+\n # rest of the first line
(.+\n)* # subsequent consecutive lines
\n* # blanks
)+
)
}{
my $bq = $1;
$bq =~ s/^[ \t]*>[ \t]?//gm; # trim one level of quoting
$bq =~ s/^[ \t]+$//mg; # trim whitespace-only lines
$bq = $self->_RunBlockGamut($bq, {wrap_in_p_tags => 1}); # recurse
$bq =~ s/^/ /mg;
# These leading spaces screw with content, so we need to fix that:
$bq =~ s{
(\s*.+?
)
}{
my $pre = $1;
$pre =~ s/^ //mg;
$pre;
}egsx;
"\n$bq\n
\n\n";
}egmx;
return $text;
}
sub _FormParagraphs {
#
# Params:
# $text - string to process with html tags
#
my ($self, $text, $options) = @_;
# Strip leading and trailing lines:
$text =~ s/\A\n+//;
$text =~ s/\n+\z//;
my @grafs = split(/\n{2,}/, $text);
#
# Wrap
tags.
#
foreach (@grafs) {
unless (defined( $self->{_html_blocks}{$_} )) {
$_ = $self->_RunSpanGamut($_);
if ($options->{wrap_in_p_tags}) {
s/^([ \t]*)/
/;
$_ .= "
";
}
}
}
#
# Unhashify HTML blocks
#
foreach (@grafs) {
if (defined( $self->{_html_blocks}{$_} )) {
$_ = $self->{_html_blocks}{$_};
}
}
return join "\n\n", @grafs;
}
sub _EncodeAmpsAndAngles {
# Smart processing for ampersands and angle brackets that need to be encoded.
my ($self, $text) = @_;
return '' if (!defined $text or !length $text);
# Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
# http://bumppo.net/projects/amputator/
$text =~ s/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/&/g;
# Encode naked <'s
$text =~ s{<(?![a-z/?\$!])}{<}gi;
# And >'s - added by Fletcher Penney
# $text =~ s{>(?![a-z/?\$!])}{>}gi;
# Causes problems...
# Remove encoding inside comments
$text =~ s{
(?<=) # End comments
}{
my $t = $1;
$t =~ s/&/&/g;
$t =~ s/</ !$g_escape_table{'>'}!ogx;
s! \\\# !$g_escape_table{'#'}!ogx;
s! \\\+ !$g_escape_table{'+'}!ogx;
s! \\\- !$g_escape_table{'-'}!ogx;
s! \\\. !$g_escape_table{'.'}!ogx;
s{ \\! }{$g_escape_table{'!'}}ogx;
return $_;
}
sub _DoAutoLinks {
my ($self, $text) = @_;
$text =~ s{<((https?|ftp):[^'">\s]+)>}{$1}gi;
# Email addresses:
$text =~ s{
<
(?:mailto:)?
(
[-.\w\+]+
\@
[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
)
>
}{
$self->_EncodeEmailAddress( $self->_UnescapeSpecialChars($1) );
}egix;
return $text;
}
sub _EncodeEmailAddress {
#
# Input: an email address, e.g. "foo@example.com"
#
# Output: the email address as a mailto link, with each character
# of the address encoded as either a decimal or hex entity, in
# the hopes of foiling most address harvesting spam bots. E.g.:
#
# foo
# @example.com
#
# Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
# mailing list:
#
my ($self, $addr) = @_;
my @encode = (
sub { '' . ord(shift) . ';' },
sub { '' . sprintf( "%X", ord(shift) ) . ';' },
sub { shift },
);
$addr = "mailto:" . $addr;
$addr =~ s{(.)}{
my $char = $1;
if ( $char eq '@' ) {
# this *must* be encoded. I insist.
$char = $encode[int rand 1]->($char);
}
elsif ( $char ne ':' ) {
# leave ':' alone (to spot mailto: later)
my $r = rand;
# roughly 10% raw, 45% hex, 45% dec
$char = (
$r > .9 ? $encode[2]->($char) :
$r < .45 ? $encode[1]->($char) :
$encode[0]->($char)
);
}
$char;
}gex;
$addr = qq{$addr};
$addr =~ s{">.+?:}{">}; # strip the mailto: from the visible part
return $addr;
}
sub _UnescapeSpecialChars {
#
# Swap back in all the special characters we've hidden.
#
my ($self, $text) = @_;
while( my($char, $hash) = each(%g_escape_table) ) {
$text =~ s/$hash/$char/g;
}
return $text;
}
sub _TokenizeHTML {
#
# Parameter: String containing HTML markup.
# Returns: Reference to an array of the tokens comprising the input
# string. Each token is either a tag (possibly with nested,
# tags contained therein, such as , or a
# run of text between tags. Each element of the array is a
# two-element array; the first is either 'tag' or 'text';
# the second is the actual value.
#
#
# Derived from the _tokenize() subroutine from Brad Choate's MTRegex plugin.
#
#
my ($self, $str) = @_;
my $pos = 0;
my $len = length $str;
my @tokens;
my $depth = 6;
my $nested_tags = join('|', ('(?:<[a-z/!$](?:[^<>]') x $depth) . (')*>)' x $depth);
my $match = qr/(?s: ) | # comment
(?s: <\? .*? \?> ) | # processing instruction
$nested_tags/iox; # nested tags
while ($str =~ m/($match)/og) {
my $whole_tag = $1;
my $sec_start = pos $str;
my $tag_start = $sec_start - length $whole_tag;
if ($pos < $tag_start) {
push @tokens, ['text', substr($str, $pos, $tag_start - $pos)];
}
push @tokens, ['tag', $whole_tag];
$pos = pos $str;
}
push @tokens, ['text', substr($str, $pos, $len - $pos)] if $pos < $len;
\@tokens;
}
sub _Outdent {
#
# Remove one level of line-leading tabs or spaces
#
my ($self, $text) = @_;
$text =~ s/^(\t|[ ]{1,$self->{tab_width}})//gm;
return $text;
}
sub _Detab {
#
# Cribbed from a post by Bart Lateur:
#
#
my ($self, $text) = @_;
# FIXME - Better anchor/regex would be quicker.
# Original:
#$text =~ s{(.*?)\t}{$1.(' ' x ($self->{tab_width} - length($1) % $self->{tab_width}))}ge;
# Much swifter, but pretty hateful:
do {} while ($text =~ s{^(.*?)\t}{$1.(' ' x ($self->{tab_width} - length($1) % $self->{tab_width}))}mge);
return $text;
}
sub _ConvertCopyright {
my ($self, $text) = @_;
# Convert to an XML compatible form of copyright symbol
$text =~ s/©/©/gi;
return $text;
}
1;
__END__
=head1 OTHER IMPLEMENTATIONS
Markdown has been re-implemented in a number of languages, and with a number of additions.
Those that I have found are listed below:
=over
=item C -
Discount - Original Markdown, but in C. Fastest implementation available, and passes MDTest.
Adds its own set of custom features.
=item python -
Python Markdown which is mostly compatible with the original, with an interesting extension API.
=item ruby (maruku) -
One of the nicest implementations out there. Builds a parse tree internally so very flexible.
=item php -
A direct port of Markdown.pl, also has a separately maintained 'extra' version,
which adds a number of features that were borrowed by MultiMarkdown.
=item lua -
Port to lua. Simple and lightweight (as lua is).
=item haskell -
Pandoc is a more general library, supporting Markdown, reStructuredText, LaTeX and more.
=item javascript -
Direct(ish) port of Markdown.pl to JavaScript
=back
=head1 BUGS
To file bug reports or feature requests please send email to:
bug-Text-Markdown@rt.cpan.org
Please include with your report: (1) the example input; (2) the output
you expected; (3) the output Markdown actually produced.
=head1 VERSION HISTORY
See the Changes file for detailed release notes for this version.
=head1 AUTHOR
John Gruber
http://daringfireball.net/
PHP port and other contributions by Michel Fortin
http://michelf.com/
MultiMarkdown changes by Fletcher Penney
http://fletcher.freeshell.org/
CPAN Module Text::MultiMarkdown (based on Text::Markdown by Sebastian
Riedel) originally by Darren Kulp (http://kulp.ch/)
Support for markdown="1" by Dan Dascalescu (http://dandascalescu.com)
This module is maintained by: Tomas Doran http://www.bobtfish.net/
=head1 THIS DISTRIBUTION
Please note that this distribution is a fork of John Gruber's original Markdown project,
and it *is not* in any way blessed by him.
Whilst this code aims to be compatible with the original Markdown.pl (and incorporates
and passes the Markdown test suite) whilst fixing a number of bugs in the original -
there may be differences between the behaviour of this module and Markdown.pl. If you find
any differences where you believe Text::Markdown behaves contrary to the Markdown spec,
please report them as bugs.
Text::Markdown *does not* extend the markdown dialect in any way from that which is documented at
daringfireball. If you want additional features, you should look at L.
=head1 SOURCE CODE
You can find the source code repository for L and L
on GitHub at .
=head1 COPYRIGHT AND LICENSE
Original Code Copyright (c) 2003-2004 John Gruber
All rights reserved.
MultiMarkdown changes Copyright (c) 2005-2006 Fletcher T. Penney
All rights reserved.
Text::MultiMarkdown changes Copyright (c) 2006-2009 Darren Kulp
and Tomas Doran
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 notice,
this list of conditions and the following disclaimer.
* 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
be used to endorse or promote products derived from this software
without specific prior written permission.
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
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.
=cut
Text-Markdown-1.0.26/License.text 0000644 0000765 0000024 00000002744 11233534574 015175 0 ustar t0m staff Copyright (c) 2004, John Gruber
All rights reserved.
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 notice,
this list of conditions and the following disclaimer.
* 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
be used to endorse or promote products derived from this software
without specific prior written permission.
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
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.
Text-Markdown-1.0.26/Makefile.PL 0000644 0000765 0000024 00000001536 11245105472 014647 0 ustar t0m staff # Load the Module::Install bundled in ./inc/
use inc::Module::Install;
# Define metadata
name 'Text-Markdown';
author 'Tomas Doran ';
license 'bsd';
all_from 'lib/Text/Markdown.pm';
resources bugtracker => 'http://github.com/bobtfish/text-markdown/issues';
resources repository => 'http://github.com/bobtfish/text-markdown/';
# Specific dependencies
perl_version '5.008';
requires 'Digest::MD5' => undef;
requires 'Text::Balanced' => undef;
requires 'Encode' => undef;
build_requires 'Test::More' => '0.42';
build_requires 'Test::Exception' => undef;
build_requires 'List::MoreUtils' => undef;
build_requires 'File::Slurp' => '9999.08';
build_requires 'FindBin' => undef;
# Scripts I install
prompt_script('script/Markdown.pl');
WriteAll;
Text-Markdown-1.0.26/MANIFEST 0000644 0000765 0000024 00000043315 11244720674 014035 0 ustar t0m staff Changes
inc/Module/Install.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/Text/Markdown.pm
License.text
Makefile.PL
MANIFEST This list of files
META.yml
README
Readme.text
script/Markdown.pl
t/02pod.t
t/03podcoverage.t
t/19exporter-markdown.t
t/21fulldocs-text-markdown.t
t/23fulldocs-markdown.t
t/25fulldocs-phpmarkdown.t
t/31angleedgecase.t
t/32tabwidth.t
t/33spaceinlinksandimages.t
t/34commandlinemarkdown.t
t/37anchormultilinebugs.t
t/40trustliststart.t
t/code-hr.t
t/docs-maruku-unittest/abbreviations.html
t/docs-maruku-unittest/abbreviations.text
t/docs-maruku-unittest/alt.html
t/docs-maruku-unittest/alt.text
t/docs-maruku-unittest/blank.html
t/docs-maruku-unittest/blank.text
t/docs-maruku-unittest/blanks_in_code.html
t/docs-maruku-unittest/blanks_in_code.text
t/docs-maruku-unittest/bug_def.html
t/docs-maruku-unittest/bug_def.text
t/docs-maruku-unittest/bug_table.html
t/docs-maruku-unittest/bug_table.text
t/docs-maruku-unittest/code.html
t/docs-maruku-unittest/code.text
t/docs-maruku-unittest/code2.html
t/docs-maruku-unittest/code2.text
t/docs-maruku-unittest/code3.html
t/docs-maruku-unittest/code3.text
t/docs-maruku-unittest/convert.pl
t/docs-maruku-unittest/data_loss.html
t/docs-maruku-unittest/data_loss.text
t/docs-maruku-unittest/easy.html
t/docs-maruku-unittest/easy.text
t/docs-maruku-unittest/email.html
t/docs-maruku-unittest/email.text
t/docs-maruku-unittest/entities.html
t/docs-maruku-unittest/entities.text
t/docs-maruku-unittest/escaping.html
t/docs-maruku-unittest/escaping.text
t/docs-maruku-unittest/extra_dl.html
t/docs-maruku-unittest/extra_dl.text
t/docs-maruku-unittest/extra_header_id.html
t/docs-maruku-unittest/extra_header_id.text
t/docs-maruku-unittest/extra_table1.html
t/docs-maruku-unittest/extra_table1.text
t/docs-maruku-unittest/footnotes.html
t/docs-maruku-unittest/footnotes.text
t/docs-maruku-unittest/headers.html
t/docs-maruku-unittest/headers.text
t/docs-maruku-unittest/hex_entities.html
t/docs-maruku-unittest/hex_entities.text
t/docs-maruku-unittest/hrule.html
t/docs-maruku-unittest/hrule.text
t/docs-maruku-unittest/html2.html
t/docs-maruku-unittest/html2.text
t/docs-maruku-unittest/html3.html
t/docs-maruku-unittest/html3.text
t/docs-maruku-unittest/html4.html
t/docs-maruku-unittest/html4.text
t/docs-maruku-unittest/html5.html
t/docs-maruku-unittest/html5.text
t/docs-maruku-unittest/ie.html
t/docs-maruku-unittest/ie.text
t/docs-maruku-unittest/images.html
t/docs-maruku-unittest/images.text
t/docs-maruku-unittest/images2.html
t/docs-maruku-unittest/images2.text
t/docs-maruku-unittest/inline_html.html
t/docs-maruku-unittest/inline_html.text
t/docs-maruku-unittest/inline_html2.html
t/docs-maruku-unittest/inline_html2.text
t/docs-maruku-unittest/links.html
t/docs-maruku-unittest/links.text
t/docs-maruku-unittest/list1.html
t/docs-maruku-unittest/list1.text
t/docs-maruku-unittest/list2.html
t/docs-maruku-unittest/list2.text
t/docs-maruku-unittest/list3.html
t/docs-maruku-unittest/list3.text
t/docs-maruku-unittest/list4.html
t/docs-maruku-unittest/list4.text
t/docs-maruku-unittest/lists.html
t/docs-maruku-unittest/lists.text
t/docs-maruku-unittest/lists11.html
t/docs-maruku-unittest/lists11.text
t/docs-maruku-unittest/lists6.html
t/docs-maruku-unittest/lists6.text
t/docs-maruku-unittest/lists7.html
t/docs-maruku-unittest/lists7.text
t/docs-maruku-unittest/lists7b.html
t/docs-maruku-unittest/lists7b.text
t/docs-maruku-unittest/lists8.html
t/docs-maruku-unittest/lists8.text
t/docs-maruku-unittest/lists9.html
t/docs-maruku-unittest/lists9.text
t/docs-maruku-unittest/lists_after_paragraph.html
t/docs-maruku-unittest/lists_after_paragraph.text
t/docs-maruku-unittest/lists_ol.html
t/docs-maruku-unittest/lists_ol.text
t/docs-maruku-unittest/loss.html
t/docs-maruku-unittest/loss.text
t/docs-maruku-unittest/misc_sw.html
t/docs-maruku-unittest/misc_sw.text
t/docs-maruku-unittest/olist.html
t/docs-maruku-unittest/olist.text
t/docs-maruku-unittest/one.html
t/docs-maruku-unittest/one.text
t/docs-maruku-unittest/paragraph.html
t/docs-maruku-unittest/paragraph.text
t/docs-maruku-unittest/paragraphs.html
t/docs-maruku-unittest/paragraphs.text
t/docs-maruku-unittest/smartypants.html
t/docs-maruku-unittest/smartypants.text
t/docs-maruku-unittest/syntax_hl.html
t/docs-maruku-unittest/syntax_hl.text
t/docs-maruku-unittest/table_attributes.html
t/docs-maruku-unittest/table_attributes.text
t/docs-maruku-unittest/test.html
t/docs-maruku-unittest/test.text
t/docs-maruku-unittest/wrapping.html
t/docs-maruku-unittest/wrapping.text
t/docs-maruku-unittest/xml.html
t/docs-maruku-unittest/xml.text
t/docs-maruku-unittest/xml2.html
t/docs-maruku-unittest/xml2.text
t/docs-maruku-unittest/xml3.html
t/docs-maruku-unittest/xml3.text
t/docs-maruku-unittest/xml_instruction.html
t/docs-maruku-unittest/xml_instruction.text
t/docs-php-markdown-extra/Abbr.html
t/docs-php-markdown-extra/Abbr.text
t/docs-php-markdown-extra/Definition_Lists.html
t/docs-php-markdown-extra/Definition_Lists.text
t/docs-php-markdown-extra/Emphasis.html
t/docs-php-markdown-extra/Emphasis.text
t/docs-php-markdown-extra/Footnotes.html
t/docs-php-markdown-extra/Footnotes.text
t/docs-php-markdown-extra/Inline_HTML_with_Markdown_content.html
t/docs-php-markdown-extra/Inline_HTML_with_Markdown_content.text
t/docs-php-markdown-extra/Tables.html
t/docs-php-markdown-extra/Tables.text
t/docs-php-markdown-todo/Email_auto_links.html
t/docs-php-markdown-todo/Email_auto_links.text
t/docs-php-markdown-todo/Emphasis.html
t/docs-php-markdown-todo/Emphasis.text
t/docs-php-markdown-todo/Inline_HTML_(Span).html
t/docs-php-markdown-todo/Inline_HTML_(Span).text
t/docs-php-markdown-todo/Ins_and_del.text
t/docs-php-markdown-todo/Ins_and_del.xhtml
t/docs-php-markdown-todo/Links_inline_style.html
t/docs-php-markdown-todo/Links_inline_style.text
t/docs-php-markdown-todo/Nesting.html
t/docs-php-markdown-todo/Nesting.text
t/docs-php-markdown-todo/Parens_in_URL.html
t/docs-php-markdown-todo/Parens_in_URL.text
t/docs-php-markdown/Backslash_escapes.html
t/docs-php-markdown/Backslash_escapes.text
t/docs-php-markdown/Code_block_in_a_list_item.html
t/docs-php-markdown/Code_block_in_a_list_item.text
t/docs-php-markdown/Code_Spans.html
t/docs-php-markdown/Code_Spans.text
t/docs-php-markdown/Headers.html
t/docs-php-markdown/Headers.text
t/docs-php-markdown/Images_(Untitled).html
t/docs-php-markdown/Images_(Untitled).text
t/docs-php-markdown/Inline_HTML_(Simple).html
t/docs-php-markdown/Inline_HTML_(Simple).text
t/docs-php-markdown/Inline_HTML_comments.html
t/docs-php-markdown/Inline_HTML_comments.text
t/docs-php-markdown/PHP-Specific_Bugs.html
t/docs-php-markdown/PHP-Specific_Bugs.text
t/docs-php-markdown/Tight_blocks.html
t/docs-php-markdown/Tight_blocks.text
t/docs-pythonmarkdown2-tm-cases-pass/auto_link.html
t/docs-pythonmarkdown2-tm-cases-pass/auto_link.text
t/docs-pythonmarkdown2-tm-cases-pass/auto_link_safe_mode.html
t/docs-pythonmarkdown2-tm-cases-pass/auto_link_safe_mode.opts
t/docs-pythonmarkdown2-tm-cases-pass/auto_link_safe_mode.text
t/docs-pythonmarkdown2-tm-cases-pass/basic_safe_mode.html
t/docs-pythonmarkdown2-tm-cases-pass/basic_safe_mode.opts
t/docs-pythonmarkdown2-tm-cases-pass/basic_safe_mode.text
t/docs-pythonmarkdown2-tm-cases-pass/basic_safe_mode_escape.html
t/docs-pythonmarkdown2-tm-cases-pass/basic_safe_mode_escape.opts
t/docs-pythonmarkdown2-tm-cases-pass/basic_safe_mode_escape.text
t/docs-pythonmarkdown2-tm-cases-pass/blockquote.html
t/docs-pythonmarkdown2-tm-cases-pass/blockquote.text
t/docs-pythonmarkdown2-tm-cases-pass/blockquote_with_pre.html
t/docs-pythonmarkdown2-tm-cases-pass/blockquote_with_pre.text
t/docs-pythonmarkdown2-tm-cases-pass/code_block_with_tabs.html
t/docs-pythonmarkdown2-tm-cases-pass/code_block_with_tabs.text
t/docs-pythonmarkdown2-tm-cases-pass/code_safe_emphasis.html
t/docs-pythonmarkdown2-tm-cases-pass/code_safe_emphasis.opts
t/docs-pythonmarkdown2-tm-cases-pass/code_safe_emphasis.text
t/docs-pythonmarkdown2-tm-cases-pass/codeblock.html
t/docs-pythonmarkdown2-tm-cases-pass/codeblock.text
t/docs-pythonmarkdown2-tm-cases-pass/codespans.html
t/docs-pythonmarkdown2-tm-cases-pass/codespans.text
t/docs-pythonmarkdown2-tm-cases-pass/codespans_safe_mode.html
t/docs-pythonmarkdown2-tm-cases-pass/codespans_safe_mode.opts
t/docs-pythonmarkdown2-tm-cases-pass/codespans_safe_mode.text
t/docs-pythonmarkdown2-tm-cases-pass/emacs_head_vars.html
t/docs-pythonmarkdown2-tm-cases-pass/emacs_head_vars.text
t/docs-pythonmarkdown2-tm-cases-pass/emacs_tail_vars.html
t/docs-pythonmarkdown2-tm-cases-pass/emacs_tail_vars.text
t/docs-pythonmarkdown2-tm-cases-pass/emphasis.html
t/docs-pythonmarkdown2-tm-cases-pass/emphasis.text
t/docs-pythonmarkdown2-tm-cases-pass/escapes.html
t/docs-pythonmarkdown2-tm-cases-pass/escapes.text
t/docs-pythonmarkdown2-tm-cases-pass/footnotes.html
t/docs-pythonmarkdown2-tm-cases-pass/footnotes.opts
t/docs-pythonmarkdown2-tm-cases-pass/footnotes.text
t/docs-pythonmarkdown2-tm-cases-pass/footnotes_letters.html
t/docs-pythonmarkdown2-tm-cases-pass/footnotes_letters.opts
t/docs-pythonmarkdown2-tm-cases-pass/footnotes_letters.text
t/docs-pythonmarkdown2-tm-cases-pass/footnotes_markup.html
t/docs-pythonmarkdown2-tm-cases-pass/footnotes_markup.opts
t/docs-pythonmarkdown2-tm-cases-pass/footnotes_markup.text
t/docs-pythonmarkdown2-tm-cases-pass/footnotes_safe_mode_escape.html
t/docs-pythonmarkdown2-tm-cases-pass/footnotes_safe_mode_escape.opts
t/docs-pythonmarkdown2-tm-cases-pass/footnotes_safe_mode_escape.text
t/docs-pythonmarkdown2-tm-cases-pass/header.html
t/docs-pythonmarkdown2-tm-cases-pass/header.text
t/docs-pythonmarkdown2-tm-cases-pass/hr.html
t/docs-pythonmarkdown2-tm-cases-pass/hr.text
t/docs-pythonmarkdown2-tm-cases-pass/img_in_link.html
t/docs-pythonmarkdown2-tm-cases-pass/img_in_link.text
t/docs-pythonmarkdown2-tm-cases-pass/inline_links.html
t/docs-pythonmarkdown2-tm-cases-pass/inline_links.text
t/docs-pythonmarkdown2-tm-cases-pass/issue2_safe_mode_borks_markup.html
t/docs-pythonmarkdown2-tm-cases-pass/issue2_safe_mode_borks_markup.opts
t/docs-pythonmarkdown2-tm-cases-pass/issue2_safe_mode_borks_markup.text
t/docs-pythonmarkdown2-tm-cases-pass/link_defn_alt_title_delims.html
t/docs-pythonmarkdown2-tm-cases-pass/link_defn_alt_title_delims.text
t/docs-pythonmarkdown2-tm-cases-pass/link_patterns.html
t/docs-pythonmarkdown2-tm-cases-pass/link_patterns.opts
t/docs-pythonmarkdown2-tm-cases-pass/link_patterns.text
t/docs-pythonmarkdown2-tm-cases-pass/link_patterns_double_hit.html
t/docs-pythonmarkdown2-tm-cases-pass/link_patterns_double_hit.opts
t/docs-pythonmarkdown2-tm-cases-pass/link_patterns_double_hit.text
t/docs-pythonmarkdown2-tm-cases-pass/link_patterns_edge_cases.html
t/docs-pythonmarkdown2-tm-cases-pass/link_patterns_edge_cases.opts
t/docs-pythonmarkdown2-tm-cases-pass/link_patterns_edge_cases.text
t/docs-pythonmarkdown2-tm-cases-pass/lists.html
t/docs-pythonmarkdown2-tm-cases-pass/lists.text
t/docs-pythonmarkdown2-tm-cases-pass/mismatched_footnotes.html
t/docs-pythonmarkdown2-tm-cases-pass/mismatched_footnotes.opts
t/docs-pythonmarkdown2-tm-cases-pass/mismatched_footnotes.text
t/docs-pythonmarkdown2-tm-cases-pass/missing_link_defn.html
t/docs-pythonmarkdown2-tm-cases-pass/missing_link_defn.text
t/docs-pythonmarkdown2-tm-cases-pass/nested_list.html
t/docs-pythonmarkdown2-tm-cases-pass/nested_list.text
t/docs-pythonmarkdown2-tm-cases-pass/nested_list_safe_mode.html
t/docs-pythonmarkdown2-tm-cases-pass/nested_list_safe_mode.opts
t/docs-pythonmarkdown2-tm-cases-pass/nested_list_safe_mode.text
t/docs-pythonmarkdown2-tm-cases-pass/parens_in_url_4.html
t/docs-pythonmarkdown2-tm-cases-pass/parens_in_url_4.text
t/docs-pythonmarkdown2-tm-cases-pass/raw_html.html
t/docs-pythonmarkdown2-tm-cases-pass/raw_html.text
t/docs-pythonmarkdown2-tm-cases-pass/ref_links.html
t/docs-pythonmarkdown2-tm-cases-pass/ref_links.text
t/docs-pythonmarkdown2-tm-cases-pass/sublist-para.html
t/docs-pythonmarkdown2-tm-cases-pass/sublist-para.text
t/docs-pythonmarkdown2-tm-cases-pass/syntax_color.html
t/docs-pythonmarkdown2-tm-cases-pass/syntax_color.opts
t/docs-pythonmarkdown2-tm-cases-pass/syntax_color.text
t/docs-pythonmarkdown2-tm-cases-pass/tricky_anchors.html
t/docs-pythonmarkdown2-tm-cases-pass/tricky_anchors.text
t/docs-pythonmarkdown2-tm-cases-pass/underline_in_autolink.html
t/docs-pythonmarkdown2-tm-cases-pass/underline_in_autolink.text
t/Markdown-from-MDTest1.1.mdtest/Amps_and_angle_encoding.text
t/Markdown-from-MDTest1.1.mdtest/Amps_and_angle_encoding.xhtml
t/Markdown-from-MDTest1.1.mdtest/Auto_links.text
t/Markdown-from-MDTest1.1.mdtest/Auto_links.xhtml
t/Markdown-from-MDTest1.1.mdtest/Backslash_escapes.text
t/Markdown-from-MDTest1.1.mdtest/Backslash_escapes.xhtml
t/Markdown-from-MDTest1.1.mdtest/Blockquotes_with_code_blocks.text
t/Markdown-from-MDTest1.1.mdtest/Blockquotes_with_code_blocks.xhtml
t/Markdown-from-MDTest1.1.mdtest/Code_Blocks.text
t/Markdown-from-MDTest1.1.mdtest/Code_Blocks.xhtml
t/Markdown-from-MDTest1.1.mdtest/Code_Spans.text
t/Markdown-from-MDTest1.1.mdtest/Code_Spans.xhtml
t/Markdown-from-MDTest1.1.mdtest/Hard-wrapped_paragraphs_with_list-like_lines.text
t/Markdown-from-MDTest1.1.mdtest/Hard-wrapped_paragraphs_with_list-like_lines.xhtml
t/Markdown-from-MDTest1.1.mdtest/Horizontal_rules.text
t/Markdown-from-MDTest1.1.mdtest/Horizontal_rules.xhtml
t/Markdown-from-MDTest1.1.mdtest/Images.text
t/Markdown-from-MDTest1.1.mdtest/Images.xhtml
t/Markdown-from-MDTest1.1.mdtest/Inline_HTML_(Advanced).text
t/Markdown-from-MDTest1.1.mdtest/Inline_HTML_(Advanced).xhtml
t/Markdown-from-MDTest1.1.mdtest/Inline_HTML_(Simple).html
t/Markdown-from-MDTest1.1.mdtest/Inline_HTML_(Simple).text
t/Markdown-from-MDTest1.1.mdtest/Inline_HTML_comments.html
t/Markdown-from-MDTest1.1.mdtest/Inline_HTML_comments.text
t/Markdown-from-MDTest1.1.mdtest/Links_inline_style.text
t/Markdown-from-MDTest1.1.mdtest/Links_inline_style.xhtml
t/Markdown-from-MDTest1.1.mdtest/Links_reference_style.text
t/Markdown-from-MDTest1.1.mdtest/Links_reference_style.xhtml
t/Markdown-from-MDTest1.1.mdtest/Links_shortcut_references.text
t/Markdown-from-MDTest1.1.mdtest/Links_shortcut_references.xhtml
t/Markdown-from-MDTest1.1.mdtest/Literal_quotes_in_titles.text
t/Markdown-from-MDTest1.1.mdtest/Literal_quotes_in_titles.xhtml
t/Markdown-from-MDTest1.1.mdtest/Markdown_Documentation_-_Basics.text
t/Markdown-from-MDTest1.1.mdtest/Markdown_Documentation_-_Basics.xhtml
t/Markdown-from-MDTest1.1.mdtest/Markdown_Documentation_-_Syntax.text
t/Markdown-from-MDTest1.1.mdtest/Markdown_Documentation_-_Syntax.xhtml
t/Markdown-from-MDTest1.1.mdtest/Nested_blockquotes.text
t/Markdown-from-MDTest1.1.mdtest/Nested_blockquotes.xhtml
t/Markdown-from-MDTest1.1.mdtest/Ordered_and_unordered_lists.text
t/Markdown-from-MDTest1.1.mdtest/Ordered_and_unordered_lists.xhtml
t/Markdown-from-MDTest1.1.mdtest/Strong_and_em_together.text
t/Markdown-from-MDTest1.1.mdtest/Strong_and_em_together.xhtml
t/Markdown-from-MDTest1.1.mdtest/Tabs.text
t/Markdown-from-MDTest1.1.mdtest/Tabs.xhtml
t/Markdown-from-MDTest1.1.mdtest/Tidyness.text
t/Markdown-from-MDTest1.1.mdtest/Tidyness.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Backslash_escapes.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Backslash_escapes.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Code_block_in_a_list_item.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Code_block_in_a_list_item.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Code_Spans.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Code_Spans.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Email_auto_links.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Email_auto_links.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Emphasis.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Emphasis.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Headers.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Headers.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Horizontal_Rules.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Horizontal_Rules.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Inline_HTML_(Simple).html
t/PHP_Markdown-from-MDTest1.1.mdtest/Inline_HTML_(Simple).text
t/PHP_Markdown-from-MDTest1.1.mdtest/Inline_HTML_(Span).text
t/PHP_Markdown-from-MDTest1.1.mdtest/Inline_HTML_(Span).xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Inline_HTML_comments.html
t/PHP_Markdown-from-MDTest1.1.mdtest/Inline_HTML_comments.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Ins_and_del.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Ins_and_del.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Links_inline_style.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Links_inline_style.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/MD5_Hashes.text
t/PHP_Markdown-from-MDTest1.1.mdtest/MD5_Hashes.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Nesting.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Nesting.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Parens_in_URL.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Parens_in_URL.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/PHP-Specific_Bugs.text
t/PHP_Markdown-from-MDTest1.1.mdtest/PHP-Specific_Bugs.xhtml
t/PHP_Markdown-from-MDTest1.1.mdtest/Tight_blocks.text
t/PHP_Markdown-from-MDTest1.1.mdtest/Tight_blocks.xhtml
t/rt37909.t
t/Text-Markdown.mdtest/CoreDumps5.8.text
t/Text-Markdown.mdtest/CoreDumps5.8.xhtml
t/Text-Markdown.mdtest/Emphasis.text
t/Text-Markdown.mdtest/Emphasis.xhtml
t/Text-Markdown.mdtest/HTML-Comment-encoding.text
t/Text-Markdown.mdtest/HTML-Comment-encoding.xhtml
t/Text-Markdown.mdtest/Links_brackets.text
t/Text-Markdown.mdtest/Links_brackets.xhtml
t/Text-Markdown.mdtest/Links_multiline_bugs_1.html
t/Text-Markdown.mdtest/Links_multiline_bugs_1.text
t/Text-Markdown.mdtest/Links_multiline_bugs_2.html
t/Text-Markdown.mdtest/Links_multiline_bugs_2.text
t/Text-Markdown.mdtest/Links_reference_style.text
t/Text-Markdown.mdtest/Links_reference_style.xhtml
t/Text-Markdown.mdtest/Lists-multilevel-md5-edgecase.text
t/Text-Markdown.mdtest/Lists-multilevel-md5-edgecase.xhtml
t/Text-Markdown.mdtest/PHP-ASP_tags.text
t/Text-Markdown.mdtest/PHP-ASP_tags.xhtml
t/Text-Markdown.mdtest/Unicode.text
t/Text-Markdown.mdtest/Unicode.xhtml
Todo
Text-Markdown-1.0.26/META.yml 0000644 0000765 0000024 00000001471 11261760145 014146 0 ustar t0m staff ---
abstract: 'Convert Markdown syntax to (X)HTML'
author:
- 'Tomas Doran '
build_requires:
ExtUtils::MakeMaker: 6.42
File::Slurp: 9999.08
FindBin: 0
List::MoreUtils: 0
Test::Exception: 0
Test::More: 0.42
script/Markdown.pl: 0
configure_requires:
ExtUtils::MakeMaker: 6.42
distribution_type: module
generated_by: 'Module::Install version 0.910'
license: bsd
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Text-Markdown
no_index:
directory:
- inc
- t
requires:
Digest::MD5: 0
Encode: 0
Text::Balanced: 0
perl: 5.8.0
resources:
bugtracker: http://github.com/bobtfish/text-markdown/issues
license: http://opensource.org/licenses/bsd-license.php
repository: http://github.com/bobtfish/text-markdown/
version: 1.0.26
Text-Markdown-1.0.26/README 0000644 0000765 0000024 00000020300 11261757515 013554 0 ustar t0m staff NAME
Text::Markdown - Convert Markdown syntax to (X)HTML
SYNOPSIS
use Text::Markdown 'markdown';
my $html = markdown($text);
use Text::Markdown 'markdown';
my $html = markdown( $text, {
empty_element_suffix => '>',
tab_width => 2,
} );
use Text::Markdown;
my $m = Text::Markdown->new;
my $html = $m->markdown($text);
use Text::Markdown;
my $m = Text::MultiMarkdown->new(
empty_element_suffix => '>',
tab_width => 2,
);
my $html = $m->markdown( $text );
DESCRIPTION
Markdown is a text-to-HTML filter; it translates an easy-to-read /
easy-to-write structured text format into HTML. Markdown's text format
is most similar to that of plain text email, and supports features such
as headers, *emphasis*, code blocks, blockquotes, and links.
Markdown's syntax is designed not as a generic markup language, but
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 and
as well).
SYNTAX
This module implements the 'original' Markdown markdown syntax from:
http://daringfireball.net/projects/markdown/
Note that Text::Markdown ensures that the output always ends with
*one* newline. The fact that multiple newlines are collapsed into one
makes sense, because this is the behavior of HTML towards whispace. The
fact that there's always a newline at the end makes sense again, given
that the output will always be nested in a block-level element (as
opposed to an inline element). That block element can be a (most
often), or a
.
Markdown is *not* interpreted in HTML block-level elements, in order for
chunks of pasted HTML (e.g. JavaScript widgets, web counters) to not be
magically (mis)interpreted. For selective processing of Markdown in some,
but not other, HTML block elements, add a "markdown" attribute to the block
element and set its value to "1", "on" or "yes":
* Home
* About
* Contact
The extra "markdown" attribute will be stripped when generating the output.
OPTIONS
Text::Markdown supports a number of options to its processor which
control the behaviour of the output document.
These options can be supplied to the constructor, on in a hash with the
individual calls to the markdown method. See the synopsis for examples
of both of the above styles.
The options for the processor are:
empty element suffix
This option can be used to generate normal HTML output. By default,
it is ' />', which is xHTML, change to '>' for normal HTML.
tab_width
Controls indent width in the generated markup, defaults to 4
METHODS
new
A simple constructor, see the SYNTAX and OPTIONS sections for more
information.
markdown
The main function as far as the outside world is concerned. See the
SYNOPSIS for details on use.
urls
Returns a reference to a hash with the key being the markdown reference
and the value being the URL.
Useful for building scripts which preprocess a list of links before the
main content. See t/05options.t for an example of this hashref being
passed back into the markdown method to create links.
OTHER IMPLEMENTATIONS
Markdown has been re-implemented in a number of languages, and with a
number of additions.
Those that I have found are listed below:
C -
Discount - Original Markdown, but in C. Fastest implementation
available, and passes MDTest. Adds it's own set of custom features.
python -
Python Markdown which is mostly compatible with the original, with
an interesting extension API.
ruby (maruku) -
One of the nicest implementations out there. Builds a parse tree
internally so very flexible.
php -
A direct port of Markdown.pl, also has a separately maintained
'extra' version, which adds a number of features that were borrowed
by MultiMarkdown.
lua -
Port to lua. Simple and lightweight (as lua is).
haskell -
Pandoc is a more general library, supporting Markdown,
reStructuredText, LaTeX and more.
javascript -
Direct(ish) port of Markdown.pl to JavaScript
BUGS
To file bug reports or feature requests please send email to:
bug-Text-Markdown@rt.cpan.org
Please include with your report: (1) the example input; (2) the output
you expected; (3) the output Markdown actually produced.
VERSION HISTORY
See the Changes file for detailed release notes for this version.
AUTHOR
John Gruber
http://daringfireball.net/
PHP port and other contributions by Michel Fortin
http://michelf.com/
MultiMarkdown changes by Fletcher Penney
http://fletcher.freeshell.org/
CPAN Module Text::MultiMarkdown (based on Text::Markdown by Sebastian
Riedel) originally by Darren Kulp (http://kulp.ch/)
Support for markdown="1" by Dan Dascalescu (http://dandascalescu.com)
This module is maintained by: Tomas Doran http://www.bobtfish.net/
THIS DISTRIBUTION
Please note that this distribution is a fork of John Gruber's original
Markdown project, and it *is not* in any way blessed by him.
Whilst this code aims to be compatible with the original Markdown.pl
(and incorporates and passes the Markdown test suite) whilst fixing a
number of bugs in the original - there may be differences between the
behaviour of this module and Markdown.pl. If you find any differences
where you believe Text::Markdown behaves contrary to the Markdown spec,
please report them as bugs.
Text::Markdown *does not* extend the markdown dialect in any way from
that which is documented at daringfireball. If you want additional
features, you should look at Text::MultiMarkdown.
COPYRIGHT AND LICENSE
Original Code Copyright (c) 2003-2004 John Gruber
All rights reserved.
MultiMarkdown changes Copyright (c) 2005-2006 Fletcher T. Penney
All rights reserved.
Text::MultiMarkdown changes Copyright (c) 2006-2008 Darren Kulp
and Tomas Doran
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 notice,
this list of conditions and the following disclaimer.
* 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 be
used to endorse or promote products derived from this software without
specific prior written permission.
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
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.
Text-Markdown-1.0.26/Readme.text 0000644 0000765 0000024 00000026071 11233534574 015007 0 ustar t0m staff # WARNING
This Readme is from the original version of Markdown; not all of the
information contained herein is applicable to Test::Markdown the CPAN
module that includes this file. See the module's POD and the README file for
more information.
Markdown
========
Version 1.0.1 - Tue 14 Dec 2004
by John Gruber
Introduction
------------
Markdown is a text-to-HTML conversion tool for web writers. Markdown
allows you to write using an easy-to-read, easy-to-write plain text
format, then convert it to structurally valid XHTML (or HTML).
Thus, "Markdown" is two things: a plain text markup syntax, and a
software tool, written in Perl, that converts the plain text markup
to HTML.
Markdown works both as a Movable Type plug-in and as a standalone Perl
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 on the web: .
(Note: this readme file is formatted in Markdown.)
Installation and Requirements
-----------------------------
Markdown requires Perl 5.6.0 or later. Welcome to the 21st Century.
Markdown also requires the standard Perl library module `Digest::MD5`.
### Movable Type ###
Markdown works with Movable Type version 2.6 or later (including
MT 3.0 or later).
1. Copy the "Markdown.pl" file into your Movable Type "plugins"
directory. The "plugins" directory should be in the same directory
as "mt.cgi"; if the "plugins" directory doesn't already exist, use
your FTP program to create it. Your installation should look like
this:
(mt home)/plugins/Markdown.pl
2. Once installed, Markdown will appear as an option in Movable Type's
Text Formatting pop-up menu. This is selectable on a per-post basis.
Markdown translates your posts to HTML when you publish; the posts
themselves are stored in your MT database in Markdown format.
3. If you also install SmartyPants 1.5 (or later), Markdown will offer
a second text formatting option: "Markdown with SmartyPants". This
option is the same as the regular "Markdown" formatter, except that
automatically uses SmartyPants to create typographically correct
curly quotes, em-dashes, and ellipses. See the SmartyPants web page
for more information:
4. To make Markdown (or "Markdown with SmartyPants") your default
text formatting option for new posts, go to Weblog Config ->
Preferences.
Note that by default, Markdown produces XHTML output. To configure
Markdown to produce HTML 4 output, see "Configuration", below.
### Blosxom ###
Markdown works with Blosxom version 2.x.
1. Rename the "Markdown.pl" plug-in to "Markdown" (case is
important). Movable Type requires plug-ins to have a ".pl"
extension; Blosxom forbids it.
2. Copy the "Markdown" plug-in file to your Blosxom plug-ins folder.
If you're not sure where your Blosxom plug-ins folder is, see the
Blosxom documentation for information.
3. That's it. The entries in your weblog will now automatically be
processed by Markdown.
4. If you'd like to apply Markdown formatting only to certain posts,
rather than all of them, see Jason Clark's instructions for using
Markdown in conjunction with Blosxom's Meta plugin:
### BBEdit ###
Markdown works with BBEdit 6.1 or later on Mac OS X. (It also works
with BBEdit 5.1 or later and MacPerl 5.6.1 on Mac OS 8.6 or later.)
1. Copy the "Markdown.pl" file to appropriate filters folder in your
"BBEdit Support" folder. On Mac OS X, this should be:
BBEdit Support/Unix Support/Unix Filters/
See the BBEdit documentation for more details on the location of
these folders.
You can rename "Markdown.pl" to whatever you wish.
2. That's it. To use Markdown, select some text in a BBEdit document,
then choose Markdown from the Filters sub-menu in the "#!" menu, or
the Filters floating palette
Configuration
-------------
By default, Markdown produces XHTML output for tags with empty elements.
E.g.:
Markdown can be configured to produce HTML-style tags; e.g.:
### Movable Type ###
You need to use a special `MTMarkdownOptions` container tag in each
Movable Type template where you want HTML 4-style output:
... put your entry content here ...
The easiest way to use MTMarkdownOptions is probably to put the
opening tag right after your `` tag, and the closing tag right
before ``.
To suppress Markdown processing in a particular template, i.e. to
publish the raw Markdown-formatted text without translation into
(X)HTML, set the `output` attribute to 'raw':
... put your entry content here ...
### Command-Line ###
Use the `--html4tags` command-line switch to produce HTML output from a
Unix-style command line. E.g.:
% perl Markdown.pl --html4tags foo.text
Type `perldoc Markdown.pl`, or read the POD documentation within the
Markdown.pl source code for more information.
Bugs
----
To file bug reports or feature requests please send email to:
.
Version History
---------------
1.0.1 (14 Dec 2004):
+ Changed the syntax rules for code blocks and spans. Previously,
backslash escapes for special Markdown characters were processed
everywhere other than within inline HTML tags. Now, the contents
of code blocks and spans are no longer processed for backslash
escapes. This means that code blocks and spans are now treated
literally, with no special rules to worry about regarding
backslashes.
**NOTE**: This changes the syntax from all previous versions of
Markdown. Code blocks and spans involving backslash characters
will now generate different output than before.
+ Tweaked the rules for link definitions so that they must occur
within three spaces of the left margin. Thus if you indent a link
definition by four spaces or a tab, it will now be a code block.
[a]: /url/ "Indented 3 spaces, this is a link def"
[b]: /url/ "Indented 4 spaces, this is a code block"
**IMPORTANT**: This may affect existing Markdown content if it
contains link definitions indented by 4 or more spaces.
+ Added `>`, `+`, and `-` to the list of backslash-escapable
characters. These should have been done when these characters
were added as unordered list item markers.
+ Trailing spaces and tabs following HTML comments and `
` tags
are now ignored.
+ Inline links using `<` and `>` URL delimiters weren't working:
like [this]()
+ Added a bit of tolerance for trailing spaces and tabs after
Markdown hr's.
+ Fixed bug where auto-links were being processed within code spans:
like this: ``
+ Sort-of fixed a bug where lines in the middle of hard-wrapped
paragraphs, which lines look like the start of a list item,
would accidentally trigger the creation of a list. E.g. a
paragraph that looked like this:
I recommend upgrading to version
8. Oops, now this line is treated
as a sub-list.
This is fixed for top-level lists, but it can still happen for
sub-lists. E.g., the following list item will not be parsed
properly:
+ I recommend upgrading to version
8. Oops, now this line is treated
as a sub-list.
Given Markdown's list-creation rules, I'm not sure this can
be fixed.
+ Standalone HTML comments are now handled; previously, they'd get
wrapped in a spurious `` tag.
+ Fix for horizontal rules preceded by 2 or 3 spaces.
+ `
` HTML tags in must occur within three spaces of left
margin. (With 4 spaces or a tab, they should be code blocks, but
weren't before this fix.)
+ Capitalized "With" in "Markdown With SmartyPants" for
consistency with the same string label in SmartyPants.pl.
(This fix is specific to the MT plug-in interface.)
+ Auto-linked email address can now optionally contain
a 'mailto:' protocol. I.e. these are equivalent:
+ Fixed annoying bug where nested lists would wind up with
spurious (and invalid) `` tags.
+ You can now write empty links:
[like this]()
and they'll be turned into anchor tags with empty href attributes.
This should have worked before, but didn't.
+ `***this***` and `___this___` are now turned into
this
Instead of
this
which isn't valid. (Thanks to Michel Fortin for the fix.)
+ Added a new substitution in `_EncodeCode()`: s/\$/$/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.:
[1]: http://sources.wikipedia.org/wiki/Middle_East_Policy_(Chomsky)
"Chomsky" was being erroneously treated as the URL's title.
+ At some point during 1.0's beta cycle, I changed every sub's
argument fetching from this idiom:
my $text = shift;
to:
my $text = shift || return '';
The idea was to keep Markdown from doing any work in a sub
if the input was empty. This introduced a bug, though:
if the input to any function was the single-character string
"0", it would also evaluate as false and return immediately.
How silly. Now fixed.
Donations
---------
Donations to support Markdown's development are happily accepted. See:
for details.
Copyright and License
---------------------
Copyright (c) 2003-2004 John Gruber
All rights reserved.
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 notice,
this list of conditions and the following disclaimer.
* 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
be used to endorse or promote products derived from this software
without specific prior written permission.
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
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.
Text-Markdown-1.0.26/script/ 0000755 0000765 0000024 00000000000 11261760160 014173 5 ustar t0m staff Text-Markdown-1.0.26/script/Markdown.pl 0000644 0000765 0000024 00000006372 11233534574 016331 0 ustar t0m staff #!/usr/bin/env perl
use strict;
use warnings;
use Text::Markdown qw(markdown);
=head1 NAME
Markdown.pl - Convert Markdown syntax to (X)HTML
=head1 DESCRIPTION
This program is distributed as part of Perl's Text::Markdown module,
illustrating sample usage.
Markdown can be invoked on any file containing Markdown-syntax, and
will produce the corresponding (X)HTML on STDOUT:
$ cat file.txt
This is a *test*.
Absolutely _nothing_ to see here. _Just a **test**_!
* test
* Yup, test.
$ Markdown.pl file.txt
This is a test.
Absolutely nothing to see here. Just a test!
If no file is specified, it will expect its input from STDIN:
$ echo "A **simple** test" | markdown
A simple test
=head1 OPTIONS
=over
=item version
Shows the full information for this version
=item shortversion
Shows only the version number
=item html4tags
Produce HTML 4-style tags instead of XHTML - XHTML requires elements
that do not wrap a block (i.e. the C
tag) to state they will not
be closed, by closing with C>. HTML 4-style will plainly output
the tag as it comes:
$ echo '---' | markdown
$ echo '---' | markdown --html4tags
=item help
Shows this documentation
=back
=head1 AUTHOR
Copyright 2004 John Gruber
Copyright 2008 Tomas Doran
The manpage was written by Gunnar Wolf for its use
in Debian systems, but can be freely used elsewhere.
For full licensing information, please refer to
L's full documentation.
=head1 SEE ALSO
L, L
=cut
#### Check for command-line switches: #################
my %cli_opts;
use Getopt::Long;
Getopt::Long::Configure('pass_through');
GetOptions(\%cli_opts,
'version',
'shortversion',
'html4tags',
'help',
);
if ($cli_opts{'version'}) { # Version info
print "\nThis is Markdown, version $Text::Markdown::VERSION.\n";
print "Copyright 2004 John Gruber\n";
print "Copyright 2008 Tomas Doran\n";
print "Parts contributed by several other people.";
print "http://daringfireball.net/projects/markdown/\n\n";
exit 0;
}
if ($cli_opts{'shortversion'}) { # Just the version number string.
print $Text::Markdown::VERSION;
exit 0;
}
if ($cli_opts{'help'}) {
for my $dir (split m/:/, $ENV{PATH}) {
my $cmd = "$dir/perldoc";
exec($cmd, $0) if (-f $cmd and -x $cmd);
}
die "perldoc could not be found in your path - Cannot show help, sorry\n";
}
my $m;
if ($cli_opts{'html4tags'}) { # Use HTML tag style instead of XHTML
$m = Text::Markdown->new(empty_element_suffix => '>');
}
else {
$m = Text::Markdown->new;
}
sub main {
my (@fns) = @_;
my $f;
if (scalar @fns) {
foreach my $fn (@fns) {
die("Cannot find file $fn") unless (-r $fn);
my $fh;
open($fh, '<', $fn) or die;
$f = join('', <$fh>);
close($fh) or die;
}
}
else { # STDIN
local $/; # Slurp the whole file
$f = <>;
}
return $m->markdown($f);
}
print main(@ARGV) unless caller();
Text-Markdown-1.0.26/t/ 0000755 0000765 0000024 00000000000 11261760161 013133 5 ustar t0m staff Text-Markdown-1.0.26/t/02pod.t 0000644 0000765 0000024 00000000330 11233534574 014246 0 ustar t0m staff use strict;
use warnings;
use Test::More;
eval "use Test::Pod 1.14";
plan skip_all => 'Test::Pod 1.14 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_files_ok();
Text-Markdown-1.0.26/t/03podcoverage.t 0000644 0000765 0000024 00000000357 11233534574 015774 0 ustar t0m staff use strict;
use warnings;
use Test::More;
eval "use Test::Pod::Coverage 1.04";
plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_coverage_ok();
Text-Markdown-1.0.26/t/19exporter-markdown.t 0000644 0000765 0000024 00000001774 11233534574 017201 0 ustar t0m staff use strict;
use warnings;
use Test::More tests => 7;
use Test::Exception;
use_ok( 'Text::Markdown', 'markdown' );
my $instr = q{A trivial block of text};
my $outstr = q{A trivial block of text
};
lives_ok {
$outstr = markdown($instr);
} 'Functional markdown works without an exception';
chomp($outstr);
is(
$outstr => '' . $instr . '
',
'exported markdown function works'
);
# Test that we *force* multimarkdown features to be off
$instr = q{# Heading 1};
my $expstr = qq{Heading 1
\n};
lives_ok {
$outstr = markdown($instr, { heading_ids => 1});
} 'Functional markdown works without an exception, with options';
is(
$outstr => $expstr,
'exported markdown function overrides passed options'
);
{
local $TODO = 'Broken here';
$outstr = '';
lives_ok {
$outstr = Text::Markdown->markdown($instr);
} 'Lives (class method)';
chomp($outstr);
is($outstr, '' . $instr . '
', 'Text::Markdown->markdown() works (as class method)');
};
Text-Markdown-1.0.26/t/21fulldocs-text-markdown.t 0000644 0000765 0000024 00000005371 11245105472 020106 0 ustar t0m staff use strict;
use warnings;
use Test::More;
use FindBin qw($Bin);
use List::MoreUtils qw(uniq);
use File::Slurp qw(slurp);
use Encode;
our $TIDY = 0;
### Generate difftest subroutine, pretty prints diffs if you have Text::Diff, use uses
### Test::More::is otherwise.
eval {
require Text::Diff;
};
if (!$@) {
*difftest = sub {
my ($got, $expected, $testname) = @_;
$got .= "\n";
$expected .= "\n";
if ($got eq $expected) {
pass($testname);
return;
}
print "=" x 80 . "\nDIFFERENCES: + = processed version from .text, - = template from .html\n";
print encode('utf8', Text::Diff::diff(\$expected => \$got, { STYLE => "Unified" }) . "\n");
fail($testname);
};
}
else {
warn("Install Text::Diff for more helpful failure messages! ($@)");
*difftest = \&Test::More::is;
}
sub tidy {
$TIDY = 1;
eval "use HTML::Tidy; ";
if ($@) {
plan skip_all => 'This test needs HTML::Tidy installed to pass correctly, skipping';
exit;
}
}
### Actual code for this test - unless(caller) stops it
### being run when this file is required by other tests
unless (caller) {
my $docsdir = "$Bin/Text-Markdown.mdtest";
my @files = get_files($docsdir);
plan tests => scalar(@files) + 1;
use_ok('Text::Markdown');
my $m = Text::Markdown->new();
run_tests($m, $docsdir, @files);
}
sub get_files {
my ($docsdir) = @_;
my $DH;
opendir($DH, $docsdir) or die("Could not open $docsdir");
my @files = uniq map { s/\.(xhtml|html|text)$// ? $_ : (); } readdir($DH);
closedir($DH);
return @files;
}
sub run_tests {
my ($m, $docsdir, @files) = @_;
foreach my $test (@files) {
my ($input, $output);
eval {
if (-f "$docsdir/$test.html") {
$output = slurp("$docsdir/$test.html");
}
else {
$output = slurp("$docsdir/$test.xhtml");
}
$input = slurp("$docsdir/$test.text");
};
$input .= "\n\n";
$output .= "\n\n";
if ($@) {
fail("1 part of test file not found: $@");
next;
}
$output =~ s/\s+\z//; # trim trailing whitespace
my $processed = $m->markdown($input);
$processed =~ s/\s+\z//; # trim trailing whitespace
if ($TIDY) {
my $t = HTML::Tidy->new;
$output = $t->clean($output);
$processed = $t->clean($processed);
}
# Un-comment for debugging if you have space diffs you can't see..
$output =~ s/ / /g;
$output =~ s/\t/&tab;/g;
$processed =~ s/ / /g;
$processed =~ s/\t/&tab;/g;
difftest($processed, $output, "Docs test: $test");
}
}
1;
Text-Markdown-1.0.26/t/23fulldocs-markdown.t 0000644 0000765 0000024 00000000513 11245105472 017117 0 ustar t0m staff use strict;
use warnings;
use Test::More;
use FindBin qw($Bin);
require "$Bin/21fulldocs-text-markdown.t";
tidy();
my $docsdir = "$Bin/Markdown-from-MDTest1.1.mdtest";
my @files = get_files($docsdir);
plan tests => scalar(@files) + 1;
use_ok('Text::Markdown');
my $m = Text::Markdown->new();
run_tests($m, $docsdir, @files);
Text-Markdown-1.0.26/t/25fulldocs-phpmarkdown.t 0000644 0000765 0000024 00000000654 11245105472 017637 0 ustar t0m staff use strict;
use warnings;
use Test::More;
use FindBin qw($Bin);
require "$Bin/21fulldocs-text-markdown.t";
tidy();
my $docsdir = "$Bin/PHP_Markdown-from-MDTest1.1.mdtest";
my @files = get_files($docsdir);
plan tests => scalar(@files) + 1;
use_ok('Text::Markdown');
my $m = Text::Markdown->new();
TODO: {
local $TODO = 'Have not fixed a load of the bugs PHP markdown has yet.';
run_tests($m, $docsdir, @files);
};
Text-Markdown-1.0.26/t/31angleedgecase.t 0000644 0000765 0000024 00000000661 11233534574 016244 0 ustar t0m staff use strict;
use warnings;
use Test::More tests => 2;
# http://babelmark.bobtfish.net/?markdown=x%3Cmax(a%2Cb)%0D%0A&normalize=on
use_ok('Text::Markdown');
my $m = Text::Markdown->new;
my $in = q{xx<max(a,b)};
{
local $TODO = 'Known "bug" (the no < unless next to space thing was originally by design) - but I would like to
break the spec and fix this..';
is ($m->markdown($in), $ex);
};
Text-Markdown-1.0.26/t/32tabwidth.t 0000644 0000765 0000024 00000001222 11233534574 015276 0 ustar t0m staff use strict;
use warnings;
use Test::More tests => 4;
use_ok( 'Text::Markdown' );
my $m = Text::Markdown->new( tab_width => 2 );
my $instr = q{start
HTML block
end
};
my $expstr = q{start
<h1>HTML block</h1>
end
};
is($m->markdown($instr) => $expstr, 'Correct (constructor)');
is(Text::Markdown->new->markdown($instr, { tab_width => 2}) => $expstr, 'Correct (markdown method option)');
my $txt = $m->markdown(<<'END_MARKDOWN');
This is a para.
This is code.
---
This is code.
This is a para.
END_MARKDOWN
unlike($txt, qr{