Skip to content

Commit

Permalink
remove markly
Browse files Browse the repository at this point in the history
  • Loading branch information
kawakamimoeki committed May 6, 2024
1 parent 512008a commit 41ece5f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mato.process("Hello!").render_html # "<p>HELLO!</p>\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:
Expand Down
53 changes: 20 additions & 33 deletions lib/mato/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,23 @@
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 <br/>
: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: {
unsafe: true,
},
extension: {
table: true,
strikethrough: true,
autolink: true,
tagfilter: true,
tasklist: false,
shortcodes: false,
footnotes: true,
},
}.freeze

# @return [Array<Proc>]
attr_accessor :text_filters
Expand All @@ -41,7 +30,7 @@ class Config
# @return [Array<Proc>]
attr_accessor :html_filters

# @return [Class<Markly]
# @return [Class<Commonmarker]
attr_accessor :markdown_parser

# @return [Cass<Nokogiri::HTML4::DocumentFragment>]
Expand All @@ -50,11 +39,11 @@ class Config
# @return [Class<Mato::Document>]
attr_accessor :document_factory

# @return [Array<Symbol>] Markly's parse extensions
# @return [Array<Symbol>] Commonmarker's parse extensions
attr_accessor :markdown_extensions

# @return [Array<Class>] Markly's pars options
attr_accessor :markdown_parse_options
# @return [Array<Class>] Commonmarker's pars options
attr_accessor :markdown_options

# @return [Array<Symbol>] Commonmarker's HTML rendering options
attr_accessor :markdown_render_options
Expand All @@ -64,14 +53,12 @@ def initialize
@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
Expand Down
2 changes: 1 addition & 1 deletion lib/mato/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions lib/mato/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion mato.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 41ece5f

Please sign in to comment.