Skip to content

Commit

Permalink
remove markly
Browse files Browse the repository at this point in the history
  • Loading branch information
moekiorg committed May 6, 2024
1 parent 512008a commit e935903
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 48 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
58 changes: 20 additions & 38 deletions lib/mato/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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: {
hardbreaks: true,
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 +31,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,28 +40,20 @@ class Config
# @return [Class<Mato::Document>]
attr_accessor :document_factory

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

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

# @return [Array<Symbol>] 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
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 e935903

Please sign in to comment.