prosereflect 0.1.1 → 0.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/.github/workflows/rake.yml +4 -0
- data/.github/workflows/release.yml +5 -0
- data/.rubocop.yml +19 -1
- data/.rubocop_todo.yml +141 -191
- data/CLAUDE.md +78 -0
- data/Gemfile +8 -4
- data/Rakefile +3 -3
- data/lib/prosereflect/attribute/base.rb +4 -6
- data/lib/prosereflect/attribute/bold.rb +2 -4
- data/lib/prosereflect/attribute/href.rb +1 -3
- data/lib/prosereflect/attribute/id.rb +7 -7
- data/lib/prosereflect/attribute.rb +4 -7
- data/lib/prosereflect/blockquote.rb +10 -11
- data/lib/prosereflect/bullet_list.rb +16 -15
- data/lib/prosereflect/code_block.rb +26 -26
- data/lib/prosereflect/code_block_wrapper.rb +12 -13
- data/lib/prosereflect/document.rb +14 -22
- data/lib/prosereflect/hard_break.rb +6 -6
- data/lib/prosereflect/heading.rb +14 -15
- data/lib/prosereflect/horizontal_rule.rb +14 -14
- data/lib/prosereflect/image.rb +23 -23
- data/lib/prosereflect/input/html.rb +83 -104
- data/lib/prosereflect/input.rb +7 -0
- data/lib/prosereflect/list_item.rb +11 -12
- data/lib/prosereflect/mark/base.rb +9 -11
- data/lib/prosereflect/mark/bold.rb +1 -3
- data/lib/prosereflect/mark/code.rb +1 -3
- data/lib/prosereflect/mark/italic.rb +1 -3
- data/lib/prosereflect/mark/link.rb +1 -3
- data/lib/prosereflect/mark/strike.rb +1 -3
- data/lib/prosereflect/mark/subscript.rb +1 -3
- data/lib/prosereflect/mark/superscript.rb +1 -3
- data/lib/prosereflect/mark/underline.rb +1 -3
- data/lib/prosereflect/mark.rb +9 -5
- data/lib/prosereflect/node.rb +31 -31
- data/lib/prosereflect/ordered_list.rb +15 -14
- data/lib/prosereflect/output/html.rb +52 -50
- data/lib/prosereflect/output.rb +7 -0
- data/lib/prosereflect/paragraph.rb +11 -13
- data/lib/prosereflect/parser.rb +47 -66
- data/lib/prosereflect/table.rb +12 -13
- data/lib/prosereflect/table_cell.rb +13 -13
- data/lib/prosereflect/table_header.rb +17 -17
- data/lib/prosereflect/table_row.rb +12 -12
- data/lib/prosereflect/text.rb +11 -11
- data/lib/prosereflect/user.rb +15 -15
- data/lib/prosereflect/version.rb +1 -1
- data/lib/prosereflect.rb +27 -17
- data/prosereflect.gemspec +17 -16
- data/spec/prosereflect/document_spec.rb +332 -330
- data/spec/prosereflect/hard_break_spec.rb +125 -125
- data/spec/prosereflect/input/html_spec.rb +522 -522
- data/spec/prosereflect/node_spec.rb +183 -182
- data/spec/prosereflect/output/html_spec.rb +105 -105
- data/spec/prosereflect/paragraph_spec.rb +275 -274
- data/spec/prosereflect/parser_spec.rb +185 -180
- data/spec/prosereflect/table_cell_spec.rb +183 -183
- data/spec/prosereflect/table_row_spec.rb +149 -149
- data/spec/prosereflect/table_spec.rb +320 -318
- data/spec/prosereflect/text_spec.rb +133 -132
- data/spec/prosereflect/user_spec.rb +31 -28
- data/spec/prosereflect_spec.rb +28 -26
- data/spec/spec_helper.rb +6 -6
- data/spec/support/matchers.rb +6 -6
- data/spec/support/shared_examples.rb +49 -49
- metadata +8 -5
- data/spec/prosereflect/version_spec.rb +0 -11
data/lib/prosereflect/parser.rb
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'node'
|
|
4
|
-
require_relative 'text'
|
|
5
|
-
require_relative 'paragraph'
|
|
6
|
-
require_relative 'table'
|
|
7
|
-
require_relative 'table_row'
|
|
8
|
-
require_relative 'table_cell'
|
|
9
|
-
require_relative 'table_header'
|
|
10
|
-
require_relative 'hard_break'
|
|
11
|
-
require_relative 'document'
|
|
12
|
-
require_relative 'heading'
|
|
13
|
-
require_relative 'mark/bold'
|
|
14
|
-
require_relative 'mark/italic'
|
|
15
|
-
require_relative 'mark/code'
|
|
16
|
-
require_relative 'mark/link'
|
|
17
|
-
require_relative 'ordered_list'
|
|
18
|
-
require_relative 'bullet_list'
|
|
19
|
-
require_relative 'list_item'
|
|
20
|
-
require_relative 'blockquote'
|
|
21
|
-
require_relative 'horizontal_rule'
|
|
22
|
-
require_relative 'image'
|
|
23
|
-
require_relative 'user'
|
|
24
|
-
|
|
25
3
|
module Prosereflect
|
|
26
4
|
class Parser
|
|
27
5
|
def self.parse(data)
|
|
@@ -33,57 +11,57 @@ module Prosereflect
|
|
|
33
11
|
def self.parse_node(data)
|
|
34
12
|
return nil unless data.is_a?(Hash)
|
|
35
13
|
|
|
36
|
-
type = data[
|
|
37
|
-
text = data[
|
|
38
|
-
attrs = data[
|
|
39
|
-
marks_data = data[
|
|
14
|
+
type = data["type"]
|
|
15
|
+
text = data["text"]
|
|
16
|
+
attrs = data["attrs"]
|
|
17
|
+
marks_data = data["marks"]
|
|
40
18
|
|
|
41
19
|
# Find the right class based on type
|
|
42
20
|
node_class = case type
|
|
43
|
-
when
|
|
21
|
+
when "doc"
|
|
44
22
|
Document
|
|
45
|
-
when
|
|
23
|
+
when "paragraph"
|
|
46
24
|
Paragraph
|
|
47
|
-
when
|
|
25
|
+
when "text"
|
|
48
26
|
Text
|
|
49
|
-
when
|
|
27
|
+
when "table"
|
|
50
28
|
Table
|
|
51
|
-
when
|
|
29
|
+
when "table_row"
|
|
52
30
|
TableRow
|
|
53
|
-
when
|
|
31
|
+
when "table_cell"
|
|
54
32
|
TableCell
|
|
55
|
-
when
|
|
33
|
+
when "table_header"
|
|
56
34
|
TableHeader
|
|
57
|
-
when
|
|
35
|
+
when "hard_break"
|
|
58
36
|
HardBreak
|
|
59
|
-
when
|
|
37
|
+
when "heading"
|
|
60
38
|
Heading
|
|
61
|
-
when
|
|
39
|
+
when "ordered_list"
|
|
62
40
|
OrderedList
|
|
63
|
-
when
|
|
41
|
+
when "bullet_list"
|
|
64
42
|
BulletList
|
|
65
|
-
when
|
|
43
|
+
when "list_item"
|
|
66
44
|
ListItem
|
|
67
|
-
when
|
|
45
|
+
when "blockquote"
|
|
68
46
|
Blockquote
|
|
69
|
-
when
|
|
47
|
+
when "horizontal_rule"
|
|
70
48
|
HorizontalRule
|
|
71
|
-
when
|
|
49
|
+
when "image"
|
|
72
50
|
Image
|
|
73
|
-
when
|
|
51
|
+
when "user"
|
|
74
52
|
User
|
|
75
53
|
else
|
|
76
54
|
Node
|
|
77
55
|
end
|
|
78
56
|
|
|
79
|
-
if type ==
|
|
57
|
+
if type == "text"
|
|
80
58
|
node = Text.new(text: text)
|
|
81
59
|
else
|
|
82
60
|
node = node_class.create(attrs)
|
|
83
61
|
|
|
84
62
|
# Process content recursively
|
|
85
|
-
if data[
|
|
86
|
-
data[
|
|
63
|
+
if data["content"].is_a?(Array)
|
|
64
|
+
data["content"].each do |content_data|
|
|
87
65
|
child_node = parse_node(content_data)
|
|
88
66
|
node.add_child(child_node) if child_node
|
|
89
67
|
end
|
|
@@ -92,30 +70,30 @@ module Prosereflect
|
|
|
92
70
|
|
|
93
71
|
# Handle special attributes for specific node types
|
|
94
72
|
case type
|
|
95
|
-
when
|
|
96
|
-
node.start = attrs[
|
|
97
|
-
when
|
|
98
|
-
node.bullet_style = attrs[
|
|
99
|
-
when
|
|
100
|
-
node.citation = attrs[
|
|
101
|
-
when
|
|
73
|
+
when "ordered_list"
|
|
74
|
+
node.start = attrs["start"].to_i if attrs && attrs["start"]
|
|
75
|
+
when "bullet_list"
|
|
76
|
+
node.bullet_style = attrs["bullet_style"] if attrs && attrs["bullet_style"]
|
|
77
|
+
when "blockquote"
|
|
78
|
+
node.citation = attrs["cite"] if attrs && attrs["cite"]
|
|
79
|
+
when "horizontal_rule"
|
|
102
80
|
if attrs
|
|
103
|
-
node.style = attrs[
|
|
104
|
-
node.width = attrs[
|
|
105
|
-
node.thickness = attrs[
|
|
81
|
+
node.style = attrs["border_style"] if attrs["border_style"]
|
|
82
|
+
node.width = attrs["width"] if attrs["width"]
|
|
83
|
+
node.thickness = attrs["thickness"].to_i if attrs["thickness"]
|
|
106
84
|
end
|
|
107
|
-
when
|
|
85
|
+
when "image"
|
|
108
86
|
if attrs
|
|
109
|
-
node.src = attrs[
|
|
110
|
-
node.alt = attrs[
|
|
111
|
-
node.title = attrs[
|
|
112
|
-
node.dimensions = [attrs[
|
|
87
|
+
node.src = attrs["src"] if attrs["src"]
|
|
88
|
+
node.alt = attrs["alt"] if attrs["alt"]
|
|
89
|
+
node.title = attrs["title"] if attrs["title"]
|
|
90
|
+
node.dimensions = [attrs["width"]&.to_i, attrs["height"]&.to_i]
|
|
113
91
|
end
|
|
114
|
-
when
|
|
92
|
+
when "table_header"
|
|
115
93
|
if attrs
|
|
116
|
-
node.scope = attrs[
|
|
117
|
-
node.abbr = attrs[
|
|
118
|
-
node.colspan = attrs[
|
|
94
|
+
node.scope = attrs["scope"] if attrs["scope"]
|
|
95
|
+
node.abbr = attrs["abbr"] if attrs["abbr"]
|
|
96
|
+
node.colspan = attrs["colspan"] if attrs["colspan"]
|
|
119
97
|
end
|
|
120
98
|
end
|
|
121
99
|
|
|
@@ -125,8 +103,11 @@ module Prosereflect
|
|
|
125
103
|
end
|
|
126
104
|
|
|
127
105
|
def self.parse_document(data)
|
|
128
|
-
raise ArgumentError,
|
|
129
|
-
|
|
106
|
+
raise ArgumentError, "Input cannot be nil" if data.nil?
|
|
107
|
+
unless data.is_a?(Hash)
|
|
108
|
+
raise ArgumentError,
|
|
109
|
+
"Input must be a hash, got #{data.class}"
|
|
110
|
+
end
|
|
130
111
|
|
|
131
112
|
document = parse_node(data)
|
|
132
113
|
|
data/lib/prosereflect/table.rb
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'node'
|
|
4
|
-
require_relative 'table_row'
|
|
5
|
-
require_relative 'table_header'
|
|
6
|
-
|
|
7
3
|
module Prosereflect
|
|
8
4
|
# TODO: support for table attributes
|
|
9
5
|
# Table class represents a ProseMirror table.
|
|
10
6
|
# It contains rows, each of which can contain cells.
|
|
11
7
|
class Table < Node
|
|
12
|
-
PM_TYPE =
|
|
8
|
+
PM_TYPE = "table"
|
|
13
9
|
|
|
14
|
-
attribute :type, :string, default: -> {
|
|
10
|
+
attribute :type, :string, default: -> {
|
|
11
|
+
self.class.send(:const_get, "PM_TYPE")
|
|
12
|
+
}
|
|
15
13
|
|
|
16
14
|
key_value do
|
|
17
|
-
map
|
|
18
|
-
map
|
|
19
|
-
map
|
|
15
|
+
map "type", to: :type, render_default: true
|
|
16
|
+
map "content", to: :content
|
|
17
|
+
map "attrs", to: :attrs
|
|
20
18
|
end
|
|
21
19
|
|
|
22
20
|
def initialize(attributes = {})
|
|
@@ -84,10 +82,11 @@ module Prosereflect
|
|
|
84
82
|
# Override to_h to handle empty content and attributes properly
|
|
85
83
|
def to_h
|
|
86
84
|
result = super
|
|
87
|
-
result[
|
|
88
|
-
if result[
|
|
89
|
-
result[
|
|
90
|
-
|
|
85
|
+
result["content"] ||= []
|
|
86
|
+
if result["attrs"]
|
|
87
|
+
result["attrs"] =
|
|
88
|
+
result["attrs"].is_a?(Hash) && result["attrs"][:attrs] ? result["attrs"][:attrs] : result["attrs"]
|
|
89
|
+
result.delete("attrs") if result["attrs"].empty?
|
|
91
90
|
end
|
|
92
91
|
result
|
|
93
92
|
end
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'node'
|
|
4
|
-
require_relative 'paragraph'
|
|
5
|
-
|
|
6
3
|
module Prosereflect
|
|
7
4
|
class TableCell < Node
|
|
8
|
-
PM_TYPE =
|
|
5
|
+
PM_TYPE = "table_cell"
|
|
9
6
|
|
|
10
|
-
attribute :type, :string, default: -> {
|
|
7
|
+
attribute :type, :string, default: -> {
|
|
8
|
+
self.class.send(:const_get, "PM_TYPE")
|
|
9
|
+
}
|
|
11
10
|
|
|
12
11
|
key_value do
|
|
13
|
-
map
|
|
14
|
-
map
|
|
15
|
-
map
|
|
12
|
+
map "type", to: :type, render_default: true
|
|
13
|
+
map "content", to: :content
|
|
14
|
+
map "attrs", to: :attrs
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
def initialize(attributes = {})
|
|
@@ -27,7 +26,7 @@ module Prosereflect
|
|
|
27
26
|
def paragraphs
|
|
28
27
|
return [] unless content
|
|
29
28
|
|
|
30
|
-
content.
|
|
29
|
+
content.grep(Paragraph)
|
|
31
30
|
end
|
|
32
31
|
|
|
33
32
|
def text_content
|
|
@@ -51,10 +50,11 @@ module Prosereflect
|
|
|
51
50
|
# Override to_h to handle empty content and attributes properly
|
|
52
51
|
def to_h
|
|
53
52
|
result = super
|
|
54
|
-
result[
|
|
55
|
-
if result[
|
|
56
|
-
result[
|
|
57
|
-
|
|
53
|
+
result["content"] ||= []
|
|
54
|
+
if result["attrs"]
|
|
55
|
+
result["attrs"] =
|
|
56
|
+
result["attrs"].is_a?(Hash) && result["attrs"][:attrs] ? result["attrs"][:attrs] : result["attrs"]
|
|
57
|
+
result.delete("attrs") if result["attrs"].empty?
|
|
58
58
|
end
|
|
59
59
|
result
|
|
60
60
|
end
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'table_cell'
|
|
4
|
-
|
|
5
3
|
module Prosereflect
|
|
6
4
|
# TableHeader class represents a header cell in a table (<th> tag).
|
|
7
5
|
# It inherits from TableCell but adds header-specific attributes.
|
|
8
6
|
class TableHeader < TableCell
|
|
9
|
-
PM_TYPE =
|
|
7
|
+
PM_TYPE = "table_header"
|
|
10
8
|
|
|
11
|
-
attribute :type, :string, default: -> {
|
|
9
|
+
attribute :type, :string, default: -> {
|
|
10
|
+
self.class.send(:const_get, "PM_TYPE")
|
|
11
|
+
}
|
|
12
12
|
attribute :scope, :string # row, col, rowgroup, or colgroup
|
|
13
13
|
attribute :abbr, :string # abbreviated version of content
|
|
14
14
|
attribute :colspan, :integer # number of columns this header spans
|
|
15
15
|
|
|
16
16
|
key_value do
|
|
17
|
-
map
|
|
18
|
-
map
|
|
19
|
-
map
|
|
17
|
+
map "type", to: :type, render_default: true
|
|
18
|
+
map "content", to: :content
|
|
19
|
+
map "attrs", to: :attrs
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def initialize(attributes = {})
|
|
@@ -41,21 +41,21 @@ module Prosereflect
|
|
|
41
41
|
return unless %w[row col rowgroup colgroup].include?(scope_value)
|
|
42
42
|
|
|
43
43
|
self.attrs ||= {}
|
|
44
|
-
attrs[
|
|
44
|
+
attrs["scope"] = scope_value
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def scope
|
|
48
|
-
attrs&.[](
|
|
48
|
+
attrs&.[]("scope")
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# Set abbreviated version of the header content
|
|
52
52
|
def abbr=(abbr_text)
|
|
53
53
|
self.attrs ||= {}
|
|
54
|
-
attrs[
|
|
54
|
+
attrs["abbr"] = abbr_text
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def abbr
|
|
58
|
-
attrs&.[](
|
|
58
|
+
attrs&.[]("abbr")
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
# Set the number of columns this header spans
|
|
@@ -63,11 +63,11 @@ module Prosereflect
|
|
|
63
63
|
return unless span.to_i.positive?
|
|
64
64
|
|
|
65
65
|
self.attrs ||= {}
|
|
66
|
-
attrs[
|
|
66
|
+
attrs["colspan"] = span.to_i
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
def colspan
|
|
70
|
-
attrs&.[](
|
|
70
|
+
attrs&.[]("colspan")
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
# Get header attributes as a hash
|
|
@@ -75,16 +75,16 @@ module Prosereflect
|
|
|
75
75
|
{
|
|
76
76
|
scope: scope,
|
|
77
77
|
abbr: abbr,
|
|
78
|
-
colspan: colspan
|
|
78
|
+
colspan: colspan,
|
|
79
79
|
}.compact
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
# Override to_h to exclude nil attributes
|
|
83
83
|
def to_h
|
|
84
84
|
result = super
|
|
85
|
-
if result[
|
|
86
|
-
result[
|
|
87
|
-
result.delete(
|
|
85
|
+
if result["attrs"]
|
|
86
|
+
result["attrs"].compact!
|
|
87
|
+
result.delete("attrs") if result["attrs"].empty?
|
|
88
88
|
end
|
|
89
89
|
result
|
|
90
90
|
end
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'node'
|
|
4
|
-
require_relative 'table_cell'
|
|
5
|
-
|
|
6
3
|
module Prosereflect
|
|
7
4
|
class TableRow < Node
|
|
8
|
-
PM_TYPE =
|
|
5
|
+
PM_TYPE = "table_row"
|
|
9
6
|
|
|
10
|
-
attribute :type, :string, default: -> {
|
|
7
|
+
attribute :type, :string, default: -> {
|
|
8
|
+
self.class.send(:const_get, "PM_TYPE")
|
|
9
|
+
}
|
|
11
10
|
|
|
12
11
|
key_value do
|
|
13
|
-
map
|
|
14
|
-
map
|
|
15
|
-
map
|
|
12
|
+
map "type", to: :type, render_default: true
|
|
13
|
+
map "content", to: :content
|
|
14
|
+
map "attrs", to: :attrs
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
def initialize(opts = {})
|
|
@@ -44,10 +43,11 @@ module Prosereflect
|
|
|
44
43
|
# Override to_h to handle empty content and attributes properly
|
|
45
44
|
def to_h
|
|
46
45
|
result = super
|
|
47
|
-
result[
|
|
48
|
-
if result[
|
|
49
|
-
result[
|
|
50
|
-
|
|
46
|
+
result["content"] ||= []
|
|
47
|
+
if result["attrs"]
|
|
48
|
+
result["attrs"] =
|
|
49
|
+
result["attrs"].is_a?(Hash) && result["attrs"][:attrs] ? result["attrs"][:attrs] : result["attrs"]
|
|
50
|
+
result.delete("attrs") if result["attrs"].empty?
|
|
51
51
|
end
|
|
52
52
|
result
|
|
53
53
|
end
|
data/lib/prosereflect/text.rb
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'node'
|
|
4
|
-
|
|
5
3
|
module Prosereflect
|
|
6
4
|
class Text < Node
|
|
7
|
-
PM_TYPE =
|
|
5
|
+
PM_TYPE = "text"
|
|
8
6
|
|
|
9
|
-
attribute :type, :string, default: -> {
|
|
10
|
-
|
|
7
|
+
attribute :type, :string, default: -> {
|
|
8
|
+
self.class.send(:const_get, "PM_TYPE")
|
|
9
|
+
}
|
|
10
|
+
attribute :text, :string, default: ""
|
|
11
11
|
|
|
12
12
|
key_value do
|
|
13
|
-
map
|
|
14
|
-
map
|
|
15
|
-
map
|
|
13
|
+
map "type", to: :type, render_default: true
|
|
14
|
+
map "text", to: :text
|
|
15
|
+
map "marks", to: :marks
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def self.create(text =
|
|
18
|
+
def self.create(text = "", marks = nil)
|
|
19
19
|
new(text: text, marks: marks)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def text_content
|
|
23
|
-
text ||
|
|
23
|
+
text || ""
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
# Override the to_h method to include the text attribute
|
|
27
27
|
def to_h
|
|
28
28
|
result = super
|
|
29
|
-
result[
|
|
29
|
+
result["text"] = text
|
|
30
30
|
result
|
|
31
31
|
end
|
|
32
32
|
end
|
data/lib/prosereflect/user.rb
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'node'
|
|
4
|
-
|
|
5
3
|
module Prosereflect
|
|
6
4
|
# User class represents a user mention in ProseMirror.
|
|
7
5
|
class User < Node
|
|
8
|
-
PM_TYPE =
|
|
6
|
+
PM_TYPE = "user"
|
|
9
7
|
|
|
10
|
-
attribute :type, :string, default: -> {
|
|
8
|
+
attribute :type, :string, default: -> {
|
|
9
|
+
self.class.send(:const_get, "PM_TYPE")
|
|
10
|
+
}
|
|
11
11
|
attribute :id, :string
|
|
12
12
|
attribute :attrs, :hash
|
|
13
13
|
|
|
14
14
|
key_value do
|
|
15
|
-
map
|
|
16
|
-
map
|
|
17
|
-
map
|
|
15
|
+
map "type", to: :type, render_default: true
|
|
16
|
+
map "attrs", to: :attrs
|
|
17
|
+
map "content", to: :content
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def initialize(attributes = {})
|
|
@@ -23,8 +23,8 @@ module Prosereflect
|
|
|
23
23
|
|
|
24
24
|
return unless attributes[:attrs]
|
|
25
25
|
|
|
26
|
-
@id = attributes[:attrs][
|
|
27
|
-
self.attrs = {
|
|
26
|
+
@id = attributes[:attrs]["id"]
|
|
27
|
+
self.attrs = { "id" => @id }
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def self.create(attrs = nil)
|
|
@@ -35,16 +35,16 @@ module Prosereflect
|
|
|
35
35
|
def id=(user_id)
|
|
36
36
|
@id = user_id
|
|
37
37
|
self.attrs ||= {}
|
|
38
|
-
attrs[
|
|
38
|
+
attrs["id"] = user_id
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def id
|
|
42
|
-
@id || attrs&.[](
|
|
42
|
+
@id || attrs&.[]("id")
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
# Override content-related methods since user mentions don't have content
|
|
46
46
|
def add_child(*)
|
|
47
|
-
raise NotImplementedError,
|
|
47
|
+
raise NotImplementedError, "User mention nodes cannot have children"
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def content
|
|
@@ -53,10 +53,10 @@ module Prosereflect
|
|
|
53
53
|
|
|
54
54
|
def to_h
|
|
55
55
|
hash = super
|
|
56
|
-
hash[
|
|
57
|
-
|
|
56
|
+
hash["attrs"] = {
|
|
57
|
+
"id" => id,
|
|
58
58
|
}
|
|
59
|
-
hash[
|
|
59
|
+
hash["content"] = []
|
|
60
60
|
hash
|
|
61
61
|
end
|
|
62
62
|
end
|
data/lib/prosereflect/version.rb
CHANGED
data/lib/prosereflect.rb
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require_relative 'prosereflect/node'
|
|
5
|
-
require_relative 'prosereflect/mark'
|
|
6
|
-
require_relative 'prosereflect/attribute'
|
|
7
|
-
require_relative 'prosereflect/text'
|
|
8
|
-
require_relative 'prosereflect/paragraph'
|
|
9
|
-
require_relative 'prosereflect/hard_break'
|
|
10
|
-
require_relative 'prosereflect/table'
|
|
11
|
-
require_relative 'prosereflect/table_row'
|
|
12
|
-
require_relative 'prosereflect/table_cell'
|
|
13
|
-
require_relative 'prosereflect/heading'
|
|
14
|
-
require_relative 'prosereflect/document'
|
|
15
|
-
require_relative 'prosereflect/parser'
|
|
16
|
-
require_relative 'prosereflect/input/html'
|
|
17
|
-
require_relative 'prosereflect/output/html'
|
|
18
|
-
require_relative 'prosereflect/user'
|
|
3
|
+
require "lutaml/model"
|
|
19
4
|
|
|
20
5
|
module Prosereflect
|
|
21
6
|
class Error < StandardError; end
|
|
22
|
-
|
|
7
|
+
|
|
8
|
+
autoload :Attribute, "prosereflect/attribute"
|
|
9
|
+
autoload :Blockquote, "prosereflect/blockquote"
|
|
10
|
+
autoload :BulletList, "prosereflect/bullet_list"
|
|
11
|
+
autoload :CodeBlock, "prosereflect/code_block"
|
|
12
|
+
autoload :CodeBlockWrapper, "prosereflect/code_block_wrapper"
|
|
13
|
+
autoload :Document, "prosereflect/document"
|
|
14
|
+
autoload :HardBreak, "prosereflect/hard_break"
|
|
15
|
+
autoload :Heading, "prosereflect/heading"
|
|
16
|
+
autoload :HorizontalRule, "prosereflect/horizontal_rule"
|
|
17
|
+
autoload :Image, "prosereflect/image"
|
|
18
|
+
autoload :Input, "prosereflect/input"
|
|
19
|
+
autoload :ListItem, "prosereflect/list_item"
|
|
20
|
+
autoload :Mark, "prosereflect/mark"
|
|
21
|
+
autoload :Node, "prosereflect/node"
|
|
22
|
+
autoload :OrderedList, "prosereflect/ordered_list"
|
|
23
|
+
autoload :Output, "prosereflect/output"
|
|
24
|
+
autoload :Paragraph, "prosereflect/paragraph"
|
|
25
|
+
autoload :Parser, "prosereflect/parser"
|
|
26
|
+
autoload :Table, "prosereflect/table"
|
|
27
|
+
autoload :TableCell, "prosereflect/table_cell"
|
|
28
|
+
autoload :TableHeader, "prosereflect/table_header"
|
|
29
|
+
autoload :TableRow, "prosereflect/table_row"
|
|
30
|
+
autoload :Text, "prosereflect/text"
|
|
31
|
+
autoload :User, "prosereflect/user"
|
|
32
|
+
autoload :VERSION, "prosereflect/version"
|
|
23
33
|
end
|
data/prosereflect.gemspec
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
3
|
+
require_relative "lib/prosereflect/version"
|
|
4
4
|
|
|
5
5
|
all_files_in_git = Dir.chdir(File.expand_path(__dir__)) do
|
|
6
6
|
`git ls-files -z`.split("\x0")
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
Gem::Specification.new do |spec|
|
|
10
|
-
spec.name =
|
|
10
|
+
spec.name = "prosereflect"
|
|
11
11
|
spec.version = Prosereflect::VERSION
|
|
12
|
-
spec.authors = [
|
|
13
|
-
spec.email = [
|
|
12
|
+
spec.authors = ["Ribose"]
|
|
13
|
+
spec.email = ["open.source@ribose.com"]
|
|
14
14
|
|
|
15
|
-
spec.summary =
|
|
16
|
-
spec.homepage =
|
|
17
|
-
spec.license =
|
|
18
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
|
15
|
+
spec.summary = "Ruby model accessor for prosereflect document trees."
|
|
16
|
+
spec.homepage = "https://github.com/metanorma/prosereflect"
|
|
17
|
+
spec.license = "BSD-2-Clause"
|
|
18
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
|
19
19
|
|
|
20
|
-
spec.metadata[
|
|
21
|
-
spec.metadata[
|
|
22
|
-
spec.metadata[
|
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
21
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
22
|
+
spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
|
|
23
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
23
24
|
|
|
24
25
|
# Specify which files should be added to the gem when it is released.
|
|
25
26
|
spec.files = all_files_in_git
|
|
26
|
-
|
|
27
|
+
.reject { |f| f.match(%r{\A(?:test|features|bin|\.)/}) }
|
|
27
28
|
|
|
28
|
-
spec.bindir =
|
|
29
|
+
spec.bindir = "exe"
|
|
29
30
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
-
spec.require_paths = [
|
|
31
|
+
spec.require_paths = ["lib"]
|
|
31
32
|
|
|
32
|
-
spec.add_dependency
|
|
33
|
-
spec.add_dependency
|
|
33
|
+
spec.add_dependency "lutaml-model", "~> 0.8"
|
|
34
|
+
spec.add_dependency "nokogiri", "~> 1.18"
|
|
34
35
|
end
|