From a5af4bbea66c30516d6807320eace25889378da0 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Sun, 31 Dec 2023 21:25:45 +0900 Subject: [PATCH 1/9] Convert CommonMarkerTemplate to subclass of StaticTemplate --- lib/tilt/commonmarker.rb | 91 +++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/lib/tilt/commonmarker.rb b/lib/tilt/commonmarker.rb index d404744..04cc3f8 100644 --- a/lib/tilt/commonmarker.rb +++ b/lib/tilt/commonmarker.rb @@ -2,53 +2,56 @@ require_relative 'template' require 'commonmarker' -aliases = { - :smartypants => :SMART -}.freeze -parse_opts = [ - :FOOTNOTES, - :LIBERAL_HTML_TAG, - :SMART, - :smartypants, - :STRIKETHROUGH_DOUBLE_TILDE, - :UNSAFE, - :VALIDATE_UTF8, -].freeze -render_opts = [ - :FOOTNOTES, - :FULL_INFO_STRING, - :GITHUB_PRE_LANG, - :HARDBREAKS, - :NOBREAKS, - :SAFE, # Removed in v0.18.0 (2018-10-17) - :SOURCEPOS, - :TABLE_PREFER_STYLE_ATTRIBUTES, - :UNSAFE, -].freeze -exts = [ - :autolink, - :strikethrough, - :table, - :tagfilter, - :tasklist, -].freeze +module Tilt + class CommonMarkerTemplate < StaticTemplate + def prepare + aliases = { + :smartypants => :SMART + }.freeze + parse_opts = [ + :FOOTNOTES, + :LIBERAL_HTML_TAG, + :SMART, + :smartypants, + :STRIKETHROUGH_DOUBLE_TILDE, + :UNSAFE, + :VALIDATE_UTF8, + ].freeze + render_opts = [ + :FOOTNOTES, + :FULL_INFO_STRING, + :GITHUB_PRE_LANG, + :HARDBREAKS, + :NOBREAKS, + :SAFE, # Removed in v0.18.0 (2018-10-17) + :SOURCEPOS, + :TABLE_PREFER_STYLE_ATTRIBUTES, + :UNSAFE, + ].freeze + exts = [ + :autolink, + :strikethrough, + :table, + :tagfilter, + :tasklist, + ].freeze + extensions = exts.select do |extension| + @options[extension] + end -Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do - extensions = exts.select do |extension| - @options[extension] - end + parse_options, render_options = [parse_opts, render_opts].map do |opts| + opts = opts.select do |option| + @options[option] + end.map! do |option| + aliases[option] || option + end - parse_options, render_options = [parse_opts, render_opts].map do |opts| - opts = opts.select do |option| - @options[option] - end.map! do |option| - aliases[option] || option - end + opts = :DEFAULT unless opts.any? + opts + end - opts = :DEFAULT unless opts.any? - opts + @output = CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions) + end end - - CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions) end From 1906bcf6d44d0ab29cea48246bd121cba55da0dd Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Sun, 31 Dec 2023 21:30:07 +0900 Subject: [PATCH 2/9] Constantize --- lib/tilt/commonmarker.rb | 68 ++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/tilt/commonmarker.rb b/lib/tilt/commonmarker.rb index 04cc3f8..90dd149 100644 --- a/lib/tilt/commonmarker.rb +++ b/lib/tilt/commonmarker.rb @@ -4,47 +4,47 @@ module Tilt class CommonMarkerTemplate < StaticTemplate - def prepare - aliases = { - :smartypants => :SMART - }.freeze - parse_opts = [ - :FOOTNOTES, - :LIBERAL_HTML_TAG, - :SMART, - :smartypants, - :STRIKETHROUGH_DOUBLE_TILDE, - :UNSAFE, - :VALIDATE_UTF8, - ].freeze - render_opts = [ - :FOOTNOTES, - :FULL_INFO_STRING, - :GITHUB_PRE_LANG, - :HARDBREAKS, - :NOBREAKS, - :SAFE, # Removed in v0.18.0 (2018-10-17) - :SOURCEPOS, - :TABLE_PREFER_STYLE_ATTRIBUTES, - :UNSAFE, - ].freeze - exts = [ - :autolink, - :strikethrough, - :table, - :tagfilter, - :tasklist, - ].freeze + ALIASES = { + :smartypants => :SMART + }.freeze + PARSE_OPTS = [ + :FOOTNOTES, + :LIBERAL_HTML_TAG, + :SMART, + :smartypants, + :STRIKETHROUGH_DOUBLE_TILDE, + :UNSAFE, + :VALIDATE_UTF8, + ].freeze + RENDER_OPTS = [ + :FOOTNOTES, + :FULL_INFO_STRING, + :GITHUB_PRE_LANG, + :HARDBREAKS, + :NOBREAKS, + :SAFE, # Removed in v0.18.0 (2018-10-17) + :SOURCEPOS, + :TABLE_PREFER_STYLE_ATTRIBUTES, + :UNSAFE, + ].freeze + EXTS = [ + :autolink, + :strikethrough, + :table, + :tagfilter, + :tasklist, + ].freeze - extensions = exts.select do |extension| + def prepare + extensions = EXTS.select do |extension| @options[extension] end - parse_options, render_options = [parse_opts, render_opts].map do |opts| + parse_options, render_options = [PARSE_OPTS, RENDER_OPTS].map do |opts| opts = opts.select do |option| @options[option] end.map! do |option| - aliases[option] || option + ALIASES[option] || option end opts = :DEFAULT unless opts.any? From 04d0ba66677032b67536e293181c95a98c0b3e98 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Sun, 31 Dec 2023 21:44:53 +0900 Subject: [PATCH 3/9] define prepare_pre and just invoke it in prepare --- lib/tilt/commonmarker.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tilt/commonmarker.rb b/lib/tilt/commonmarker.rb index 90dd149..36edcc8 100644 --- a/lib/tilt/commonmarker.rb +++ b/lib/tilt/commonmarker.rb @@ -36,6 +36,10 @@ class CommonMarkerTemplate < StaticTemplate ].freeze def prepare + prepare_pre + end + + private def prepare_pre extensions = EXTS.select do |extension| @options[extension] end From 2a342cd285afd50116631e6325b3582ec6959f29 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Mon, 1 Jan 2024 00:29:06 +0900 Subject: [PATCH 4/9] Env var for commonmarker version --- .ci.gemfile | 8 +++++++- .github/workflows/ci.yml | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.ci.gemfile b/.ci.gemfile index 83f4e2b..b4d93a1 100644 --- a/.ci.gemfile +++ b/.ci.gemfile @@ -74,7 +74,13 @@ platform :ruby do gem 'rinku' # dependency for wikicloth for handling links gem 'RedCloth' - gem 'commonmarker', '< 1' + + if ENV['LATEST_COMMONMARKER'] == 'yes' + gem 'commonmarker' + else + gem 'commonmarker', '< 1' + end + gem 'rdiscount', '>= 2.1.6' gem 'redcarpet' gem 'yajl-ruby' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcaa7e0..7b80f92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,10 +17,19 @@ jobs: fail-fast: false matrix: ruby: [ "2.0.0", 2.1, 2.3, 2.4, 2.5, 2.6, 2.7, "3.0", 3.1, 3.2, 3.3, jruby-9.1, jruby-9.2, jruby-9.3, jruby-9.4 ] + latest_commonmarker: ["", "yes"] + include: + - ruby: "3.1" + latest_commonmarker: "yes" + - ruby: "3.2" + latest_commonmarker: "yes" + - ruby: "3.3" + latest_commonmarker: "yes" name: ${{ matrix.ruby }} env: BUNDLE_GEMFILE: .ci.gemfile COFFEE_SCRIPT: use + LATEST_COMMONMARKER: ${{ matrix.latest_commonmarker }} steps: - uses: actions/checkout@v4 # WikiCloth needs IDN From fbb104d19ad6876d04c394efbfe76b886e0633a9 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Mon, 1 Jan 2024 00:29:39 +0900 Subject: [PATCH 5/9] Support commonmarker v1 api The Commonmarker gem released v1 incluging breaking api changes. https://github.com/gjtorikian/commonmarker/releases/tag/v1.0.0 These changes supports the new commonmarker's api. --- lib/tilt/commonmarker.rb | 43 +++++++++++- test/tilt_commonmarkertemplate_test.rb | 91 ++++++++++++++++++++------ 2 files changed, 112 insertions(+), 22 deletions(-) diff --git a/lib/tilt/commonmarker.rb b/lib/tilt/commonmarker.rb index 36edcc8..3ffb994 100644 --- a/lib/tilt/commonmarker.rb +++ b/lib/tilt/commonmarker.rb @@ -35,8 +35,38 @@ class CommonMarkerTemplate < StaticTemplate :tasklist, ].freeze + V1_PARSE_OPTS = [ + :smart, + :default_info_string, + ].freeze + V1_RENDER_OPTS = [ + :hardbreaks, + :github_pre_lang, + :width, + :unsafe, + :escape, + :sourcepos, + ].freeze + V1_EXTS = [ + :strikethrough, + :tagfilter, + :table, + :autolink, + :tasklist, + :superscript, + :header_ids, + :footnotes, + :description_lists, + :front_matter_delimiter, + :shortcodes, + ].freeze + def prepare - prepare_pre + if commonmaker_v1_or_later? + prepare_v1 + else + prepare_pre + end end private def prepare_pre @@ -57,5 +87,16 @@ def prepare @output = CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions) end + + private def prepare_v1 + parse_options = @options.select { |key, _| V1_PARSE_OPTS.include?(key) } + render_options = @options.select { |key, _| V1_RENDER_OPTS.include?(key) } + extensions = @options.select { |key, _| V1_EXTS.include?(key) } + @output = Commonmarker.to_html(@data, options: { parse: parse_options, render: render_options, extension: extensions }) + end + + private def commonmaker_v1_or_later? + defined?(::Commonmarker) ? true : false + end end end diff --git a/test/tilt_commonmarkertemplate_test.rb b/test/tilt_commonmarkertemplate_test.rb index c381e81..10d33c6 100644 --- a/test/tilt_commonmarkertemplate_test.rb +++ b/test/tilt_commonmarkertemplate_test.rb @@ -1,26 +1,27 @@ require_relative 'test_helper' checked_describe 'tilt/commonmarker' do - it "preparing and evaluating templates on #render" do - template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } - assert_equal "

Hello World!

\n", template.render - end + if ENV['LATEST_COMMONMARKER'] == 'yes' + it "preparing and evaluating templates on #render" do + template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } + assert_equal "

Hello World!

\n", template.render + end - it "can be rendered more than once" do - template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } - 3.times { assert_equal "

Hello World!

\n", template.render } - end + it "can be rendered more than once" do + template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } + 3.times { assert_equal "

Hello World!

\n", template.render } + end - it "smartypants when :smartypants is set" do - template = Tilt::CommonMarkerTemplate.new(:smartypants => true) do |t| - "OKAY -- 'Smarty Pants'" + it "smartypants when :smatr is set" do + template = Tilt::CommonMarkerTemplate.new(smart: true) do |t| + "OKAY -- 'Smarty Pants'" + end + assert_match('

OKAY – ‘Smarty Pants’

', template.render) end - assert_match('

OKAY – ‘Smarty Pants’

', template.render) - end - it 'Renders unsafe HTML when :UNSAFE is set' do - template = Tilt::CommonMarkerTemplate.new(UNSAFE: true) do |_t| - <
TL;DR

This is an unsafe HTML block

@@ -28,9 +29,56 @@ And then some **other** Markdown MARKDOWN + end + + expected = < +
TL;DR
+

This is an unsafe HTML block

+ +

And then some other Markdown

+EXPECTED_HTML + + assert_match(expected, template.render) + end + + it "autolinking when :autolink is set" do + template = Tilt::CommonMarkerTemplate.new(autolink: true) do |t| + "https://example.com" + end + assert_match('https://example.com', template.render) + end + else + it "preparing and evaluating templates on #render" do + template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } + assert_equal "

