@@ -398,6 +398,31 @@ export default class MarkdownPreview extends React.Component {
398
398
}
399
399
}
400
400
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
+
401
426
getScrollBarStyle ( ) {
402
427
const { theme } = this . props
403
428
@@ -632,11 +657,16 @@ export default class MarkdownPreview extends React.Component {
632
657
indentSize,
633
658
showCopyNotification,
634
659
storagePath,
635
- noteKey
660
+ noteKey,
661
+ sanitize
636
662
} = this . props
637
663
let { value, codeBlockTheme } = this . props
638
664
639
665
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
+ }
640
670
const renderedHTML = this . markdown . render ( value )
641
671
attachmentManagement . migrateAttachments ( value , storagePath , noteKey )
642
672
this . refs . root . contentWindow . document . body . innerHTML = attachmentManagement . fixLocalURLS (
0 commit comments