Skip to content

Instantly share code, notes, and snippets.

@lionel-rowe
Last active March 23, 2023 12:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lionel-rowe/bb384465ba4e4c81a9c8dada84167225 to your computer and use it in GitHub Desktop.
Save lionel-rowe/bb384465ba4e4c81a9c8dada84167225 to your computer and use it in GitHub Desktop.
insane options for use with marked and highlightjs
const insaneOptions = {
allowedAttributes: {
a: ['href', 'name', 'target', 'rel', 'title'],
img: ['src', 'alt', 'title'],
input: ['type', 'checked', 'disabled'],
code: ['class'],
span: ['class'],
th: ['align'],
tr: ['align']
},
allowedClasses: {
},
allowedSchemes: ['http', 'https', 'mailto'],
allowedTags: [
'a', 'article', 'b', 'blockquote', 'br', 'caption', 'code', 'del', 'details', 'div',
'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input', 'ins', 'kbd',
'label', 'li', 'main', 'ol', 'p', 'pre', 'section', 'span', 'strike', 'strong', 'sub',
'summary', 'sup', 'table', 'tbody', 'td', 'th', 'thead', 'tr', 'u', 'ul'
],
filter: node => {
[
[ 'code', 'language-' ],
[ 'span', 'hljs-' ]
].forEach(([ tag, prefix ]) => {
if (
node.tag === tag
&& typeof node.attrs.class === 'string'
&& (/\s/.test(node.attrs.class) || !node.attrs.class.startsWith(prefix))
) {
delete node.attrs.class;
}
});
return true;
},
transformText: null
};
for (let i = 1; i <= 6; i++) {
insaneOptions.allowedAttributes[`h${i}`] = ['id'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment