diff --git a/.github/workflows/ruby_test.yml b/.github/workflows/ruby_test.yml index 8209214..89b23b3 100644 --- a/.github/workflows/ruby_test.yml +++ b/.github/workflows/ruby_test.yml @@ -11,13 +11,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ["3.1", "3.2", "3.3"] + ruby-version: ["3.2", "3.3"] steps: - - uses: actions/checkout@v3 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - name: Run tests - run: bundle exec rake test + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Run tests + run: bundle exec rake test diff --git a/.rubocop.yml b/.rubocop.yml index 400716a..e39b8fb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,7 @@ require: - rubocop-performance AllCops: - TargetRubyVersion: 3.1 + TargetRubyVersion: 3.2 DisplayCopNames: true Exclude: - bin/**/* diff --git a/lib/mato/config.rb b/lib/mato/config.rb index a4e05b0..b51ef71 100644 --- a/lib/mato/config.rb +++ b/lib/mato/config.rb @@ -10,6 +10,7 @@ class Config render: { hardbreaks: true, unsafe: true, + escaped_char_spans: false, }, extension: { table: true, @@ -43,6 +44,9 @@ class Config # @return [Hash] Commonmarker's options attr_accessor :markdown_options + # @return [Hash] Commonmarker's plugins + attr_accessor :markdown_plugins + def initialize @text_filters = [] @markdown_filters = [] @@ -54,6 +58,7 @@ def initialize @document_factory = Document @markdown_options = DEFAULT_MARKDOWN_OPTIONS + @markdown_plugins = { syntax_highlighter: nil } end # @param [Proc] block diff --git a/lib/mato/html_filters/section_anchor.rb b/lib/mato/html_filters/section_anchor.rb index e378c41..fb223b7 100644 --- a/lib/mato/html_filters/section_anchor.rb +++ b/lib/mato/html_filters/section_anchor.rb @@ -17,6 +17,8 @@ def call(doc) anchor_builder = AnchorBuilder.new(@anchor_icon_element) doc.css(HX_PATTERN).each do |hx| + # Remove existing anchor elements generated by CommonMarker v2 + hx.css('a.anchor[inert]').remove hx.children = anchor_builder.make_anchor_element(hx) + hx.children.to_html end end diff --git a/lib/mato/html_filters/syntax_highlight.rb b/lib/mato/html_filters/syntax_highlight.rb index 4ef25b6..aa2e0f0 100644 --- a/lib/mato/html_filters/syntax_highlight.rb +++ b/lib/mato/html_filters/syntax_highlight.rb @@ -56,7 +56,8 @@ def parse_label(class_name) # @return [Nokogiri::XML::Element] a new
wrapping the given code block def highlight(pre) code = pre.at('code') - metadata = parse_label(code['class']) + lang_attr = pre['lang'] || code['class'] + metadata = parse_label(lang_attr) language = metadata[:language]&.sub(/^language-/, '') filename = metadata[:filename] source = code.inner_text diff --git a/lib/mato/processor.rb b/lib/mato/processor.rb index f3e962a..32bc93c 100644 --- a/lib/mato/processor.rb +++ b/lib/mato/processor.rb @@ -51,7 +51,7 @@ def parse_markdown(text) # @param [Commonmarker::Node] markdown_node # @return [String] def render_to_html(markdown_node) - markdown_node.to_html(options: config.markdown_options) + markdown_node.to_html(options: config.markdown_options, plugins: config.markdown_plugins) end # @param [String] html diff --git a/mato.gemspec b/mato.gemspec index e532186..7291e7b 100644 --- a/mato.gemspec +++ b/mato.gemspec @@ -25,9 +25,9 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.required_ruby_version = "~> 3.1" + spec.required_ruby_version = "~> 3.2" - spec.add_runtime_dependency "commonmarker", "~> 1.0" + spec.add_runtime_dependency "commonmarker", "~> 2.3" spec.add_runtime_dependency "nokogiri", ">= 1.12" spec.add_runtime_dependency "rouge", ">= 3.0.0" end