fix #1396: fixed hyperlinks in notes

This commit is contained in:
antelle 2020-03-14 20:32:55 +01:00
parent 649516cf32
commit 98c22a4323
2 changed files with 12 additions and 2 deletions

View File

@ -3,18 +3,27 @@ import marked from 'marked';
const whiteSpaceRegex = /<\/?p>|<br>|\r|\n/g;
class MdRenderer extends marked.Renderer {
link(href, title, text) {
return super
.link(href, title, text)
.replace('<a ', '<a target="_blank" rel="noreferrer noopener" ');
}
}
const MdToHtml = {
convert(md) {
if (!md) {
return '';
}
const html = marked(md);
const renderer = new MdRenderer();
const html = marked(md, { renderer });
const htmlWithoutLineBreaks = html.replace(whiteSpaceRegex, '');
const mdWithoutLineBreaks = md.replace(whiteSpaceRegex, '');
if (htmlWithoutLineBreaks === mdWithoutLineBreaks) {
return md;
} else {
const sanitized = dompurify.sanitize(html);
const sanitized = dompurify.sanitize(html, { ADD_ATTR: ['target'] });
return `<div class="markdown">${sanitized}</div>`;
}
}

View File

@ -4,6 +4,7 @@ Release notes
`+` #1341: auto-lock the app on screen lock on Windows
`+` #1065: PORTABLE_EXECUTABLE_DIR environment variable
`*` #1397: Segoe UI font on Windows
`-` fix #1396: fixed hyperlinks in notes
`-` fix #1323: version in the About dialog
`-` fix #734: OTP secrets with spaces
`-` fix #1208: webdav credentials corruption