mato 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/lib/mato.rb +1 -0
- data/lib/mato/converter.rb +61 -0
- data/lib/mato/html_filters/bare_inline_element.rb +9 -10
- data/lib/mato/processor.rb +4 -0
- data/lib/mato/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a90e7f93e54d37654d73461b98bb894e5ac5ba2
|
4
|
+
data.tar.gz: 79023df2717584da84317c669a0368674ed31bc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c43c85c5b67a41a7c9a27434863920fd68365b0ab4facf4b053ab5174b5db5d931d249dac09f0f77cdb990273ccc7a923a0c1129e27353429d9341723fdc00b
|
7
|
+
data.tar.gz: 4f87d7a392f7d9b0a53453a92c1cef0f496d14f99c3520c34e89ae8bdb436ddda781d8f661dbc325cddc1e05ff38eddcbcdd441299fc5064f262c8673d1f470c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# The revision history of Mato
|
2
2
|
|
3
|
+
## v1.2.0 - 2017/08/28
|
4
|
+
|
5
|
+
https://github.com/bitjourney/mato/compare/v1.1.0...v1.2.0
|
6
|
+
|
7
|
+
* *Experimental*: `Mato::Processor#convert` to convert X-flavored markdown to CommonMark
|
8
|
+
* Currently only `flavor: :redcarpet` is supported
|
9
|
+
|
3
10
|
## v1.1.0 - 2017/08/24
|
4
11
|
|
5
12
|
https://github.com/bitjourney/mato/compare/v1.0.3...v1.1.0
|
data/Gemfile
CHANGED
data/lib/mato.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
# Convert X-flavored markdown to CommonMark
|
6
|
+
module Mato
|
7
|
+
class Converter
|
8
|
+
|
9
|
+
FLAVORES = Set.new([
|
10
|
+
:redcarpet, # legacy GFM uses it
|
11
|
+
]).freeze
|
12
|
+
|
13
|
+
attr_reader :processor
|
14
|
+
attr_reader :content
|
15
|
+
attr_reader :flavor
|
16
|
+
|
17
|
+
# @return [Array<String>]
|
18
|
+
attr_reader :content_lines
|
19
|
+
|
20
|
+
def initialize(processor, content, flavor)
|
21
|
+
unless FLAVORES.include?(flavor)
|
22
|
+
raise "Unsupported flavor #{flavor.inspect}, it must be one of: #{FLAVORES.map(&:inspect).join(' ')}"
|
23
|
+
end
|
24
|
+
|
25
|
+
@processor = processor
|
26
|
+
@content = content
|
27
|
+
@content_lines = content.split(/\n/)
|
28
|
+
@flavor = flavor
|
29
|
+
end
|
30
|
+
|
31
|
+
def run
|
32
|
+
# @type [CommonMarker::Node]
|
33
|
+
document = processor.parse_markdown(content)
|
34
|
+
|
35
|
+
convert_headings!(document)
|
36
|
+
|
37
|
+
content_lines.join("\n").tap do |c|
|
38
|
+
# fixup newlines removed by String#split
|
39
|
+
content.scan(/\n+\z/) do |matched|
|
40
|
+
c << matched
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def convert_headings!(document)
|
46
|
+
document.walk.select do |node|
|
47
|
+
node.type == :text &&
|
48
|
+
node.sourcepos[:start_column] == 1 &&
|
49
|
+
node.parent.type == :paragraph &&
|
50
|
+
node.parent.parent.type == :document
|
51
|
+
end.reverse.each do |node|
|
52
|
+
replacement = node.string_content.gsub(/\A(#+)(?=\S)/, '\1 ')
|
53
|
+
|
54
|
+
if node.string_content != replacement
|
55
|
+
pos = node.sourcepos
|
56
|
+
content_lines[pos[:start_line] - 1][(pos[:start_column] - 1)...pos[:end_column]] = replacement
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -8,19 +8,18 @@
|
|
8
8
|
module Mato
|
9
9
|
module HtmlFilters
|
10
10
|
class BareInlineElement
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
STANDALONE_INLINE_ELEMENTS = Set.new([
|
12
|
+
"img",
|
13
|
+
"input",
|
14
|
+
"textarea",
|
15
|
+
])
|
16
16
|
|
17
17
|
def call(doc)
|
18
18
|
doc.children.each do |node|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
19
|
+
next unless STANDALONE_INLINE_ELEMENTS.include?(node.name)
|
20
|
+
parent = Nokogiri::HTML.fragment('<p/>')
|
21
|
+
parent.child.add_child(node.dup)
|
22
|
+
node.replace(parent)
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
data/lib/mato/processor.rb
CHANGED
data/lib/mato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FUJI Goro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/mato/anchor_builder.rb
|
62
62
|
- lib/mato/concerns/html_node_checkable.rb
|
63
63
|
- lib/mato/config.rb
|
64
|
+
- lib/mato/converter.rb
|
64
65
|
- lib/mato/document.rb
|
65
66
|
- lib/mato/html_filters/bare_inline_element.rb
|
66
67
|
- lib/mato/html_filters/mention_link.rb
|