Refactor markdown/sanitize html code

This commit is contained in:
Chocobozzz
2020-11-17 14:34:09 +01:00
parent 9afb5c10e5
commit 9ff36c2d70
7 changed files with 67 additions and 70 deletions
+4
View File
@@ -1,3 +1,7 @@
export * from './abuse'
export * from './i18n'
export * from './logs'
export * from './miscs'
export * from './plugins'
export * from './renderer'
export * from './users'
+21
View File
@@ -0,0 +1,21 @@
export const SANITIZE_OPTIONS = {
allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ],
allowedSchemes: [ 'http', 'https' ],
allowedAttributes: {
a: [ 'href', 'class', 'target', 'rel' ]
},
transformTags: {
a: (tagName, attribs) => {
let rel = 'noopener noreferrer'
if (attribs.rel === 'me') rel += ' me'
return {
tagName,
attribs: Object.assign(attribs, {
target: '_blank',
rel
})
}
}
}
}
+2
View File
@@ -0,0 +1,2 @@
export * from './markdown'
export * from './html'
+23
View File
@@ -0,0 +1,23 @@
export const TEXT_RULES = [
'linkify',
'autolink',
'emphasis',
'link',
'newline',
'list'
]
export const TEXT_WITH_HTML_RULES = TEXT_RULES.concat([
'html_inline',
'html_block'
])
export const ENHANCED_RULES = TEXT_RULES.concat([ 'image' ])
export const ENHANCED_WITH_HTML_RULES = TEXT_WITH_HTML_RULES.concat([ 'image' ])
export const COMPLETE_RULES = ENHANCED_WITH_HTML_RULES.concat([
'block',
'inline',
'heading',
'paragraph'
])