summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-04-27 23:38:33 +0200
committerDouwe Maan <douwe@selenight.nl>2016-07-09 21:23:05 -0400
commit6a477b9bfc5bf9b32c9a961269066694d1216dce (patch)
treef80ade54e454079ae87caf0541a8274948f13b0f /lib
parent92772f85c1c68858b962b4934f3c5ee2e0849c14 (diff)
downloadgitlab-ce-6a477b9bfc5bf9b32c9a961269066694d1216dce.tar.gz
Add blockquote fence syntax to Markdown
Diffstat (limited to 'lib')
-rw-r--r--lib/banzai/filter/blockquote_fence_filter.rb50
-rw-r--r--lib/banzai/pipeline/pre_process_pipeline.rb3
2 files changed, 52 insertions, 1 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
diff --git a/lib/banzai/pipeline/pre_process_pipeline.rb b/lib/banzai/pipeline/pre_process_pipeline.rb
index 50dc978b452..6cf219661d3 100644
--- a/lib/banzai/pipeline/pre_process_pipeline.rb
+++ b/lib/banzai/pipeline/pre_process_pipeline.rb
@@ -3,7 +3,8 @@ module Banzai
class PreProcessPipeline < BasePipeline
def self.filters
FilterArray[
- Filter::YamlFrontMatterFilter
+ Filter::YamlFrontMatterFilter,
+ Filter::BlockquoteFenceFilter,
]
end