Skip to content

Commit

Permalink
Fix: Custom MD link renderer broken in staging
Browse files Browse the repository at this point in the history
Closes #342
  • Loading branch information
bkis committed Sep 23, 2024
1 parent bfe3b03 commit 6fe8977
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Tekst-Web/scripts/parseHelpTexts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ const localeDirs = readdirSync(HELP_DIR, { withFileTypes: true }).filter((entry)
const localeImports = []; // imports in index file

// customize marked's link renderer to include "target" and "rel" attributes
const mdRenderer = new marked.Renderer();
mdRenderer.link = (href, title, text) => {
const titleAttr = title ? ` title="${title}"` : '';
return `<a href="${href}"${titleAttr} target="_blank" rel="noopener noreferrer">${text}</a>`;
const renderer = {
link(href, title, text) {
const link = marked.Renderer.prototype.link.call(this, href, title, text);
const titleAttr = title ? ` title="${title}"` : '';
return link.replace('<a', `<a target="_blank" rel="noreferrer"${titleAttr} `);
},
};
marked.setOptions({ renderer: mdRenderer });
marked.use({ renderer });

// delete old target files
console.log(`🗑 Deleting old help text translations in ${OUT_DIR} ...`);
Expand Down

0 comments on commit 6fe8977

Please sign in to comment.