coradoc-mirror 0.1.8 → 0.1.9
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/lib/coradoc/mirror/handlers/inline.rb +44 -0
- data/lib/coradoc/mirror/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d0dddcebf58649933def45133c70a5ed3caf8f1441d1a789b9ea95d49fa8d24
|
|
4
|
+
data.tar.gz: 6275f1315af45cb267762a26862bdcb1d2bb65e29fd4657cd411a98200b6c0f9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13c8d02108886f582cf93f501a9e503361c450c224f0105e255583200323bd4d170d3303b2250510922ee4dad0aa92b45a987caf690528098f77d90b18e2672a
|
|
7
|
+
data.tar.gz: 3eef4445a831dfce49faaa0e777ad4cd28fb54d9d7b71db640e45585ea557267f87b831031839da32077bf6886ae53f9d085e65200ac6aa2cc939c393f93df1d
|
|
@@ -123,12 +123,56 @@ module Coradoc
|
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
def build_simple_mark(element, context, mark_class)
|
|
126
|
+
# When the mark carries parsed children (Bug 16B — nested
|
|
127
|
+
# inline marks like `**bold \`code\`**`), walk the children
|
|
128
|
+
# and apply this mark to each text leaf. Inner mark elements
|
|
129
|
+
# get the outer mark added to their marks list, producing
|
|
130
|
+
# ProseMirror's flat text-node-with-marks shape.
|
|
131
|
+
if element.children&.any?
|
|
132
|
+
return flatten_marked_children(element.children, [mark_class.new], context)
|
|
133
|
+
end
|
|
134
|
+
|
|
126
135
|
text = extract_inline_text(element)
|
|
127
136
|
return nil if text.empty?
|
|
128
137
|
|
|
129
138
|
context.text_node(text, marks: [mark_class.new])
|
|
130
139
|
end
|
|
131
140
|
|
|
141
|
+
# Walk a list of children, attaching the active set of marks
|
|
142
|
+
# to each text leaf. When a child is itself an InlineElement
|
|
143
|
+
# with its own mark (e.g. CodeElement inside BoldElement),
|
|
144
|
+
# the inner mark is added to the active set and recursion
|
|
145
|
+
# proceeds into its children. Produces the conjunction of
|
|
146
|
+
# marks for each text run that ProseMirror expects:
|
|
147
|
+
# **a `b` c** → text("a ", [bold]), text("b", [bold, code]), text(" c", [bold])
|
|
148
|
+
def flatten_marked_children(children, active_marks, context)
|
|
149
|
+
result = []
|
|
150
|
+
children.each do |child|
|
|
151
|
+
case child
|
|
152
|
+
when CoreModel::TextContent
|
|
153
|
+
next if child.text.nil? || child.text.empty?
|
|
154
|
+
|
|
155
|
+
result << context.text_node(child.text, marks: active_marks.dup)
|
|
156
|
+
when CoreModel::InlineElement
|
|
157
|
+
inner_mark_class = SIMPLE_MARK_TYPES[child.class]
|
|
158
|
+
if inner_mark_class && child.children&.any?
|
|
159
|
+
combined = active_marks + [inner_mark_class.new]
|
|
160
|
+
result.concat(flatten_marked_children(child.children, combined, context))
|
|
161
|
+
elsif inner_mark_class
|
|
162
|
+
text = extract_inline_text(child)
|
|
163
|
+
next if text.empty?
|
|
164
|
+
|
|
165
|
+
combined = active_marks + [inner_mark_class.new]
|
|
166
|
+
result << context.text_node(text, marks: combined)
|
|
167
|
+
else
|
|
168
|
+
nested = dispatch_inline(child, context)
|
|
169
|
+
result << nested if nested
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
result
|
|
174
|
+
end
|
|
175
|
+
|
|
132
176
|
def build_link_mark(element, context)
|
|
133
177
|
text = extract_inline_text(element)
|
|
134
178
|
text = element.target.to_s if text.empty? && element.target
|