tags around the output.
sub _FormParagraphs {
my ($self, $text) = @_;
return $self->SUPER::_FormParagraphs($text, { wrap_in_p_tags => 0 });
}
sub _DoStrikethroughs {
my ($self, $text) = @_;
$text =~ s{ ^ ~~ (?=\S) ([^~]+?) (?<=\S) ~~ (?!~) }{$1}gsx;
$text =~ s{ (?<=_|[^~\w]) ~~ (?=\S) ([^~]+?) (?<=\S) ~~ (?!~) }{$1}gsx;
return $text;
}
# The original _DoCodeSpans() uses the 's' modifier in its regex
# which prevents _DoCodeBlocks() to match GFM fenced code blocks.
# We copy the code from the original implementation and remove the
# 's' modifier from it.
sub _DoCodeSpans {
my ($self, $text) = @_;
$text =~ s@
(?_EncodeCode($c);
"$c
";
@egx;
return $text;
}
# Override to add GFM Fenced Code Blocks
sub _DoCodeBlocks {
my ($self, $text) = @_;
$text =~ s{
^ `{3,} [\s\t]* \n
( # $1 = the entire code block
(?: .* \n+)+?
)
`{3,} [\s\t]* $
}{
my $codeblock = $1;
my $result;
$codeblock = $self->_EncodeCode($codeblock);
$codeblock = $self->_Detab($codeblock);
$codeblock =~ s/\n\z//; # remove the trailing newline
$result = "\n\n
" . $codeblock . "
\n\n";
$result;
}egmx;
# And now do the standard code blocks
$text = $self->SUPER::_DoCodeBlocks($text);
return $text;
}
sub _EncodeCode {
my ($self, $text) = @_;
# We need to unescape the escaped HTML characters in code blocks.
# These are the reverse of the escapings done in Bugzilla::Util::html_quote()
$text =~ s/<//g;
$text =~ s/"/"/g;
$text =~ s/@/@/g;
# '&' substitution must be the last one, otherwise a literal like '>'
# will turn to '>' because '&' is already changed to '&' in Bugzilla::Util::html_quote().
# In other words, html_quote() will change '>' to '>' and then we will
# change '>' -> '>' -> '>' if we write this substitution as the first one.
$text =~ s/&/&/g;
$text =~ s{ \1 }{$1}xmgi;
$text = $self->SUPER::_EncodeCode($text);
$text =~ s/~/$g_escape_table{'~'}/go;
# Encode '<' to prevent URLs from getting linkified in code spans
$text =~ s/</$g_escape_table{'<'}/go;
return $text;
}
sub _EncodeBackslashEscapes {
my ($self, $text) = @_;
$text = $self->SUPER::_EncodeBackslashEscapes($text);
$text =~ s/\\~/$g_escape_table{'~'}/go;
return $text;
}
sub _UnescapeSpecialChars {
my ($self, $text) = @_;
$text = $self->SUPER::_UnescapeSpecialChars($text);
$text =~ s/$g_escape_table{'~'}/~/go;
$text =~ s/$g_escape_table{'<'}/</go;
return $text;
}
# Check if the passed string is of the form multiple_underscores_in_a_word.
# To check that, we first need to make sure that the string does not contain
# any white-space. Then, if the string is composed of non-space chunks which
# are bound together with underscores, the string has the desired form.
sub _has_multiple_underscores {
my $string = shift;
return 0 unless defined($string) && length($string);
return 0 if $string =~ /[\t\s]+/;
return 1 if scalar (split /_/, $string) > 1;
return 0;
}
1;
__END__
=head1 NAME
Bugzilla::Markdown - Generates HTML output from structured plain-text input.
=head1 SYNOPSIS
use Bugzilla::Markdown;
my $markdown = Bugzilla::Markdown->new();
print $markdown->markdown($text);
=head1 DESCRIPTION
Bugzilla::Markdown implements a Markdown engine that produces
an HTML-based output from a given plain-text input.
The majority of the implementation is done by C