Allow encode mailto and self target link in markdown

On translation files
This commit is contained in:
Andrey Antukh 2025-06-06 11:26:15 +02:00
parent e464d8cf9c
commit de2695682d
2 changed files with 20 additions and 10 deletions

View file

@ -237,18 +237,29 @@ async function renderTemplate(path, context = {}, partials = {}) {
return mustache.render(content, context, partials);
}
const extension = {
useNewRenderer: true,
const markedOptions = {
renderer: {
link(token) {
const href = token.href;
const text = token.text;
return `<a href="${href}" target="_blank">${text}</a>`;
},
},
};
if (token.href === "mailto") {
return `<a href="mailto:${token.text}">${token.text}</a>`;
} else {
let target = "_blank";
marked.use(extension);
if (token.text.endsWith("|target:self")) {
const index = token.text.indexOf("|target:self");
token.text = token.text.substring(0, index);
target = "_self";
}
const href = token.href;
const text = token.text;
return `<a href="${href}" target="${target}">${text}</a>`;
}
}
}
}
marked.use(markedOptions);
async function readTranslations() {
const langs = [