From 4db4cf1513012ef2f3726083d4d45b7f874fa44d Mon Sep 17 00:00:00 2001
From: Colin Darie
Date: Fri, 30 Aug 2024 13:00:13 +0200
Subject: [PATCH] fix(attestation): don't render block levels presentation
elements into a p
---
.../champ_presentations/base_presentation.rb | 9 +++++++++
.../multiple_drop_down_list_presentation.rb | 2 +-
.../repetition_presentation.rb | 2 +-
app/services/tiptap_service.rb | 18 ++++++++++++++----
spec/services/tiptap_service_spec.rb | 2 +-
5 files changed, 26 insertions(+), 7 deletions(-)
create mode 100644 app/models/champ_presentations/base_presentation.rb
diff --git a/app/models/champ_presentations/base_presentation.rb b/app/models/champ_presentations/base_presentation.rb
new file mode 100644
index 000000000..6b043219b
--- /dev/null
+++ b/app/models/champ_presentations/base_presentation.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module ChampPresentations
+ class BasePresentation
+ def block_level?
+ true
+ end
+ end
+end
diff --git a/app/models/champ_presentations/multiple_drop_down_list_presentation.rb b/app/models/champ_presentations/multiple_drop_down_list_presentation.rb
index 21290193e..8660b06a2 100644
--- a/app/models/champ_presentations/multiple_drop_down_list_presentation.rb
+++ b/app/models/champ_presentations/multiple_drop_down_list_presentation.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class ChampPresentations::MultipleDropDownListPresentation
+class ChampPresentations::MultipleDropDownListPresentation < ChampPresentations::BasePresentation
attr_reader :selected_options
def initialize(selected_options)
diff --git a/app/models/champ_presentations/repetition_presentation.rb b/app/models/champ_presentations/repetition_presentation.rb
index 6a9c2bcb6..41bf2c2ad 100644
--- a/app/models/champ_presentations/repetition_presentation.rb
+++ b/app/models/champ_presentations/repetition_presentation.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class ChampPresentations::RepetitionPresentation
+class ChampPresentations::RepetitionPresentation < ChampPresentations::BasePresentation
attr_reader :libelle
attr_reader :rows
diff --git a/app/services/tiptap_service.rb b/app/services/tiptap_service.rb
index a55644353..1779f827d 100644
--- a/app/services/tiptap_service.rb
+++ b/app/services/tiptap_service.rb
@@ -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?
+ "
#{content}"
+ else
+ content
+ end
+ end
+
def text_align(attrs)
if attrs.present? && attrs[:textAlign].present?
" style=\"text-align: #{attrs[:textAlign]}\""
diff --git a/spec/services/tiptap_service_spec.rb b/spec/services/tiptap_service_spec.rb
index 287e76985..86ae1bbb2 100644
--- a/spec/services/tiptap_service_spec.rb
+++ b/spec/services/tiptap_service_spec.rb
@@ -171,7 +171,7 @@ RSpec.describe TiptapService do
'
Bonjour Paul !
',
'',
'Item 1
Item 2
',
- 'Langages de prédilection:
', # TODO: fix this markup,