mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
export html is escaping html characters as the preview
This commit is contained in:
@@ -23,10 +23,10 @@ import formatHTML, {
|
|||||||
CSS_FILES,
|
CSS_FILES,
|
||||||
buildStyle,
|
buildStyle,
|
||||||
getCodeThemeLink,
|
getCodeThemeLink,
|
||||||
getStyleParams
|
getStyleParams,
|
||||||
|
escapeHtmlCharactersInCodeTag
|
||||||
} from 'browser/main/lib/dataApi/formatHTML'
|
} from 'browser/main/lib/dataApi/formatHTML'
|
||||||
import formatPDF from 'browser/main/lib/dataApi/formatPDF'
|
import formatPDF from 'browser/main/lib/dataApi/formatPDF'
|
||||||
import { escapeHtmlCharacters } from 'browser/lib/utils'
|
|
||||||
import yaml from 'js-yaml'
|
import yaml from 'js-yaml'
|
||||||
import i18n from 'browser/lib/i18n'
|
import i18n from 'browser/lib/i18n'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
@@ -247,32 +247,6 @@ class MarkdownPreview extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Convert special characters between three ```
|
|
||||||
* @param {string[]} splitWithCodeTag Array of HTML strings separated by three ```
|
|
||||||
* @returns {string} HTML in which special characters between three ``` have been converted
|
|
||||||
*/
|
|
||||||
escapeHtmlCharactersInCodeTag(splitWithCodeTag) {
|
|
||||||
for (let index = 0; index < splitWithCodeTag.length; index++) {
|
|
||||||
const codeTagRequired =
|
|
||||||
splitWithCodeTag[index] !== '```' && index < splitWithCodeTag.length - 1
|
|
||||||
if (codeTagRequired) {
|
|
||||||
splitWithCodeTag.splice(index + 1, 0, '```')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let inCodeTag = false
|
|
||||||
let result = ''
|
|
||||||
for (let content of splitWithCodeTag) {
|
|
||||||
if (content === '```') {
|
|
||||||
inCodeTag = !inCodeTag
|
|
||||||
} else if (inCodeTag) {
|
|
||||||
content = escapeHtmlCharacters(content)
|
|
||||||
}
|
|
||||||
result += content
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
getScrollBarStyle() {
|
getScrollBarStyle() {
|
||||||
const { theme } = this.props
|
const { theme } = this.props
|
||||||
|
|
||||||
@@ -485,7 +459,7 @@ class MarkdownPreview extends React.Component {
|
|||||||
this.refs.root.contentWindow.document.body.setAttribute('data-theme', theme)
|
this.refs.root.contentWindow.document.body.setAttribute('data-theme', theme)
|
||||||
if (sanitize === 'NONE') {
|
if (sanitize === 'NONE') {
|
||||||
const splitWithCodeTag = value.split('```')
|
const splitWithCodeTag = value.split('```')
|
||||||
value = this.escapeHtmlCharactersInCodeTag(splitWithCodeTag)
|
value = escapeHtmlCharactersInCodeTag(splitWithCodeTag)
|
||||||
}
|
}
|
||||||
const renderedHTML = this.markdown.render(value)
|
const renderedHTML = this.markdown.render(value)
|
||||||
attachmentManagement.migrateAttachments(value, storagePath, noteKey)
|
attachmentManagement.migrateAttachments(value, storagePath, noteKey)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import consts from 'browser/lib/consts'
|
|||||||
import Markdown from 'browser/lib/markdown'
|
import Markdown from 'browser/lib/markdown'
|
||||||
import attachmentManagement from './attachmentManagement'
|
import attachmentManagement from './attachmentManagement'
|
||||||
import { version as codemirrorVersion } from 'codemirror/package.json'
|
import { version as codemirrorVersion } from 'codemirror/package.json'
|
||||||
|
import { escapeHtmlCharacters } from 'browser/lib/utils'
|
||||||
|
|
||||||
const { app } = remote
|
const { app } = remote
|
||||||
const appPath = fileUrl(
|
const appPath = fileUrl(
|
||||||
@@ -467,7 +468,13 @@ document.addEventListener('DOMContentLoaded', displaySequences);
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let body = markdown.render(note.content)
|
let body = note.content
|
||||||
|
|
||||||
|
if (sanitize === 'NONE') {
|
||||||
|
body = escapeHtmlCharactersInCodeTag(body.split('```'))
|
||||||
|
}
|
||||||
|
|
||||||
|
body = markdown.render(note.content)
|
||||||
|
|
||||||
const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(
|
const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(
|
||||||
note.content,
|
note.content,
|
||||||
@@ -761,3 +768,29 @@ body p {
|
|||||||
${allowCustomCSS ? customCSS : ''}
|
${allowCustomCSS ? customCSS : ''}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Convert special characters between three ```
|
||||||
|
* @param {string[]} splitWithCodeTag Array of HTML strings separated by three ```
|
||||||
|
* @returns {string} HTML in which special characters between three ``` have been converted
|
||||||
|
*/
|
||||||
|
export function escapeHtmlCharactersInCodeTag(splitWithCodeTag) {
|
||||||
|
for (let index = 0; index < splitWithCodeTag.length; index++) {
|
||||||
|
const codeTagRequired =
|
||||||
|
splitWithCodeTag[index] !== '```' && index < splitWithCodeTag.length - 1
|
||||||
|
if (codeTagRequired) {
|
||||||
|
splitWithCodeTag.splice(index + 1, 0, '```')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let inCodeTag = false
|
||||||
|
let result = ''
|
||||||
|
for (let content of splitWithCodeTag) {
|
||||||
|
if (content === '```') {
|
||||||
|
inCodeTag = !inCodeTag
|
||||||
|
} else if (inCodeTag) {
|
||||||
|
content = escapeHtmlCharacters(content)
|
||||||
|
}
|
||||||
|
result += content
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user