Skip to content

Commit 8319952

Browse files
authored
Merge pull request #279 from gwincr11/cg-config-commonmarker-extensions
Let users set the common marker extensions
2 parents 49d02d2 + dc0f98a commit 8319952

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/html/pipeline/markdown_filter.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Pipeline
1212
#
1313
# Context options:
1414
# :gfm => false Disable GFM line-end processing
15+
# :commonmarker_extensions => [ :table, :strikethrough,
16+
# :tagfilter, :autolink ] Common marker extensions to include
1517
#
1618
# This filter does not write any additional information to the context hash.
1719
class MarkdownFilter < TextFilter
@@ -25,7 +27,10 @@ def initialize(text, context = nil, result = nil)
2527
def call
2628
options = [:GITHUB_PRE_LANG]
2729
options << :HARDBREAKS if context[:gfm] != false
28-
html = CommonMarker.render_html(@text, options, [:table, :strikethrough, :tagfilter, :autolink])
30+
extensions = context.fetch(
31+
:commonmarker_extensions,
32+
[:table, :strikethrough, :tagfilter, :autolink])
33+
html = CommonMarker.render_html(@text, options, extensions)
2934
html.rstrip!
3035
html
3136
end

test/html/pipeline/markdown_filter_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ def test_fenced_code_blocks_with_language
4848
assert_equal 1, doc.search('pre').size
4949
assert_equal 'ruby', doc.search('pre').first['lang']
5050
end
51+
52+
def test_standard_extensions
53+
iframe = "<iframe src='http://www.google.com'></iframe>"
54+
iframe_escaped = "&lt;iframe src='http://www.google.com'>&lt;/iframe>"
55+
doc = MarkdownFilter.new(iframe).call
56+
assert_equal(doc, iframe_escaped)
57+
end
58+
59+
def test_changing_extensions
60+
iframe = "<iframe src='http://www.google.com'></iframe>"
61+
doc = MarkdownFilter.new(iframe, commonmarker_extensions: []).call
62+
assert_equal(doc, iframe)
63+
end
5164
end
5265

5366
class GFMTest < Minitest::Test

0 commit comments

Comments
 (0)