[tiptap] convert tiptap json to path
This commit is contained in:
parent
b3c2b46bb1
commit
93ad0f4bda
2 changed files with 37 additions and 0 deletions
|
@ -5,6 +5,12 @@ class TiptapService
|
|||
children(node[:content], substitutions, 0)
|
||||
end
|
||||
|
||||
def to_path(node, substitutions = {})
|
||||
return '' if node.nil?
|
||||
|
||||
children_path(node[:content], substitutions)
|
||||
end
|
||||
|
||||
# NOTE: node must be deep symbolized keys
|
||||
def used_tags_and_libelle_for(node, tags = Set.new)
|
||||
case node
|
||||
|
@ -25,6 +31,21 @@ class TiptapService
|
|||
@body_started = false
|
||||
end
|
||||
|
||||
def children_path(content, substitutions)
|
||||
content.map { node_to_path(_1, substitutions) }.join
|
||||
end
|
||||
|
||||
def node_to_path(node, substitutions)
|
||||
case node
|
||||
in type: 'paragraph', content:
|
||||
children_path(content, substitutions)
|
||||
in type: 'text', text:, **rest
|
||||
text.strip
|
||||
in type: 'mention', attrs: { id: }, **rest
|
||||
substitutions.fetch(id) { "--#{id}--" }
|
||||
end
|
||||
end
|
||||
|
||||
def children(content, substitutions, level)
|
||||
content.map { node_to_html(_1, substitutions, level) }.join
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue