mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-26 19:25:47 +03:00
Fix some links have same class names from the app itself
Srsly need to sanitize the HTML one day
This commit is contained in:
parent
679fba4f66
commit
7d28744234
1 changed files with 13 additions and 2 deletions
|
@ -10,15 +10,26 @@ function enhanceContent(content, opts = {}) {
|
|||
const hasLink = /<a/i.test(enhancedContent);
|
||||
const hasCodeBlock = enhancedContent.indexOf('```') !== -1;
|
||||
|
||||
// Add target="_blank" to all links with no target="_blank"
|
||||
// E.g. `note` in `account`
|
||||
if (hasLink) {
|
||||
// Add target="_blank" to all links with no target="_blank"
|
||||
// E.g. `note` in `account`
|
||||
const noTargetBlankLinks = Array.from(
|
||||
dom.querySelectorAll('a:not([target="_blank"])'),
|
||||
);
|
||||
noTargetBlankLinks.forEach((link) => {
|
||||
link.setAttribute('target', '_blank');
|
||||
});
|
||||
|
||||
// Remove all classes except `u-url`, `mention`, `hashtag`
|
||||
const links = Array.from(dom.querySelectorAll('a[class]'));
|
||||
const whitelistClasses = ['u-url', 'mention', 'hashtag'];
|
||||
links.forEach((link) => {
|
||||
link.classList.forEach((c) => {
|
||||
if (!whitelistClasses.includes(c)) {
|
||||
link.classList.remove(c);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Add 'has-url-text' to all links that contains a url
|
||||
|
|
Loading…
Reference in a new issue