fix(attestation): don't render block levels presentation elements into a p

This commit is contained in:
Colin Darie 2024-08-30 13:00:13 +02:00
parent c9956c4881
commit 4db4cf1513
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
5 changed files with 26 additions and 7 deletions

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
module ChampPresentations
class BasePresentation
def block_level?
true
end
end
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
class ChampPresentations::MultipleDropDownListPresentation
class ChampPresentations::MultipleDropDownListPresentation < ChampPresentations::BasePresentation
attr_reader :selected_options
def initialize(selected_options)

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
class ChampPresentations::RepetitionPresentation
class ChampPresentations::RepetitionPresentation < ChampPresentations::BasePresentation
attr_reader :libelle
attr_reader :rows

View file

@ -96,11 +96,11 @@ class TiptapService
text
end
in type: 'mention', attrs: { id: }, **rest
text_or_representation = substitutions.fetch(id) { "--#{id}--" }
text = if text_or_representation.respond_to?(:to_tiptap_node)
node_to_html(text_or_representation.to_tiptap_node, substitutions, level + 1)
text_or_presentation = substitutions.fetch(id) { "--#{id}--" }
text = if text_or_presentation.respond_to?(:to_tiptap_node)
handle_presentation_node(text_or_presentation, substitutions, level + 1)
else
text_or_representation
text_or_presentation
end
if rest[:marks].present?
@ -113,6 +113,16 @@ class TiptapService
end
end
def handle_presentation_node(presentation, substitutions, level)
node = presentation.to_tiptap_node
content = node_to_html(node, substitutions, level)
if presentation.block_level?
"</p>#{content}<p>"
else
content
end
end
def text_align(attrs)
if attrs.present? && attrs[:textAlign].present?
" style=\"text-align: #{attrs[:textAlign]}\""

View file

@ -171,7 +171,7 @@ RSpec.describe TiptapService do
'<p><s><em>Bonjour </em></s><u><strong>Paul</strong></u> <mark>!</mark></p>',
'<ul><li><p>Item 1</p></li><li><p>Item 2</p></li></ul>',
'<ol><li><p>Item 1</p></li><li><p>Item 2</p></li></ol>',
'<p>Langages de prédilection:<ul><li><p>ruby</p></li><li><p>rust</p></li></ul></p>', # TODO: fix this markup, <ul> should not be under <p>
'<p>Langages de prédilection:</p><ul><li><p>ruby</p></li><li><p>rust</p></li></ul><p></p>', # TODO: remove empty <p> ?
'<footer>Footer</footer>'
].join
end