aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/core-utils/index.ts4
-rw-r--r--shared/core-utils/renderer/html.ts21
-rw-r--r--shared/core-utils/renderer/index.ts2
-rw-r--r--shared/core-utils/renderer/markdown.ts23
4 files changed, 50 insertions, 0 deletions
diff --git a/shared/core-utils/index.ts b/shared/core-utils/index.ts
index 54e233522..42d7cab1d 100644
--- a/shared/core-utils/index.ts
+++ b/shared/core-utils/index.ts
@@ -1,3 +1,7 @@
1export * from './abuse'
2export * from './i18n'
1export * from './logs' 3export * from './logs'
2export * from './miscs' 4export * from './miscs'
3export * from './plugins' 5export * from './plugins'
6export * from './renderer'
7export * from './users'
diff --git a/shared/core-utils/renderer/html.ts b/shared/core-utils/renderer/html.ts
new file mode 100644
index 000000000..37ae5147c
--- /dev/null
+++ b/shared/core-utils/renderer/html.ts
@@ -0,0 +1,21 @@
1export const SANITIZE_OPTIONS = {
2 allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ],
3 allowedSchemes: [ 'http', 'https' ],
4 allowedAttributes: {
5 a: [ 'href', 'class', 'target', 'rel' ]
6 },
7 transformTags: {
8 a: (tagName, attribs) => {
9 let rel = 'noopener noreferrer'
10 if (attribs.rel === 'me') rel += ' me'
11
12 return {
13 tagName,
14 attribs: Object.assign(attribs, {
15 target: '_blank',
16 rel
17 })
18 }
19 }
20 }
21}
diff --git a/shared/core-utils/renderer/index.ts b/shared/core-utils/renderer/index.ts
new file mode 100644
index 000000000..0ad29d782
--- /dev/null
+++ b/shared/core-utils/renderer/index.ts
@@ -0,0 +1,2 @@
1export * from './markdown'
2export * from './html'
diff --git a/shared/core-utils/renderer/markdown.ts b/shared/core-utils/renderer/markdown.ts
new file mode 100644
index 000000000..dff746d87
--- /dev/null
+++ b/shared/core-utils/renderer/markdown.ts
@@ -0,0 +1,23 @@
1export const TEXT_RULES = [
2 'linkify',
3 'autolink',
4 'emphasis',
5 'link',
6 'newline',
7 'list'
8]
9
10export const TEXT_WITH_HTML_RULES = TEXT_RULES.concat([
11 'html_inline',
12 'html_block'
13])
14
15export const ENHANCED_RULES = TEXT_RULES.concat([ 'image' ])
16export const ENHANCED_WITH_HTML_RULES = TEXT_WITH_HTML_RULES.concat([ 'image' ])
17
18export const COMPLETE_RULES = ENHANCED_WITH_HTML_RULES.concat([
19 'block',
20 'inline',
21 'heading',
22 'paragraph'
23])