diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml
index 5f8c520..d338f69 100644
--- a/.github/workflows/reviewdog.yml
+++ b/.github/workflows/reviewdog.yml
@@ -11,13 +11,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
- name: Use ruby
uses: ruby/setup-ruby@v1
with:
- bundler-cache: true
- ruby-version: '3.0'
+ ruby-version: '3.1'
- name: rubocop
uses: reviewdog/action-rubocop@v2
diff --git a/.github/workflows/ruby_test.yml b/.github/workflows/ruby_test.yml
index 23a1b13..8209214 100644
--- a/.github/workflows/ruby_test.yml
+++ b/.github/workflows/ruby_test.yml
@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- ruby-version: ['2.7', '3.0', '3.1']
+ ruby-version: ["3.1", "3.2", "3.3"]
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
diff --git a/.rubocop.yml b/.rubocop.yml
index fdc38b5..400716a 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -3,7 +3,7 @@ require:
- rubocop-performance
AllCops:
- TargetRubyVersion: 2.7
+ TargetRubyVersion: 3.1
DisplayCopNames: true
Exclude:
- bin/**/*
diff --git a/README.md b/README.md
index 242408c..fffae7b 100644
--- a/README.md
+++ b/README.md
@@ -89,7 +89,7 @@ mato.process("Hello!").render_html # "
HELLO!
\n"
### Markdown Filters
-A markdown filter is a callable instance that takes a ``CommonMarker::Node`
+A markdown filter is a callable instance that takes a ``Commonmarker::Node`
and mutate it in the method. The return value is ignored.
For example:
diff --git a/lib/mato/config.rb b/lib/mato/config.rb
index 984d8c5..a4e05b0 100644
--- a/lib/mato/config.rb
+++ b/lib/mato/config.rb
@@ -6,29 +6,21 @@
module Mato
class Config
- # https://github.com/gjtorikian/commonmarker#parse-options
- DEFAULT_MARKDOWN_PARSE_OPTIONS = %i[
- DEFAULT
- VALIDATE_UTF8
- FOOTNOTES
- ].freeze
-
- # https://github.com/gjtorikian/commonmarker#render-options
- DEFAULT_MARKDOWN_RENDER_OPTIONS = [
- :DEFAULT,
- :HARDBREAKS, # convert "\n" as
- :TABLE_PREFER_STYLE_ATTRIBUTES,
- :UNSAFE,
- # :SOURCEPOS, // TODO: enable it after assertions are supported
- ].freeze
-
- # https://github.com/github/cmark/tree/master/extensions
- DEFAULT_MARKDOWN_EXTENSIONS = %i[
- table
- strikethrough
- autolink
- tagfilter
- ].freeze
+ DEFAULT_MARKDOWN_OPTIONS = {
+ render: {
+ hardbreaks: true,
+ unsafe: true,
+ },
+ extension: {
+ table: true,
+ strikethrough: true,
+ autolink: true,
+ tagfilter: true,
+ tasklist: false,
+ shortcodes: false,
+ footnotes: true,
+ },
+ }.freeze
# @return [Array]
attr_accessor :text_filters
@@ -39,7 +31,7 @@ class Config
# @return [Array]
attr_accessor :html_filters
- # @return [Class]
@@ -48,28 +40,20 @@ class Config
# @return [Class]
attr_accessor :document_factory
- # @return [Array] CommonMarker's parse extensions
- attr_accessor :markdown_extensions
-
- # @return [Array] CommonMarker's pars options
- attr_accessor :markdown_parse_options
-
- # @return [Array] CommonMarker's HTML rendering options
- attr_accessor :markdown_render_options
+ # @return [Hash] Commonmarker's options
+ attr_accessor :markdown_options
def initialize
@text_filters = []
@markdown_filters = []
@html_filters = []
- @markdown_parser = CommonMarker
+ @markdown_parser = Commonmarker
@html_parser = Nokogiri::HTML4::DocumentFragment
@document_factory = Document
- @markdown_extensions = DEFAULT_MARKDOWN_EXTENSIONS
- @markdown_parse_options = DEFAULT_MARKDOWN_PARSE_OPTIONS
- @markdown_render_options = DEFAULT_MARKDOWN_RENDER_OPTIONS
+ @markdown_options = DEFAULT_MARKDOWN_OPTIONS
end
# @param [Proc] block
diff --git a/lib/mato/converter.rb b/lib/mato/converter.rb
index 8336574..65b39e2 100644
--- a/lib/mato/converter.rb
+++ b/lib/mato/converter.rb
@@ -29,7 +29,7 @@ def initialize(processor, content, flavor)
end
def run
- # @type [CommonMarker::Node]
+ # @type [Commonmarker::Node]
document = processor.parse_markdown(content)
convert_headings!(document)
@@ -45,14 +45,14 @@ def run
def convert_headings!(document)
document.walk.select do |node|
node.type == :text &&
- node.sourcepos[:start_column] == 1 &&
+ node.source_position[:start_column] == 1 &&
node.parent.type == :paragraph &&
node.parent.parent.type == :document
end.reverse_each do |node|
replacement = node.string_content.gsub(/\A(#+)(?=\S)/, '\1 ')
if node.string_content != replacement
- pos = node.sourcepos
+ pos = node.source_position
content_lines[pos[:start_line] - 1][(pos[:start_column] - 1)...pos[:end_column]] = replacement
end
end
diff --git a/lib/mato/processor.rb b/lib/mato/processor.rb
index f3f8d09..f3e962a 100644
--- a/lib/mato/processor.rb
+++ b/lib/mato/processor.rb
@@ -43,15 +43,15 @@ def process(input)
end
# @param [String] text
- # @return [CommonMarker::Node]
+ # @return [Commonmarker::Node]
def parse_markdown(text)
- config.markdown_parser.render_doc(text, config.markdown_parse_options, config.markdown_extensions)
+ config.markdown_parser.parse(text, options: config.markdown_options)
end
- # @param [CommonMarker::Node] markdown_node
+ # @param [Commonmarker::Node] markdown_node
# @return [String]
def render_to_html(markdown_node)
- markdown_node.to_html(config.markdown_render_options)
+ markdown_node.to_html(options: config.markdown_options)
end
# @param [String] html
diff --git a/mato.gemspec b/mato.gemspec
index 7b1f5c6..e532186 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 = ">= 2.7"
+ spec.required_ruby_version = "~> 3.1"
- spec.add_runtime_dependency "commonmarker", ">= 0.18.1"
+ spec.add_runtime_dependency "commonmarker", "~> 1.0"
spec.add_runtime_dependency "nokogiri", ">= 1.12"
spec.add_runtime_dependency "rouge", ">= 3.0.0"
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index c2d4212..ae3719e 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -9,7 +9,7 @@
require 'active_support'
require 'rr'
-class MyTest < MiniTest::Test
+class MyTest < Minitest::Test
include Minitest::PowerAssert::Assertions
def assert_html_eq(actual, expected)