diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-04-27 23:38:33 +0200 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-07-09 21:23:05 -0400 |
commit | 6a477b9bfc5bf9b32c9a961269066694d1216dce (patch) | |
tree | f80ade54e454079ae87caf0541a8274948f13b0f /lib/banzai/filter | |
parent | 92772f85c1c68858b962b4934f3c5ee2e0849c14 (diff) | |
download | gitlab-ce-6a477b9bfc5bf9b32c9a961269066694d1216dce.tar.gz |
Add blockquote fence syntax to Markdown
Diffstat (limited to 'lib/banzai/filter')
-rw-r--r-- | lib/banzai/filter/blockquote_fence_filter.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/banzai/filter/blockquote_fence_filter.rb b/lib/banzai/filter/blockquote_fence_filter.rb new file mode 100644 index 00000000000..fb815c2d837 --- /dev/null +++ b/lib/banzai/filter/blockquote_fence_filter.rb @@ -0,0 +1,50 @@ +module Banzai + module Filter + class BlockquoteFenceFilter < HTML::Pipeline::TextFilter + REGEX = %r{ + (?<code> + # Code blocks: + # ``` + # Anything, including ignored `>>>` blocks + # ``` + ^```.+?\n```$ + ) + | + (?<html> + # HTML: + # <tag> + # Anything, including ignored `>>>` blocks + # </tag> + ^<[^>]+?>.+?\n<\/[^>]+?>$ + ) + | + ( + ^>>>\n(?<quote> + (?: + (?!^```|^<[^>]+?>). + | + \g<code> + | + \g<html> + ) + +?)\n>>>$ + ) + }mx.freeze + + def initialize(text, context = nil, result = nil) + super text, context, result + @text = @text.delete "\r" + end + + def call + @text.gsub(REGEX) do + if $~[:quote] + $~[:quote].gsub(/^/, "> ").gsub(/^> $/, ">") + else + $~[0] + end + end + end + end + end +end |