]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1519564 - Add a mechanism for disabling all special markdown syntax
authorDylan William Hardison <dylan@hardison.net>
Wed, 16 Jan 2019 15:29:12 +0000 (10:29 -0500)
committerGitHub <noreply@github.com>
Wed, 16 Jan 2019 15:29:12 +0000 (10:29 -0500)
Bugzilla/Markdown.pm
Bugzilla/Template.pm

index 8e3c85f55e32e2f29d8127aaa75a22893c1c6154..0693687012c96df13ddb6c90eaad5a205ff5ec32 100644 (file)
@@ -11,6 +11,7 @@ use Moo;
 
 use Encode;
 use Mojo::DOM;
+use Mojo::Util qw(trim);
 use HTML::Escape qw(escape_html);
 use List::MoreUtils qw(any);
 
@@ -39,11 +40,22 @@ sub _build_markdown_parser {
   }
 }
 
+my $MARKDOWN_OFF = quotemeta '#[markdown(off)]';
 sub render_html {
   my ($self, $markdown, $bug, $comment, $user) = @_;
   my $parser = $self->markdown_parser;
   return escape_html($markdown) unless $parser;
 
+  # This makes sure we never handle > foo text in the shortcuts code.
+  local $Bugzilla::Template::COLOR_QUOTES = 0;
+
+  if ($markdown =~ /^\s*$MARKDOWN_OFF\n/s) {
+    my $text = $self->bugzilla_shorthand->( trim($markdown) );
+    my @p = split(/\n{2,}/, $text);
+    my $html = join("\n", map { s/\n/<br>\n/gs; "<p>$_</p>\n" } @p );
+    return $html;
+  }
+
   no warnings 'utf8'; # this is needed because our perl is so old.
   # This is a bit faster since it doesn't engage the regex engine.
   # Replace < with \x{FDD4}, and remove \x{FDD4}.
index 1ff8e6c2d3c962da7267dc0b4b63cda7d2a6aca6..6fbc3eeabe566d4f41a3edf9b0bc06a549a6339e 100644 (file)
@@ -50,6 +50,7 @@ use constant FORMAT_DOUBLE => '%19s %-55s';
 use constant FORMAT_2_SIZE => [19, 55];
 
 our %SHARED_PROVIDERS;
+our $COLOR_QUOTES = 1;
 
 # Pseudo-constant.
 sub SAFE_URL_REGEXP {
@@ -216,9 +217,11 @@ sub quoteUrls {
 
   $text = html_quote($text);
 
-  # Color quoted text
-  $text =~ s~^(&gt;.+)$~<span class="quote">$1</span >~mg;
-  $text =~ s~</span >\n<span class="quote">~\n~g;
+  if ($COLOR_QUOTES) {
+    # Color quoted text
+    $text =~ s~^(&gt;.+)$~<span class="quote">$1</span >~mg;
+    $text =~ s~</span >\n<span class="quote">~\n~g;
+  }
 
   # mailto:
   # Use |<nothing> so that $1 is defined regardless