Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
1 change: 1 addition & 0 deletions lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@
content: string,
context: { citations?: { url: string; title: string; filepath: string }[] },
): string {
if (!context?.citations) return content.replaceAll('\n', '\\n').replaceAll('"', '\"');

Check failure on line 517 in lib/helpers.ts

View workflow job for this annotation

GitHub Actions / lint / check

Unnecessary escape character: \"

Check failure on line 517 in lib/helpers.ts

View workflow job for this annotation

GitHub Actions / lint / check

Unnecessary escape character: \"

const { uniqueCitations, originalDocToUniqueDoc } = getUniqueCitationsAndMapping(context.citations);

Expand Down Expand Up @@ -583,7 +583,8 @@

replacedContent = replacedContent
.replaceAll('\n', '\\n')
.replaceAll('"', '\"')

Check failure on line 586 in lib/helpers.ts

View workflow job for this annotation

GitHub Actions / lint / check

Unnecessary escape character: \"

Check failure on line 586 in lib/helpers.ts

View workflow job for this annotation

GitHub Actions / lint / check

Unnecessary escape character: \"
.replaceAll(/([)\\/\p{L}\p{N}])⁽/gu, '$1 ⁽')
.replaceAll(/(⁽[⁰¹²³⁴⁵⁶⁷⁸⁹]+⁾)\1+/g, '$1');

if (links.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion views/pdf.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
</table>
</div>
</body>
</html>
</html>
Loading