test('escapeHtmlCharacters should NOT skip code block if that option is NOT enabled', t => {
  const input = `    <no escape>
<escapeMe>`
  const expected = `    &lt;no escape&gt;
&lt;escapeMe&gt;`
  const actual = escapeHtmlCharacters(input)
  t.is(actual, expected)
})
test('escapeHtmlCharacters should skip code block if that option is enabled', t => {
  const input = `    <no escape>
<escapeMe>`
  const expected = `    <no escape>
&lt;escapeMe&gt;`
  const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
  t.is(actual, expected)
})
Example #3
0
    this.exportAsDocument('html', (noteContent, exportTasks) => {
      const {fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme, allowCustomCSS, customCSS} = this.getStyleParams()

      const inlineStyles = buildStyle(fontFamily, fontSize, codeBlockFontFamily, lineNumber, scrollPastEnd, theme, allowCustomCSS, customCSS)
      let body = this.markdown.render(escapeHtmlCharacters(noteContent))

      const files = [this.GetCodeThemeLink(codeBlockTheme), ...CSS_FILES]
      const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(noteContent, this.props.storagePath)

      files.forEach((file) => {
        file = file.replace('file://', '')
        exportTasks.push({
          src: file,
          dst: 'css'
        })
      })
      attachmentsAbsolutePaths.forEach((attachment) => {
        exportTasks.push({
          src: attachment,
          dst: attachmentManagement.DESTINATION_FOLDER
        })
      })
      body = attachmentManagement.removeStorageAndNoteReferences(body, this.props.noteKey)

      let styles = ''
      files.forEach((file) => {
        styles += `<link rel="stylesheet" href="css/${path.basename(file)}">`
      })

      return `<html>
                 <head>
                   <meta charset="UTF-8">
                   <meta name = "viewport" content = "width = device-width, initial-scale = 1, maximum-scale = 1">
                   <style id="style">${inlineStyles}</style>
                   ${styles}
                 </head>
                 <body>${body}</body>
              </html>`
    })
test('escapeHtmlCharacters should skip char if in code block', t => {
  const input = `
\`\`\`
<dontescapeme>
\`\`\`
das<das>dasd
dasdasdasd
\`\`\`
<dontescapeme>
\`\`\`
`
  const expected = `
\`\`\`
<dontescapeme>
\`\`\`
das&lt;das&gt;dasd
dasdasdasd
\`\`\`
<dontescapeme>
\`\`\`
`
  const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
  t.is(actual, expected)
})
test('escapeHtmlCharacters should return the correct result', t => {
  const input = '& < > " \''
  const expected = '&amp; &lt; &gt; &quot; &#39;'
  const actual = escapeHtmlCharacters(input)
  t.is(actual, expected)
})
test("escapeHtmlCharacters should NOT escape & character if it's a part of an escaped character", t => {
  const input = 'Do not escape &amp; or &quot; but do escape &'
  const expected = 'Do not escape &amp; or &quot; but do escape &amp;'
  const actual = escapeHtmlCharacters(input)
  t.is(actual, expected)
})
test('escapeHtmlCharacters should return the original string if nothing needed to escape', t => {
  const input = 'Nothing to be escaped'
  const expected = 'Nothing to be escaped'
  const actual = escapeHtmlCharacters(input)
  t.is(actual, expected)
})
test('escapeHtmlCharacters should NOT skip character not in code block but start with 4 spaces', t => {
  const input = '4 spaces    &'
  const expected = '4 spaces    &amp;'
  const actual = escapeHtmlCharacters(input, { detectCodeBlock: true })
  t.is(actual, expected)
})