style(attestation): fix for headings style and spacing following charte

This commit is contained in:
Colin Darie 2024-02-02 13:49:22 +01:00
parent 72e59b6473
commit eb55abebfc
4 changed files with 35 additions and 19 deletions

View file

@ -110,7 +110,7 @@
}
.body-start {
margin-top: 30mm;
margin-top: 12.6mm; // from masque traitement de texte
}
.main {
@ -140,13 +140,13 @@
h2 {
margin: 0;
line-height: 6pt;
line-height: 8pt;
}
h3 {
font-size: 11pt;
font-weight: normal;
line-height: 3pt;
font-size: 10pt; // same as text
font-weight: bold;
line-height: 4pt;
}
li p {

View file

@ -49,8 +49,8 @@
}
h3 {
font-size: 1.15rem;
font-weight: normal;
font-size: 1rem; // same as text
font-weight: bold;
line-height: 1rem;
}

View file

@ -30,7 +30,7 @@ class TiptapService
end
def node_to_html(node, substitutions, level)
if level == 0 && !@body_started && node[:type] == 'paragraph' && node.key?(:content)
if level == 0 && !@body_started && node[:type].in?(['paragraph', 'heading']) && node.key?(:content)
@body_started = true
body_start_mark = " class=\"body-start\""
end
@ -47,7 +47,7 @@ class TiptapService
in type: 'title', content:, **rest
"<h1#{text_align(rest[:attrs])}>#{children(content, substitutions, level + 1)}</h1>"
in type: 'heading', attrs: { level: hlevel, **attrs }, content:
"<h#{hlevel}#{text_align(attrs)}>#{children(content, substitutions, level + 1)}</h#{hlevel}>"
"<h#{hlevel}#{body_start_mark}#{text_align(attrs)}>#{children(content, substitutions, level + 1)}</h#{hlevel}>"
in type: 'bulletList', content:
"<ul>#{children(content, substitutions, level + 1)}</ul>"
in type: 'orderedList', content:

View file

@ -23,11 +23,6 @@ RSpec.describe TiptapService do
{
type: 'title' # remained empty in editor
},
{
type: 'heading',
attrs: { level: 1 },
content: [{ type: 'text', text: 'Heading 1' }]
},
{
type: 'heading',
attrs: { level: 2, textAlign: 'center' },
@ -35,7 +30,7 @@ RSpec.describe TiptapService do
},
{
type: 'heading',
attrs: { level: 3 },
attrs: { level: 3, textAlign: 'center' },
content: [{ type: 'text', text: 'Heading 3' }]
},
{
@ -155,10 +150,9 @@ RSpec.describe TiptapService do
[
'<header><div>Left</div><div>Right</div></header>',
'<h1>Title</h1>',
'<h1>Heading 1</h1>',
'<h2 style="text-align: center">Heading 2</h2>',
'<h3>Heading 3</h3>',
'<p class="body-start" style="text-align: right">First paragraph</p>',
'<h2 class="body-start" style="text-align: center">Heading 2</h2>',
'<h3 style="text-align: center">Heading 3</h3>',
'<p style="text-align: right">First paragraph</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>',
'<ol><li><p>Item 1</p></li><li><p>Item 2</p></li></ol>',
@ -169,6 +163,28 @@ RSpec.describe TiptapService do
it 'returns html' do
expect(described_class.new.to_html(json, substitutions)).to eq(html)
end
context 'body start on paragraph' do
let(:json) do
{
type: 'doc',
content: [
{
type: 'title',
content: [{ type: 'text', text: 'The Title' }]
},
{
type: 'paragraph',
content: [{ type: 'text', text: 'First paragraph' }]
}
]
}
end
it 'defines stat body on first paragraph' do
expect(described_class.new.to_html(json, substitutions)).to eq("<h1>The Title</h1><p class=\"body-start\">First paragraph</p>")
end
end
end
describe '#used_tags' do