fix(attestation): don't render block levels presentation elements into a p
This commit is contained in:
parent
c9956c4881
commit
4db4cf1513
5 changed files with 26 additions and 7 deletions
9
app/models/champ_presentations/base_presentation.rb
Normal file
9
app/models/champ_presentations/base_presentation.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module ChampPresentations
|
||||||
|
class BasePresentation
|
||||||
|
def block_level?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ChampPresentations::MultipleDropDownListPresentation
|
class ChampPresentations::MultipleDropDownListPresentation < ChampPresentations::BasePresentation
|
||||||
attr_reader :selected_options
|
attr_reader :selected_options
|
||||||
|
|
||||||
def initialize(selected_options)
|
def initialize(selected_options)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ChampPresentations::RepetitionPresentation
|
class ChampPresentations::RepetitionPresentation < ChampPresentations::BasePresentation
|
||||||
attr_reader :libelle
|
attr_reader :libelle
|
||||||
attr_reader :rows
|
attr_reader :rows
|
||||||
|
|
||||||
|
|
|
@ -96,11 +96,11 @@ class TiptapService
|
||||||
text
|
text
|
||||||
end
|
end
|
||||||
in type: 'mention', attrs: { id: }, **rest
|
in type: 'mention', attrs: { id: }, **rest
|
||||||
text_or_representation = substitutions.fetch(id) { "--#{id}--" }
|
text_or_presentation = substitutions.fetch(id) { "--#{id}--" }
|
||||||
text = if text_or_representation.respond_to?(:to_tiptap_node)
|
text = if text_or_presentation.respond_to?(:to_tiptap_node)
|
||||||
node_to_html(text_or_representation.to_tiptap_node, substitutions, level + 1)
|
handle_presentation_node(text_or_presentation, substitutions, level + 1)
|
||||||
else
|
else
|
||||||
text_or_representation
|
text_or_presentation
|
||||||
end
|
end
|
||||||
|
|
||||||
if rest[:marks].present?
|
if rest[:marks].present?
|
||||||
|
@ -113,6 +113,16 @@ class TiptapService
|
||||||
end
|
end
|
||||||
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)
|
def text_align(attrs)
|
||||||
if attrs.present? && attrs[:textAlign].present?
|
if attrs.present? && attrs[:textAlign].present?
|
||||||
" style=\"text-align: #{attrs[:textAlign]}\""
|
" style=\"text-align: #{attrs[:textAlign]}\""
|
||||||
|
|
|
@ -171,7 +171,7 @@ RSpec.describe TiptapService do
|
||||||
'<p><s><em>Bonjour </em></s><u><strong>Paul</strong></u> <mark>!</mark></p>',
|
'<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>',
|
'<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>',
|
'<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>'
|
'<footer>Footer</footer>'
|
||||||
].join
|
].join
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue