kopia lustrzana https://github.com/cheeaun/phanpy
Fix some links have same class names from the app itself
Srsly need to sanitize the HTML one daypull/228/head
rodzic
679fba4f66
commit
7d28744234
|
@ -10,15 +10,26 @@ function enhanceContent(content, opts = {}) {
|
|||
const hasLink = /<a/i.test(enhancedContent);
|
||||
const hasCodeBlock = enhancedContent.indexOf('```') !== -1;
|
||||
|
||||
if (hasLink) {
|
||||
// Add target="_blank" to all links with no target="_blank"
|
||||
// E.g. `note` in `account`
|
||||
if (hasLink) {
|
||||
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
|
||||
|
|
Ładowanie…
Reference in New Issue