summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorAlbert Ting <altlist@gmail.com>2016-03-27 23:08:08 +0200
committerFrédéric Buclin <LpSolit@gmail.com>2016-03-27 23:08:08 +0200
commitc9ba7ae53567600d34dc401f5a0746ca45dad331 (patch)
tree6d5dff1566ea9940041671cba755ca4cb8535eb5 /Bugzilla
parenta6562e03893e2d6f3c5719f4cc36e53067277959 (diff)
downloadbugzilla-c9ba7ae53567600d34dc401f5a0746ca45dad331.tar.gz
bugzilla-c9ba7ae53567600d34dc401f5a0746ca45dad331.tar.xz
Bug 1205072: Markdown should not call quoteUrl() for code sections
r=LpSolit
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Markdown.pm38
1 files changed, 29 insertions, 9 deletions
diff --git a/Bugzilla/Markdown.pm b/Bugzilla/Markdown.pm
index 212f1e093..49f49c9b0 100644
--- a/Bugzilla/Markdown.pm
+++ b/Bugzilla/Markdown.pm
@@ -18,6 +18,10 @@ use Digest::MD5 qw(md5_hex);
use parent qw(Text::MultiMarkdown);
+# use private code points
+use constant FENCED_BLOCK => "\N{U+F111}";
+use constant INDENTED_FENCED_BLOCK => "\N{U+F222}";
+
# Regex to match balanced [brackets]. See Friedl's
# "Mastering Regular Expressions", 2nd Ed., pp. 328-331.
our ($g_nested_brackets, $g_nested_parens);
@@ -74,6 +78,7 @@ sub _Markdown {
my $self = shift;
my $text = shift;
+ $text = $self->_removeFencedCodeBlocks($text);
$text = Bugzilla::Template::quoteUrls($text, undef, undef, undef, 1);
return $self->SUPER::_Markdown($text, @_);
@@ -85,6 +90,12 @@ sub _code_blocks {
return $self->{code_blocks};
}
+sub _indented_code_blocks {
+ my ($self) = @_;
+ $self->{indented_code_blocks} = $self->{params}->{indented_code_blocks} ||= [];
+ return $self->{indented_code_blocks};
+}
+
sub _RunSpanGamut {
# These are all the transformations that occur *within* block-level
# tags like paragraphs, headers, and list items.
@@ -126,7 +137,21 @@ sub _removeFencedCodeBlocks {
`{3,} [\s\t]* $
}{
push @{$self->_code_blocks}, $1;
- "%%%FENCED_BLOCK%%%";
+ "${\FENCED_BLOCK}\n";
+ }egmx;
+
+ $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
+ }{
+ push @{$self->_indented_code_blocks}, $1;
+ "\n${\INDENTED_FENCED_BLOCK}\n";
}egmx;
return $text;
}
@@ -135,7 +160,6 @@ sub _removeFencedCodeBlocks {
sub _StripLinkDefinitions {
my ($self, $text) = @_;
- $text = $self->_removeFencedCodeBlocks($text);
#
# Strips link definitions from text, stores the URLs and titles in
# hash references.
@@ -406,14 +430,11 @@ sub _DoCodeSpans {
sub _DoCodeBlocks {
my ($self, $text) = @_;
- # First, do the standard code blocks to avoid generating nested code blocks
- # if the block is both indented and is surrounded by backticks.
- $text = $self->SUPER::_DoCodeBlocks($text);
-
$text =~ s{
- ^ %%%FENCED_BLOCK%%%
+ ^ (${\FENCED_BLOCK}|${\INDENTED_FENCED_BLOCK})
}{
- my $codeblock = shift @{$self->_code_blocks};
+ my $aref = ($1 eq FENCED_BLOCK) ? $self->_code_blocks : $self->_indented_code_blocks;
+ my $codeblock = shift @$aref;
my $result;
$codeblock = $self->_EncodeCode($codeblock);
@@ -443,7 +464,6 @@ sub _DoBlockQuotes {
my $bq = $1;
$bq =~ s/^[ \t]*&gt;[ \t]?//gm; # trim one level of quoting
$bq =~ s/^[ \t]+$//mg; # trim whitespace-only lines
- $bq = $self->_removeFencedCodeBlocks($bq);
$bq = $self->_RunBlockGamut($bq, {wrap_in_p_tags => 1}); # recurse
$bq =~ s/^/ /mg;
# These leading spaces screw with <pre> content, so we need to fix that: