Skip to content

Commit f0de3af

Browse files
authored
fix(glossaire): ignore les headings dans le glossaire (#1235)
1 parent 0d2196b commit f0de3af

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

targets/export-elasticsearch/src/ingester/glossary/__tests__/glossary.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,33 @@ describe("Glossary", () => {
3939
);
4040
});
4141

42+
test("should add webcomponent tooltip even if next tag is omitted", () => {
43+
const htmlContent = `<p>indemnité</p><summary>test</summary>`;
44+
expect(addGlossary(htmlContent)).toEqual(
45+
`<p><webcomponent-tooltip content="Sommes%20vers%C3%A9es%20en%20compensation%20ou%20en%20r%C3%A9paration%20de%20quelque%20chose.">indemnité</webcomponent-tooltip></p><summary>test</summary>`
46+
);
47+
});
48+
4249
test("should not add webcomponent tooltip in a summary tag with strong", () => {
4350
const htmlContent = `<summary><strong>L'indemnité de fin de contrat n'est pas due dans les cas suivants</strong></summary>`;
4451
expect(addGlossary(htmlContent)).toEqual(
4552
`<summary><strong>L'indemnité de fin de contrat n'est pas due dans les cas suivants</strong></summary>`
4653
);
4754
});
4855

56+
test.each`
57+
heading
58+
${"h1"}
59+
${"h2"}
60+
${"h3"}
61+
${"h4"}
62+
${"h5"}
63+
${"h6"}
64+
`("should not add webcomponent tooltip in $heading", ({ heading }) => {
65+
const markdown = `<${heading}>indemnité</${heading}>`;
66+
expect(addGlossary(markdown)).toEqual(markdown);
67+
});
68+
4969
test("should not replace html property for cc word", () => {
5070
const htmlContent =
5171
'<p class="un accord de branche ou pas">voici une convention collective et un web component mais aussi dispositions, ceci est un test</p>';

targets/export-elasticsearch/src/ingester/glossary/explodeGlossaryTerms.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ const conventionMatchers =
77
const startWordBreaks = `(?<=^| |\\.|,|'|>|\\()`;
88
const endWordBreaks = `(?= |\\.|,|'|$|<|\\))`;
99

10-
const startAnchorOmit = `(?<!<a>|<summary>|<summary><strong>)`;
11-
const endAnchorOmit = `(?![^<]*</a>|[^<]*</summary>|[^<]*</strong></summary>)`;
10+
const endAnchorOmit = `(?![^<]*</a>|[^<]*</summary>|[^<]*</strong></summary>|[^<]*</h[1-6]>)`;
1211

1312
const tagAttributeOmit = `(?<=(^|>)[^><]*)`;
1413

15-
const startTag = `${startAnchorOmit}${tagAttributeOmit}${startWordBreaks}`;
14+
const startTag = `${tagAttributeOmit}${startWordBreaks}`;
1615
const endTag = `${endWordBreaks}${endAnchorOmit}`;
1716

1817
export const explodeGlossaryTerms = (glossary: Glossary): GlossaryTerms[] => {

0 commit comments

Comments
 (0)