Hello World!

\n", template.render end - expected = <Hello World!\n", template.render } + end + + it "smartypants when :smartypants is set" do + template = Tilt::CommonMarkerTemplate.new(:smartypants => true) do |t| + "OKAY -- 'Smarty Pants'" + end + assert_match('

OKAY – ‘Smarty Pants’

', template.render) + end + + it 'Renders unsafe HTML when :UNSAFE is set' do + template = Tilt::CommonMarkerTemplate.new(UNSAFE: true) do |_t| + < +
TL;DR
+

This is an unsafe HTML block

+ + +And then some **other** Markdown +MARKDOWN + end + + expected = <
TL;DR

This is an unsafe HTML block

@@ -38,10 +86,11 @@

And then some other Markdown

EXPECTED_HTML - assert_match(expected, template.render) - end + assert_match(expected, template.render) + end - it "sets allows_script metadata set to false" do - assert_equal false, Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" }.metadata[:allows_script] + it "sets allows_script metadata set to false" do + assert_equal false, Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" }.metadata[:allows_script] + end end end From 597a139f3fb829cdeab2c91aa6532744ed1bdfa1 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Sat, 6 Jan 2024 03:34:06 +0900 Subject: [PATCH 6/9] Switch to constant name approach --- lib/tilt/commonmarker.rb | 163 ++++++++++++------------- test/tilt_commonmarkertemplate_test.rb | 49 +------- 2 files changed, 77 insertions(+), 135 deletions(-) diff --git a/lib/tilt/commonmarker.rb b/lib/tilt/commonmarker.rb index 3ffb994..d74f454 100644 --- a/lib/tilt/commonmarker.rb +++ b/lib/tilt/commonmarker.rb @@ -2,101 +2,88 @@ require_relative 'template' require 'commonmarker' -module Tilt - class CommonMarkerTemplate < StaticTemplate - ALIASES = { - :smartypants => :SMART - }.freeze - PARSE_OPTS = [ - :FOOTNOTES, - :LIBERAL_HTML_TAG, - :SMART, - :smartypants, - :STRIKETHROUGH_DOUBLE_TILDE, - :UNSAFE, - :VALIDATE_UTF8, - ].freeze - RENDER_OPTS = [ - :FOOTNOTES, - :FULL_INFO_STRING, - :GITHUB_PRE_LANG, - :HARDBREAKS, - :NOBREAKS, - :SAFE, # Removed in v0.18.0 (2018-10-17) - :SOURCEPOS, - :TABLE_PREFER_STYLE_ATTRIBUTES, - :UNSAFE, - ].freeze - EXTS = [ - :autolink, - :strikethrough, - :table, - :tagfilter, - :tasklist, - ].freeze +if defined?(::Commonmarker) + parse_opts = [ + :smart, + :default_info_string, + ].freeze + render_opts = [ + :hardbreaks, + :github_pre_lang, + :width, + :unsafe, + :escape, + :sourcepos, + ].freeze + exts = [ + :strikethrough, + :tagfilter, + :table, + :autolink, + :tasklist, + :superscript, + :header_ids, + :footnotes, + :description_lists, + :front_matter_delimiter, + :shortcodes, + ].freeze - V1_PARSE_OPTS = [ - :smart, - :default_info_string, - ].freeze - V1_RENDER_OPTS = [ - :hardbreaks, - :github_pre_lang, - :width, - :unsafe, - :escape, - :sourcepos, - ].freeze - V1_EXTS = [ - :strikethrough, - :tagfilter, - :table, - :autolink, - :tasklist, - :superscript, - :header_ids, - :footnotes, - :description_lists, - :front_matter_delimiter, - :shortcodes, - ].freeze + Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do + parse_options = @options.select { |key, _| parse_opts.include?(key) } + render_options = @options.select { |key, _| render_opts.include?(key) } + extensions = @options.select { |key, _| exts.include?(key) } - def prepare - if commonmaker_v1_or_later? - prepare_v1 - else - prepare_pre - end - end - - private def prepare_pre - extensions = EXTS.select do |extension| - @options[extension] - end + Commonmarker.to_html(@data, options: { parse: parse_options, render: render_options, extension: extensions }) + end +else + aliases = { + :smartypants => :SMART + }.freeze + parse_opts = [ + :FOOTNOTES, + :LIBERAL_HTML_TAG, + :SMART, + :smartypants, + :STRIKETHROUGH_DOUBLE_TILDE, + :UNSAFE, + :VALIDATE_UTF8, + ].freeze + render_opts = [ + :FOOTNOTES, + :FULL_INFO_STRING, + :GITHUB_PRE_LANG, + :HARDBREAKS, + :NOBREAKS, + :SAFE, # Removed in v0.18.0 (2018-10-17) + :SOURCEPOS, + :TABLE_PREFER_STYLE_ATTRIBUTES, + :UNSAFE, + ].freeze + exts = [ + :autolink, + :strikethrough, + :table, + :tagfilter, + :tasklist, + ].freeze - parse_options, render_options = [PARSE_OPTS, RENDER_OPTS].map do |opts| - opts = opts.select do |option| - @options[option] - end.map! do |option| - ALIASES[option] || option - end + Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do + extensions = exts.select do |extension| + @options[extension] + end - opts = :DEFAULT unless opts.any? - opts + parse_options, render_options = [parse_opts, render_opts].map do |opts| + opts = opts.select do |option| + @options[option] + end.map! do |option| + aliases[option] || option end - @output = CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions) - end - - private def prepare_v1 - parse_options = @options.select { |key, _| V1_PARSE_OPTS.include?(key) } - render_options = @options.select { |key, _| V1_RENDER_OPTS.include?(key) } - extensions = @options.select { |key, _| V1_EXTS.include?(key) } - @output = Commonmarker.to_html(@data, options: { parse: parse_options, render: render_options, extension: extensions }) + opts = :DEFAULT unless opts.any? + opts end - private def commonmaker_v1_or_later? - defined?(::Commonmarker) ? true : false - end + CommonMarker.render_doc(@data, parse_options, extensions).to_html(render_options, extensions) end end diff --git a/test/tilt_commonmarkertemplate_test.rb b/test/tilt_commonmarkertemplate_test.rb index 10d33c6..4caca2c 100644 --- a/test/tilt_commonmarkertemplate_test.rb +++ b/test/tilt_commonmarkertemplate_test.rb @@ -1,53 +1,8 @@ require_relative 'test_helper' checked_describe 'tilt/commonmarker' do - if ENV['LATEST_COMMONMARKER'] == 'yes' - it "preparing and evaluating templates on #render" do - template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } - assert_equal "

Hello World!

\n", template.render - end - - it "can be rendered more than once" do - template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } - 3.times { assert_equal "

Hello World!

\n", template.render } - end - - it "smartypants when :smatr is set" do - template = Tilt::CommonMarkerTemplate.new(smart: true) do |t| - "OKAY -- 'Smarty Pants'" - end - assert_match('

OKAY – ‘Smarty Pants’

', template.render) - end - - it 'Renders unsafe HTML when :unsafe is set' do - template = Tilt::CommonMarkerTemplate.new(unsafe: true) do |_t| - < -
TL;DR
-

This is an unsafe HTML block

- - -And then some **other** Markdown -MARKDOWN - end - - expected = < -
TL;DR
-

This is an unsafe HTML block

- -

And then some other Markdown

-EXPECTED_HTML - - assert_match(expected, template.render) - end - - it "autolinking when :autolink is set" do - template = Tilt::CommonMarkerTemplate.new(autolink: true) do |t| - "https://example.com" - end - assert_match('https://example.com', template.render) - end + if defined?(::Commonmarker) + # TODO else it "preparing and evaluating templates on #render" do template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } From 041948164b2b75d11b2b454ab9d8c4e7a60fd112 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Sat, 6 Jan 2024 04:10:15 +0900 Subject: [PATCH 7/9] Keep backword compatiblity of commonmarker's option --- lib/tilt/commonmarker.rb | 10 +++- test/tilt_commonmarkertemplate_test.rb | 76 ++++++++++++++++++++------ 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/lib/tilt/commonmarker.rb b/lib/tilt/commonmarker.rb index d74f454..6693aa5 100644 --- a/lib/tilt/commonmarker.rb +++ b/lib/tilt/commonmarker.rb @@ -3,6 +3,9 @@ require 'commonmarker' if defined?(::Commonmarker) + aliases = { + :smartypants => :smart + }.freeze parse_opts = [ :smart, :default_info_string, @@ -30,9 +33,10 @@ ].freeze Tilt::CommonMarkerTemplate = Tilt::StaticTemplate.subclass do - parse_options = @options.select { |key, _| parse_opts.include?(key) } - render_options = @options.select { |key, _| render_opts.include?(key) } - extensions = @options.select { |key, _| exts.include?(key) } + parse_options = @options.select { |key, _| parse_opts.include?(key.downcase) }.transform_keys(&:downcase) + parse_options.merge!(@options.select { |key, _| aliases.has_key?(key) }.transform_keys { |key| aliases[key] }) + render_options = @options.select { |key, _| render_opts.include?(key.downcase) }.transform_keys(&:downcase) + extensions = @options.select { |key, _| exts.include?(key) }.transform_keys(&:downcase) Commonmarker.to_html(@data, options: { parse: parse_options, render: render_options, extension: extensions }) end diff --git a/test/tilt_commonmarkertemplate_test.rb b/test/tilt_commonmarkertemplate_test.rb index 4caca2c..9b68ca2 100644 --- a/test/tilt_commonmarkertemplate_test.rb +++ b/test/tilt_commonmarkertemplate_test.rb @@ -1,27 +1,52 @@ require_relative 'test_helper' checked_describe 'tilt/commonmarker' do - if defined?(::Commonmarker) - # TODO - else - it "preparing and evaluating templates on #render" do - template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } - assert_equal "

Hello World!

\n", template.render - end + it "preparing and evaluating templates on #render" do + template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } + assert_equal "

Hello World!

\n", template.render + end + + it "can be rendered more than once" do + template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } + 3.times { assert_equal "

Hello World!

\n", template.render } + end - it "can be rendered more than once" do - template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" } - 3.times { assert_equal "

Hello World!

\n", template.render } + it "smartypants when :smartypants is set" do + template = Tilt::CommonMarkerTemplate.new(:smartypants => true) do |t| + "OKAY -- 'Smarty Pants'" end + assert_match('

OKAY – ‘Smarty Pants’

', template.render) + end - it "smartypants when :smartypants is set" do - template = Tilt::CommonMarkerTemplate.new(:smartypants => true) do |t| - "OKAY -- 'Smarty Pants'" - end - assert_match('

OKAY – ‘Smarty Pants’

', template.render) + it 'Renders unsafe HTML when :UNSAFE is set' do + template = Tilt::CommonMarkerTemplate.new(UNSAFE: true) do |_t| + < +
TL;DR
+

This is an unsafe HTML block

+ + +And then some **other** Markdown +MARKDOWN end - it 'Renders unsafe HTML when :UNSAFE is set' do + expected = < +
TL;DR
+

This is an unsafe HTML block

+ +

And then some other Markdown

+EXPECTED_HTML + + assert_match(expected, template.render) + end + + it "sets allows_script metadata set to false" do + assert_equal false, Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" }.metadata[:allows_script] + end + + if defined?(::Commonmarker) + it "render unsafe HTML with pre version's option name" do template = Tilt::CommonMarkerTemplate.new(UNSAFE: true) do |_t| < @@ -44,8 +69,23 @@ assert_match(expected, template.render) end - it "sets allows_script metadata set to false" do - assert_equal false, Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" }.metadata[:allows_script] + it "smartypants when :smartypants is set (pre version's option name)" do + template = Tilt::CommonMarkerTemplate.new(:smartypants => true) do |t| + "OKAY -- 'Smarty Pants'" + end + assert_match('

