Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
55d92323
Commit
55d92323
authored
Aug 14, 2015
by
Albert Ting
Committed by
David Lawrence
Aug 14, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 1154116 - Some markdown structures are not ignored in fenced code blocks
r=dkl,a=sgreen
parent
ac956759
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
13 deletions
+37
-13
Markdown.pm
Bugzilla/Markdown.pm
+37
-13
No files found.
Bugzilla/Markdown.pm
View file @
55d92323
...
@@ -44,6 +44,8 @@ $g_nested_parens = qr{
...
@@ -44,6 +44,8 @@ $g_nested_parens = qr{
}
x
;
}
x
;
our
%
g_escape_table
;
our
%
g_escape_table
;
my
@code_blocks
;
foreach
my
$char
(
split
//
,
'\\`*_{}[]()>#+-.!~'
)
{
foreach
my
$char
(
split
//
,
'\\`*_{}[]()>#+-.!~'
)
{
$g_escape_table
{
$char
}
=
md5_hex
(
$char
);
$g_escape_table
{
$char
}
=
md5_hex
(
$char
);
}
}
...
@@ -104,13 +106,37 @@ sub _RunSpanGamut {
...
@@ -104,13 +106,37 @@ sub _RunSpanGamut {
return
$text
;
return
$text
;
}
}
# We first replace all fenced code blocks with just their
# surrounding backticks and an empty body to know where
# they are exactly for later processing. The bodies of
# blocks will be in an array. This measure is taken to not
# interpret fenced code blocks contents as possible markdown
# structures. The contents of the body will be processed after
# processing markdown structures.
sub
_removeFencedCodeBlocks
{
my
(
$self
,
$text
)
=
@_
;
$text
=~
s{
^ `{3,} [\s\t]
*
\
n
(
# $1 = the entire code block
(?:
.*
\
n
+
)
+
?
)
`{3,} [\s\t]* $
}{
push @code_blocks, $1;
"%%%FENCED_BLOCK%%%";
}egmx;
return $text;
}
# Override to check for HTML-escaped <>" chars.
# Override to check for HTML-escaped <>" chars.
sub _StripLinkDefinitions {
sub _StripLinkDefinitions {
#
# Strips link definitions from text, stores the URLs and titles in
# hash references.
#
my ($self, $text) = @_;
my ($self, $text) = @_;
$text = $self->_removeFencedCodeBlocks($text);
#
# Strips link definitions from text, stores the URLs and titles in
# hash references.
#
my $less_than_tab = $self->{tab_width} - 1;
my $less_than_tab = $self->{tab_width} - 1;
# Link defs are in the form: ^[id]: url "optional title"
# Link defs are in the form: ^[id]: url "optional title"
...
@@ -377,14 +403,14 @@ sub _DoCodeSpans {
...
@@ -377,14 +403,14 @@ sub _DoCodeSpans {
sub _DoCodeBlocks {
sub _DoCodeBlocks {
my ($self, $text) = @_;
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{
$text =~ s{
^ `{3,} [\s\t]
*
\
n
^ %%%FENCED_BLOCK%%%
(
# $1 = the entire code block
(?:
.*
\
n
+
)
+
?
)
`
{
3
,}
[
\
s\t]* $
}{
}{
my $codeblock =
$1
;
my $codeblock =
shift @code_blocks
;
my $result;
my $result;
$codeblock = $self->_EncodeCode($codeblock);
$codeblock = $self->_EncodeCode($codeblock);
...
@@ -395,9 +421,6 @@ sub _DoCodeBlocks {
...
@@ -395,9 +421,6 @@ sub _DoCodeBlocks {
$result;
$result;
}egmx;
}egmx;
# And now do the standard code blocks
$text
=
$self
->
SUPER::
_DoCodeBlocks
(
$text
);
return $text;
return $text;
}
}
...
@@ -417,6 +440,7 @@ sub _DoBlockQuotes {
...
@@ -417,6 +440,7 @@ sub _DoBlockQuotes {
my $bq = $1;
my $bq = $1;
$bq =~ s/^[ \t]*>[ \t]?//gm; # trim one level of quoting
$bq =~ s/^[ \t]*>[ \t]?//gm; # trim one level of quoting
$bq =~ s/^[ \t]+$//mg; # trim whitespace-only lines
$bq =~ s/^[ \t]+$//mg; # trim whitespace-only lines
$bq = $self->_removeFencedCodeBlocks($bq);
$bq = $self->_RunBlockGamut($bq, {wrap_in_p_tags => 1}); # recurse
$bq = $self->_RunBlockGamut($bq, {wrap_in_p_tags => 1}); # recurse
$bq =~ s/^/ /mg;
$bq =~ s/^/ /mg;
# These leading spaces screw with <pre> content, so we need to fix that:
# These leading spaces screw with <pre> content, so we need to fix that:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment