From e371479e9410972ec8bf554d7a12c3a8381acce8 Mon Sep 17 00:00:00 2001 From: "Paul B." Date: Wed, 20 Dec 2023 10:54:03 +0100 Subject: [PATCH 1/2] WIP: plugins: add custom markdown converter --- bridgetown.config.yml | 2 ++ .../markdown/custom_markdown_converter.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 plugins/converters/markdown/custom_markdown_converter.rb diff --git a/bridgetown.config.yml b/bridgetown.config.yml index 3a3ca51c..289853ed 100644 --- a/bridgetown.config.yml +++ b/bridgetown.config.yml @@ -53,3 +53,5 @@ collections: sort_direction: descending kramdown: parse_html_blocks: true + +markdown: CustomMarkdownConverter diff --git a/plugins/converters/markdown/custom_markdown_converter.rb b/plugins/converters/markdown/custom_markdown_converter.rb new file mode 100644 index 00000000..2293ecc0 --- /dev/null +++ b/plugins/converters/markdown/custom_markdown_converter.rb @@ -0,0 +1,14 @@ +class Converters::Markdown::CustomMarkdownConverter < Bridgetown::Converter + def initialize(config) + require 'commonmarkdown' + @config = config + rescue LoadError + STDERR.puts 'You are missing a library required for Markdown. Please run:' + STDERR.puts ' $ [sudo] gem install commonmarkdown' + raise RuntimeError.new("Missing dependency: commonmarkdown") + end + + def convert(content) + ::FunkyMarkdown.new(content).convert + end +end From b27625b4f31fd5733a2a7bee94b38d89b1aaa417 Mon Sep 17 00:00:00 2001 From: Thimy Kieu Date: Wed, 20 Dec 2023 15:24:08 +0100 Subject: [PATCH 2/2] markdown: use commonmarker as markdown processor --- Gemfile | 2 + Gemfile.lock | 83 ++++++++++--------- bridgetown.config.yml | 4 +- .../converters/markdown/commonmarker.rb | 14 ++++ .../markdown/custom_markdown_converter.rb | 14 ---- 5 files changed, 63 insertions(+), 54 deletions(-) create mode 100644 plugins/bridgetown/converters/markdown/commonmarker.rb delete mode 100644 plugins/converters/markdown/custom_markdown_converter.rb diff --git a/Gemfile b/Gemfile index 30edba2d..f88711a2 100644 --- a/Gemfile +++ b/Gemfile @@ -45,3 +45,5 @@ gem "bridgetown-sitemap", "~> 2.0" gem "bridgetown-seo-tag", "~> 6.0" gem "bridgetown_internal_markdown_links", "~> 0.2.0" + +gem "commonmarker" diff --git a/Gemfile.lock b/Gemfile.lock index 3813172d..240cafe0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,23 +1,24 @@ GEM remote: https://rubygems.org/ specs: - activemodel (7.1.3.2) - activesupport (= 7.1.3.2) - activesupport (7.1.3.2) + activemodel (7.2.1) + activesupport (= 7.2.1) + activesupport (7.2.1) base64 bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) - addressable (2.8.6) - public_suffix (>= 2.0.2, < 6.0) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) amazing_print (1.6.0) base64 (0.2.0) - bigdecimal (3.1.7) + bigdecimal (3.1.8) bridgetown (1.3.3) bridgetown-builder (= 1.3.3) bridgetown-core (= 1.3.3) @@ -64,65 +65,72 @@ GEM bridgetown_internal_markdown_links (0.2.0) bridgetown (>= 1.2.0, < 2.0) colorator (1.1.0) - concurrent-ruby (1.2.3) + commonmarker (1.1.5-arm64-darwin) + commonmarker (1.1.5-x86_64-darwin) + commonmarker (1.1.5-x86_64-linux) + concurrent-ruby (1.3.4) connection_pool (2.4.1) - csv (3.2.8) + csv (3.3.0) drb (2.2.1) - erubi (1.12.0) - faraday (2.9.0) - faraday-net_http (>= 2.0, < 3.2) + erubi (1.13.0) + faraday (2.11.0) + faraday-net_http (>= 2.0, < 3.4) + logger faraday-follow_redirects (0.3.0) faraday (>= 1, < 3) - faraday-net_http (3.1.0) + faraday-net_http (3.3.0) net-http - ffi (1.16.3) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-darwin) + ffi (1.17.0-x86_64-linux-gnu) hash_with_dot_access (1.2.0) activesupport (>= 5.0.0, < 8.0) - i18n (1.14.4) + i18n (1.14.5) concurrent-ruby (~> 1.0) kramdown (2.4.0) rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) - liquid (5.5.0) + liquid (5.5.1) listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - minitest (5.22.3) - mutex_m (0.2.0) + logger (1.6.1) + minitest (5.25.1) net-http (0.4.1) uri - nio4r (2.7.1) - nokogiri (1.16.3-arm64-darwin) + nio4r (2.7.3) + nokogiri (1.16.7-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.3-x86_64-darwin) + nokogiri (1.16.7-x86_64-darwin) racc (~> 1.4) - nokogiri (1.16.3-x86_64-linux) + nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) - public_suffix (5.0.4) + public_suffix (6.0.1) puma (6.4.2) nio4r (~> 2.0) - racc (1.7.3) - rack (3.0.10) - rake (13.1.0) - random-port (0.6.0) + racc (1.8.1) + rack (3.1.7) + rake (13.2.1) + random-port (0.7.1) rb-fsevent (0.11.2) - rb-inotify (0.10.1) + rb-inotify (0.11.1) ffi (~> 1.0) - rexml (3.2.6) - roda (3.78.0) + rexml (3.3.7) + roda (3.83.0) rack - rouge (4.2.1) + rouge (4.3.0) + securerandom (0.3.1) serbea (1.0.1) activesupport (>= 6.0) erubi (>= 1.10) tilt (~> 2.0) - thor (1.3.1) - tilt (2.3.0) + thor (1.3.2) + tilt (2.4.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - uri (0.13.0) - zeitwerk (2.6.13) + uri (0.13.1) + zeitwerk (2.6.18) PLATFORMS arm64-darwin-21 @@ -140,6 +148,7 @@ DEPENDENCIES bridgetown-sitemap (~> 2.0) bridgetown-svg-inliner (~> 2.0) bridgetown_internal_markdown_links (~> 0.2.0) + commonmarker puma (< 7) BUNDLED WITH diff --git a/bridgetown.config.yml b/bridgetown.config.yml index 289853ed..2fe1edbb 100644 --- a/bridgetown.config.yml +++ b/bridgetown.config.yml @@ -51,7 +51,5 @@ collections: future: true sort_by: date sort_direction: descending -kramdown: - parse_html_blocks: true -markdown: CustomMarkdownConverter +markdown: Commonmarker diff --git a/plugins/bridgetown/converters/markdown/commonmarker.rb b/plugins/bridgetown/converters/markdown/commonmarker.rb new file mode 100644 index 00000000..de9081eb --- /dev/null +++ b/plugins/bridgetown/converters/markdown/commonmarker.rb @@ -0,0 +1,14 @@ +class Bridgetown::Converters::Markdown::Commonmarker + def initialize(config) + require "commonmarker" + @config = config + rescue LoadError + STDERR.puts 'You are missing a library required for Markdown. Please run:' + STDERR.puts ' $ [sudo] gem install commonmarker' + raise RuntimeError.new("Missing dependency: commonmarker") + end + + def convert(content) + CommonMarker.render_html(content) + end +end diff --git a/plugins/converters/markdown/custom_markdown_converter.rb b/plugins/converters/markdown/custom_markdown_converter.rb deleted file mode 100644 index 2293ecc0..00000000 --- a/plugins/converters/markdown/custom_markdown_converter.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Converters::Markdown::CustomMarkdownConverter < Bridgetown::Converter - def initialize(config) - require 'commonmarkdown' - @config = config - rescue LoadError - STDERR.puts 'You are missing a library required for Markdown. Please run:' - STDERR.puts ' $ [sudo] gem install commonmarkdown' - raise RuntimeError.new("Missing dependency: commonmarkdown") - end - - def convert(content) - ::FunkyMarkdown.new(content).convert - end -end