OKAY – ‘Smarty Pants’

', template.render) + end + + it "render markdown with custom prefixed-header id" do + template = Tilt::CommonMarkerTemplate.new(header_ids: "prefix-") do |t| + <<~MARKDOWN + # Foo + MARKDOWN + end + expected = <<~HTML +

Foo

+ HTML + assert_match(expected, template.render) end end end From fa1d35fcb4f7bf952edab417c9475c741192fce0 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Sat, 6 Jan 2024 04:13:34 +0900 Subject: [PATCH 8/9] Just install latest commonmarker in current ruby --- .ci.gemfile | 7 +------ .github/workflows/ci.yml | 9 --------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/.ci.gemfile b/.ci.gemfile index b4d93a1..2754b4e 100644 --- a/.ci.gemfile +++ b/.ci.gemfile @@ -74,12 +74,7 @@ platform :ruby do gem 'rinku' # dependency for wikicloth for handling links gem 'RedCloth' - - if ENV['LATEST_COMMONMARKER'] == 'yes' - gem 'commonmarker' - else - gem 'commonmarker', '< 1' - end + gem 'commonmarker' gem 'rdiscount', '>= 2.1.6' gem 'redcarpet' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b80f92..fcaa7e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,19 +17,10 @@ jobs: fail-fast: false matrix: ruby: [ "2.0.0", 2.1, 2.3, 2.4, 2.5, 2.6, 2.7, "3.0", 3.1, 3.2, 3.3, jruby-9.1, jruby-9.2, jruby-9.3, jruby-9.4 ] - latest_commonmarker: ["", "yes"] - include: - - ruby: "3.1" - latest_commonmarker: "yes" - - ruby: "3.2" - latest_commonmarker: "yes" - - ruby: "3.3" - latest_commonmarker: "yes" name: ${{ matrix.ruby }} env: BUNDLE_GEMFILE: .ci.gemfile COFFEE_SCRIPT: use - LATEST_COMMONMARKER: ${{ matrix.latest_commonmarker }} steps: - uses: actions/checkout@v4 # WikiCloth needs IDN From 290541d373c4440b94f0f831aaa89e89e93d81ad Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Sat, 6 Jan 2024 04:56:12 +0900 Subject: [PATCH 9/9] Fix heredoc syntax for ruby 2.1 or older --- test/tilt_commonmarkertemplate_test.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/tilt_commonmarkertemplate_test.rb b/test/tilt_commonmarkertemplate_test.rb index 9b68ca2..ba1c86b 100644 --- a/test/tilt_commonmarkertemplate_test.rb +++ b/test/tilt_commonmarkertemplate_test.rb @@ -78,13 +78,11 @@ it "render markdown with custom prefixed-header id" do template = Tilt::CommonMarkerTemplate.new(header_ids: "prefix-") do |t| - <<~MARKDOWN - # Foo - MARKDOWN + "# Foo" end - expected = <<~HTML -

Foo

- HTML + expected = <Foo +HTML assert_match(expected, template.render) end end