disallow images in topic card markdown
This commit is contained in:
parent
a81c5a71e3
commit
5af79e405d
1 changed files with 21 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
/* global $ */
|
/* global $ */
|
||||||
|
|
||||||
import { Parser, HtmlRenderer } from 'commonmark'
|
import { Parser, HtmlRenderer, Node } from 'commonmark'
|
||||||
import { emojiIndex } from 'emoji-mart'
|
import { emojiIndex } from 'emoji-mart'
|
||||||
import { escapeRegExp } from 'lodash'
|
import { escapeRegExp } from 'lodash'
|
||||||
|
|
||||||
|
@ -135,9 +135,27 @@ const Util = {
|
||||||
},
|
},
|
||||||
mdToHTML: text => {
|
mdToHTML: text => {
|
||||||
const safeText = text || ''
|
const safeText = text || ''
|
||||||
|
const parsed = new Parser().parse(safeText)
|
||||||
|
|
||||||
|
// remove images to avoid http content in https context
|
||||||
|
const walker = parsed.walker()
|
||||||
|
let event
|
||||||
|
while (event = walker.next()) {
|
||||||
|
const node = event.node
|
||||||
|
if (node.type === 'image') {
|
||||||
|
const imageAlt = node.firstChild.literal
|
||||||
|
const imageSrc = node.destination
|
||||||
|
const textNode = new Node('text', node.sourcepos)
|
||||||
|
textNode.literal = ``
|
||||||
|
|
||||||
|
node.insertBefore(textNode)
|
||||||
|
node.unlink() // remove the image, replacing it with markdown
|
||||||
|
walker.resumeAt(textNode, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// use safe: true to filter xss
|
// use safe: true to filter xss
|
||||||
return new HtmlRenderer({ safe: true })
|
return new HtmlRenderer({ safe: true }).render(parsed)
|
||||||
.render(new Parser().parse(safeText))
|
|
||||||
},
|
},
|
||||||
logCanvasAttributes: function(canvas) {
|
logCanvasAttributes: function(canvas) {
|
||||||
const fakeMgraph = { canvas }
|
const fakeMgraph = { canvas }
|
||||||
|
|
Loading…
Add table
Reference in a new issue