@@ -7,6 +7,7 @@ const fse = require('fs-extra')
7
7
const escapeStringRegexp = require ( 'escape-string-regexp' )
8
8
const sander = require ( 'sander' )
9
9
import i18n from 'browser/lib/i18n'
10
+ import { escapeHtmlCharacters } from '../../../lib/utils'
10
11
11
12
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
12
13
const DESTINATION_FOLDER = 'attachments'
@@ -220,6 +221,31 @@ function migrateAttachments (markdownContent, storagePath, noteKey) {
220
221
}
221
222
}
222
223
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
+
223
249
/**
224
250
* @description Fixes the URLs embedded in the generated HTML so that they again refer actual local files.
225
251
* @param {String } renderedHTML HTML in that the links should be fixed
@@ -574,6 +600,7 @@ function handleAttachmentLinkPaste (storageKey, noteKey, linkText) {
574
600
module . exports = {
575
601
copyAttachment,
576
602
fixLocalURLS,
603
+ escapeHtmlCharactersInCodeTag,
577
604
generateAttachmentMarkdown,
578
605
handleAttachmentDrop,
579
606
handlePastImageEvent,
0 commit comments