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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d484c25c78ff88494568a3342fb83f0ccedbe30f2d1b6f29d92f9d9e56ba49d9
4
- data.tar.gz: 8ad09da4197ecdcab8a260a6140a727742b65bde66f22c25796187d74dd8e11a
3
+ metadata.gz: ef97dcc38918f4650f93eecd010522e60f435326b1c5330855b277063bf91c2d
4
+ data.tar.gz: 45986e32975fb362c82c1c7428450d6a64b6237c1e722039b1bc91ca24d57d1e
5
5
  SHA512:
6
- metadata.gz: fb088a0c93b8ffccffa81e60e256d7028bc569993dd53f8329867a354e7f594901f3d6134e451335851b13d4f70436aaf03f552e6f6ba84ebd8df8d91ca82f60
7
- data.tar.gz: 15989f1b3d75e06983af2be29f28ce92f07224f315c55ba87a310d04bf2da3f0c5618302235df1ac7670b0f83f66838d44e36bfbb8961cbeada93b5144a7e2dd
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>
@@ -17,14 +17,15 @@ module Protos
17
17
  end
18
18
  end
19
19
 
20
- def self.parse(content, **kwargs)
20
+ def self.parse(content, markdown_options: {})
21
21
  options = {
22
- flags: Markly::GITHUB_PRE_LANG,
23
- extensions: [:table]
24
- }.merge(kwargs)
22
+ render: { gfm_quirks: true },
23
+ extension: { table: true },
24
+ **markdown_options
25
+ }
25
26
 
26
- Markly
27
- .parse(content, **options)
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: -> { false }, reader: false
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)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "protos"
4
- require "markly"
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 visit_header(node)
41
- case node.header_level
42
- in 1 then h1 { visit_children(node) }
43
- in 2 then h2 { visit_children(node) }
44
- in 3 then h3 { visit_children(node) }
45
- in 4 then h4 { visit_children(node) }
46
- in 5 then h5 { visit_children(node) }
47
- in 6 then h6 { visit_children(node) }
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 :ordered_list then ol { visit_children(node) }
84
- when :bullet_list then ul { visit_children(node) }
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 visit_list_item(node)
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 visit_hrule(_node)
132
+ def visit_thematic_break(_node)
109
133
  hr
110
134
  end
111
135
 
112
- def visit_blockquote(node)
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 visit_inline_html(node)
146
+ def visit_html_inline(node)
123
147
  return if @sanitize
124
148
 
125
- raw safe(node.string_content)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "protos-markdown"
5
- spec.version = "1.0.0"
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 "markly", "~> 0.9"
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.0.0
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: 2025-03-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: markly
13
+ name: commonmarker
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.9'
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: '0.9'
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.2
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: []