Skip to content

Commit 0289caa

Browse files
authored
Merge pull request #2712 from roottool/fix-issue#2644-and-#2662
fix issues #2644 and #2662
2 parents 99cb6fa + 071f7cb commit 0289caa

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

browser/components/MarkdownPreview.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,31 @@ export default class MarkdownPreview extends React.Component {
398398
}
399399
}
400400

401+
/**
402+
* @description Convert special characters between three ```
403+
* @param {string[]} splitWithCodeTag Array of HTML strings separated by three ```
404+
* @returns {string} HTML in which special characters between three ``` have been converted
405+
*/
406+
escapeHtmlCharactersInCodeTag (splitWithCodeTag) {
407+
for (let index = 0; index < splitWithCodeTag.length; index++) {
408+
const codeTagRequired = (splitWithCodeTag[index] !== '\`\`\`' && index < splitWithCodeTag.length - 1)
409+
if (codeTagRequired) {
410+
splitWithCodeTag.splice((index + 1), 0, '\`\`\`')
411+
}
412+
}
413+
let inCodeTag = false
414+
let result = ''
415+
for (let content of splitWithCodeTag) {
416+
if (content === '\`\`\`') {
417+
inCodeTag = !inCodeTag
418+
} else if (inCodeTag) {
419+
content = escapeHtmlCharacters(content)
420+
}
421+
result += content
422+
}
423+
return result
424+
}
425+
401426
getScrollBarStyle () {
402427
const { theme } = this.props
403428

@@ -632,11 +657,16 @@ export default class MarkdownPreview extends React.Component {
632657
indentSize,
633658
showCopyNotification,
634659
storagePath,
635-
noteKey
660+
noteKey,
661+
sanitize
636662
} = this.props
637663
let { value, codeBlockTheme } = this.props
638664

639665
this.refs.root.contentWindow.document.body.setAttribute('data-theme', theme)
666+
if (sanitize === 'NONE') {
667+
const splitWithCodeTag = value.split('```')
668+
value = this.escapeHtmlCharactersInCodeTag(splitWithCodeTag)
669+
}
640670
const renderedHTML = this.markdown.render(value)
641671
attachmentManagement.migrateAttachments(value, storagePath, noteKey)
642672
this.refs.root.contentWindow.document.body.innerHTML = attachmentManagement.fixLocalURLS(

0 commit comments

Comments
 (0)