protos-markdown 1.0.0 → 1.1.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/README.md +3 -3
- data/lib/protos/markdown/ast.rb +7 -6
- data/lib/protos/markdown/table.rb +3 -3
- data/lib/protos/markdown.rb +49 -17
- data/protos-markdown.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef97dcc38918f4650f93eecd010522e60f435326b1c5330855b277063bf91c2d
|
4
|
+
data.tar.gz: 45986e32975fb362c82c1c7428450d6a64b6237c1e722039b1bc91ca24d57d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edde7fdbe9ed89febeb5fe007bd5f7a3bc382277fe68a02949f0054d68ac427daa281a208f66eae358b29479c4c782f9759206dde3ad1f32a51a5be3870e2102
|
7
|
+
data.tar.gz: f8baa177b747fea06e86452a221ad39042cec9a43c699f9159e4840c9e9170cd7c7950c8d97c05c468136112f94303fbca030f4671a6423ef6a1cdca1ce4ec28
|
data/README.md
CHANGED
@@ -22,8 +22,8 @@ using the standard protos conventions:
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
class Markdown < Protos::Markdown
|
25
|
-
def h1 = super(class: css[:title])
|
26
|
-
def ul = super(class: "ml-4 pt-2")
|
25
|
+
def h1(**) = super(class: css[:title], **)
|
26
|
+
def ul(**) = super(class: "ml-4 pt-2", **)
|
27
27
|
|
28
28
|
private
|
29
29
|
|
@@ -52,7 +52,7 @@ output = Markdown.new(content).call
|
|
52
52
|
Which outputs the following html:
|
53
53
|
|
54
54
|
```html
|
55
|
-
<h1 class="font-bold text-xl">Hello World</h1>
|
55
|
+
<h1 class="font-bold text-xl" id="hello-world">Hello World</h1>
|
56
56
|
<ul class="ml-4 pt-2">
|
57
57
|
<li>A</li>
|
58
58
|
<li>B</li>
|
data/lib/protos/markdown/ast.rb
CHANGED
@@ -17,14 +17,15 @@ module Protos
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def self.parse(content,
|
20
|
+
def self.parse(content, markdown_options: {})
|
21
21
|
options = {
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
render: { gfm_quirks: true },
|
23
|
+
extension: { table: true },
|
24
|
+
**markdown_options
|
25
|
+
}
|
25
26
|
|
26
|
-
|
27
|
-
.parse(content,
|
27
|
+
Commonmarker
|
28
|
+
.parse(content, options:)
|
28
29
|
.then { |node| new(Node.new(node)) }
|
29
30
|
end
|
30
31
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Protos
|
4
4
|
class Markdown
|
5
5
|
class Table < Protos::Table
|
6
|
-
option :inside_header, default: -> {
|
6
|
+
option :inside_header, default: -> { true }, reader: false
|
7
7
|
|
8
8
|
def visit_table(node)
|
9
9
|
visit_children(node)
|
@@ -30,11 +30,11 @@ module Protos
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def visit_table_row(node)
|
33
|
-
@inside_header = false
|
34
|
-
|
35
33
|
row do
|
36
34
|
visit_children(node)
|
37
35
|
end
|
36
|
+
|
37
|
+
@inside_header = false
|
38
38
|
end
|
39
39
|
|
40
40
|
def visit_code(node)
|
data/lib/protos/markdown.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "protos"
|
4
|
-
require "
|
4
|
+
require "commonmarker"
|
5
5
|
require "rouge"
|
6
6
|
require "delegate"
|
7
7
|
|
@@ -12,6 +12,27 @@ module Protos
|
|
12
12
|
class Markdown < ::Protos::Component # rubocop:disable Metrics/ClassLength
|
13
13
|
param :content, reader: false
|
14
14
|
option :sanitize, default: -> { true }, reader: false
|
15
|
+
option :markdown_options, default: -> { {} }, reader: false
|
16
|
+
|
17
|
+
Heading = Data.define(:node) do
|
18
|
+
def id
|
19
|
+
text.downcase.gsub(/[^a-z0-9]+/, "-").chomp("-")
|
20
|
+
end
|
21
|
+
|
22
|
+
def text
|
23
|
+
buffer = +""
|
24
|
+
node.walk do |node|
|
25
|
+
buffer << node.string_content
|
26
|
+
rescue TypeError
|
27
|
+
# Ignore non-text nodes
|
28
|
+
end
|
29
|
+
buffer
|
30
|
+
end
|
31
|
+
|
32
|
+
def header_level
|
33
|
+
node.header_level
|
34
|
+
end
|
35
|
+
end
|
15
36
|
|
16
37
|
def view_template
|
17
38
|
return unless root
|
@@ -37,14 +58,16 @@ module Protos
|
|
37
58
|
plain(node.string_content)
|
38
59
|
end
|
39
60
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
in
|
45
|
-
in
|
46
|
-
in
|
47
|
-
in
|
61
|
+
def visit_heading(node)
|
62
|
+
heading = Heading.new(node)
|
63
|
+
|
64
|
+
case heading.header_level
|
65
|
+
in 1 then h1(id: heading.id) { visit_children(node) }
|
66
|
+
in 2 then h2(id: heading.id) { visit_children(node) }
|
67
|
+
in 3 then h3(id: heading.id) { visit_children(node) }
|
68
|
+
in 4 then h4(id: heading.id) { visit_children(node) }
|
69
|
+
in 5 then h5(id: heading.id) { visit_children(node) }
|
70
|
+
in 6 then h6(id: heading.id) { visit_children(node) }
|
48
71
|
end
|
49
72
|
end
|
50
73
|
|
@@ -80,12 +103,13 @@ module Protos
|
|
80
103
|
|
81
104
|
def visit_list(node)
|
82
105
|
case node.list_type
|
83
|
-
when :
|
84
|
-
when :
|
106
|
+
when :ordered then ol { visit_children(node) }
|
107
|
+
when :bullet then ul { visit_children(node) }
|
108
|
+
else raise ArgumentError, "Unknown list type: #{node.list_type}"
|
85
109
|
end
|
86
110
|
end
|
87
111
|
|
88
|
-
def
|
112
|
+
def visit_item(node)
|
89
113
|
li { visit_children(node) }
|
90
114
|
end
|
91
115
|
|
@@ -105,11 +129,11 @@ module Protos
|
|
105
129
|
end
|
106
130
|
end
|
107
131
|
|
108
|
-
def
|
132
|
+
def visit_thematic_break(_node)
|
109
133
|
hr
|
110
134
|
end
|
111
135
|
|
112
|
-
def
|
136
|
+
def visit_block_quote(node)
|
113
137
|
blockquote { visit_children(node) }
|
114
138
|
end
|
115
139
|
|
@@ -119,16 +143,24 @@ module Protos
|
|
119
143
|
raw safe(node.string_content)
|
120
144
|
end
|
121
145
|
|
122
|
-
def
|
146
|
+
def visit_html_inline(node)
|
123
147
|
return if @sanitize
|
124
148
|
|
125
|
-
raw safe(node.
|
149
|
+
raw safe(node.to_html(options: { render: { unsafe: true } }))
|
150
|
+
end
|
151
|
+
|
152
|
+
def visit_html_block(_node)
|
153
|
+
nil
|
154
|
+
end
|
155
|
+
|
156
|
+
def visit_escaped(node)
|
157
|
+
plain(node.first_child&.string_content)
|
126
158
|
end
|
127
159
|
|
128
160
|
private
|
129
161
|
|
130
162
|
def root
|
131
|
-
AST.parse(@content)
|
163
|
+
AST.parse(@content, markdown_options: @markdown_options)
|
132
164
|
end
|
133
165
|
|
134
166
|
def formatter
|
data/protos-markdown.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "protos-markdown"
|
5
|
-
spec.version = "1.
|
5
|
+
spec.version = "1.1.0"
|
6
6
|
spec.authors = ["Nolan Tait"]
|
7
7
|
spec.email = ["nolanjtait@gmail.com"]
|
8
8
|
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_dependency "
|
33
|
+
spec.add_dependency "commonmarker", "~> 2.3"
|
34
34
|
spec.add_dependency "protos", "~> 1"
|
35
35
|
spec.add_dependency "rouge", "~> 4"
|
36
36
|
|
metadata
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protos-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nolan Tait
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
|
-
name:
|
13
|
+
name: commonmarker
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: '
|
18
|
+
version: '2.3'
|
19
19
|
type: :runtime
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: '
|
25
|
+
version: '2.3'
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: protos
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
|
-
rubygems_version: 3.6.
|
95
|
+
rubygems_version: 3.6.7
|
96
96
|
specification_version: 4
|
97
97
|
summary: A markdown renderer with Phlex and Protos
|
98
98
|
test_files: []
|