diff --git a/lib/helpers.test.ts b/lib/helpers.test.ts index 003e922..0db9c19 100644 --- a/lib/helpers.test.ts +++ b/lib/helpers.test.ts @@ -215,6 +215,24 @@ describe('helpers', () => { expect(helpers.replaceDocs(content, context)).toMatch(/Viited/); }); + it('replaceDocs adds space before citation when it follows a link (closing paren)', () => { + const content = 'See (https://example.ee/cites)[doc1] for more.'; + const context = { + citations: [{ url: 'https://a', title: 'Example', filepath: 'https://example.ee/cites' }], + }; + const result = helpers.replaceDocs(content, context); + expect(result).toMatch(/cites\) ⁽¹⁾/); + }); + + it('replaceDocs adds space before citation when it follows a bare URL', () => { + const content = 'Lisainfot leiate „CITES" https://kliimaministeerium.ee/cites[doc1].'; + const context = { + citations: [{ url: 'https://a', title: 'Example', filepath: 'https://kliimaministeerium.ee/cites' }], + }; + const result = helpers.replaceDocs(content, context); + expect(result).toMatch(/cites ⁽¹⁾/); + }); + it('toArray wraps non-array', () => { expect(helpers.toArray(1)).toEqual([1]); expect(helpers.toArray([1, 2])).toEqual([1, 2]); diff --git a/lib/helpers.ts b/lib/helpers.ts index 95ad994..94bae0b 100644 --- a/lib/helpers.ts +++ b/lib/helpers.ts @@ -584,6 +584,7 @@ export function replaceDocs( replacedContent = replacedContent .replaceAll('\n', '\\n') .replaceAll('"', '\"') + .replaceAll(/([)\\/\p{L}\p{N}])⁽/gu, '$1 ⁽') .replaceAll(/(⁽[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾)\1+/g, '$1'); if (links.length > 0) { diff --git a/views/pdf.handlebars b/views/pdf.handlebars index 8292492..10e22f6 100644 --- a/views/pdf.handlebars +++ b/views/pdf.handlebars @@ -18,4 +18,4 @@ - + \ No newline at end of file