Skip to content

Commit 071f7cb

Browse files
committed
rewrote the function code to MarkdownPreview.js #2644 #2662
1 parent a11b0f1 commit 071f7cb

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

browser/components/MarkdownPreview.js

Lines changed: 26 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

@@ -640,7 +665,7 @@ export default class MarkdownPreview extends React.Component {
640665
this.refs.root.contentWindow.document.body.setAttribute('data-theme', theme)
641666
if (sanitize === 'NONE') {
642667
const splitWithCodeTag = value.split('```')
643-
value = attachmentManagement.escapeHtmlCharactersInCodeTag(splitWithCodeTag)
668+
value = this.escapeHtmlCharactersInCodeTag(splitWithCodeTag)
644669
}
645670
const renderedHTML = this.markdown.render(value)
646671
attachmentManagement.migrateAttachments(value, storagePath, noteKey)

browser/main/lib/dataApi/attachmentManagement.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const fse = require('fs-extra')
77
const escapeStringRegexp = require('escape-string-regexp')
88
const sander = require('sander')
99
import i18n from 'browser/lib/i18n'
10-
import { escapeHtmlCharacters } from '../../../lib/utils'
1110

1211
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
1312
const DESTINATION_FOLDER = 'attachments'
@@ -221,31 +220,6 @@ function migrateAttachments (markdownContent, storagePath, noteKey) {
221220
}
222221
}
223222

224-
/**
225-
* @description Convert special characters between ```
226-
* @param {string[]} splitWithCodeTag Array of HTML strings separated by ```
227-
* @returns {string} HTML in which special characters between ``` have been converted
228-
*/
229-
function escapeHtmlCharactersInCodeTag (splitWithCodeTag) {
230-
for (let index = 0; index < splitWithCodeTag.length; index++) {
231-
const codeTagRequired = (splitWithCodeTag[index] !== '\`\`\`' && index < splitWithCodeTag.length - 1)
232-
if (codeTagRequired) {
233-
splitWithCodeTag.splice((index + 1), 0, '\`\`\`')
234-
}
235-
}
236-
let inCodeTag = false
237-
let result = ''
238-
for (let content of splitWithCodeTag) {
239-
if (content === '\`\`\`') {
240-
inCodeTag = !inCodeTag
241-
} else if (inCodeTag) {
242-
content = escapeHtmlCharacters(content)
243-
}
244-
result += content
245-
}
246-
return result
247-
}
248-
249223
/**
250224
* @description Fixes the URLs embedded in the generated HTML so that they again refer actual local files.
251225
* @param {String} renderedHTML HTML in that the links should be fixed
@@ -607,7 +581,6 @@ function handleAttachmentLinkPaste (storageKey, noteKey, linkText) {
607581

608582
module.exports = {
609583
copyAttachment,
610-
escapeHtmlCharactersInCodeTag,
611584
fixLocalURLS,
612585
generateAttachmentMarkdown,
613586
handleAttachmentDrop,

0 commit comments

Comments
 (0)