From e935903399af60a79b615a323e1c9a650c804910 Mon Sep 17 00:00:00 2001 From: Moeki Kawakami Date: Tue, 7 May 2024 08:27:32 +0900 Subject: [PATCH] remove markly --- README.md | 2 +- lib/mato/config.rb | 58 +++++++++++++++---------------------------- lib/mato/converter.rb | 2 +- lib/mato/processor.rb | 11 +++----- mato.gemspec | 1 - 5 files changed, 26 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index b0a8dc7..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 ``Markly::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 9ed8833..a4e05b0 100644 --- a/lib/mato/config.rb +++ b/lib/mato/config.rb @@ -3,34 +3,24 @@ require_relative('./document') require 'nokogiri' -require 'markly' module Mato class Config - # https://github.com/gjtorikian/commonmarker#parse-options - DEFAULT_MARKDOWN_PARSE_OPTIONS = [ - Markly::DEFAULT, - Markly::VALIDATE_UTF8, - Markly::FOOTNOTES, - Markly::UNSAFE, - ].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 @@ -41,7 +31,7 @@ class Config # @return [Array] attr_accessor :html_filters - # @return [Class] @@ -50,28 +40,20 @@ class Config # @return [Class] attr_accessor :document_factory - # @return [Array] Markly's parse extensions - attr_accessor :markdown_extensions - - # @return [Array] Markly'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 = Markly + @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 39ab4b8..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 [Markly::Node] + # @type [Commonmarker::Node] document = processor.parse_markdown(content) convert_headings!(document) diff --git a/lib/mato/processor.rb b/lib/mato/processor.rb index eac79a0..f3e962a 100644 --- a/lib/mato/processor.rb +++ b/lib/mato/processor.rb @@ -12,9 +12,6 @@ class Processor def initialize(config) @config = config - config.markdown_parse_options.each do |options| - @flags = @flags ? @flags | options : options - end end # @param [String] input @@ -46,15 +43,15 @@ def process(input) end # @param [String] text - # @return [Markly::Node] + # @return [Commonmarker::Node] def parse_markdown(text) - config.markdown_parser.parse(text, flags: @flags, extensions: config.markdown_extensions) + config.markdown_parser.parse(text, options: config.markdown_options) end - # @param [Markly::Node] markdown_node + # @param [Commonmarker::Node] markdown_node # @return [String] def render_to_html(markdown_node) - markdown_node.to_html(flags: @flags) + markdown_node.to_html(options: config.markdown_options) end # @param [String] html diff --git a/mato.gemspec b/mato.gemspec index e12cf78..e532186 100644 --- a/mato.gemspec +++ b/mato.gemspec @@ -28,7 +28,6 @@ Gem::Specification.new do |spec| spec.required_ruby_version = "~> 3.1" spec.add_runtime_dependency "commonmarker", "~> 1.0" - spec.add_runtime_dependency "markly", "~> 0.9" spec.add_runtime_dependency "nokogiri", ">= 1.12" spec.add_runtime_dependency "rouge", ">= 3.0.0" end