Skip to content

Commit 8335598

Browse files
committed
fix: escap error in language input
1 parent 6fd3608 commit 8335598

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/main/menus/view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let viewMenu = {
7878
}]
7979
}
8080

81-
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'development') {
81+
if (process.env.NODE_ENV !== 'production' || process.env.NODE_ENV === 'development') {
8282
// add devtool when development
8383
viewMenu.submenu.push({
8484
label: 'Toggle Developer Tools',

src/muya/lib/parser/render/renderBlock/renderLeafBlock.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ const MARKER_HASK = {
1313
"'": `%${getLongUniqueId()}%`
1414
}
1515

16-
const getHighlightHtml = (text, highlights) => {
16+
const getHighlightHtml = (text, highlights, escape = false) => {
1717
let code = ''
1818
let pos = 0
1919
for (const highlight of highlights) {
2020
const { start, end, active } = highlight
2121
code += text.substring(pos, start)
2222
const className = active ? 'ag-highlight' : 'ag-selection'
23-
code += `${MARKER_HASK['<']}span class=${MARKER_HASK['"']}${className}${MARKER_HASK['"']}${MARKER_HASK['>']}${text.substring(start, end)}${MARKER_HASK['<']}/span${MARKER_HASK['>']}`
23+
code += escape
24+
? `${MARKER_HASK['<']}span class=${MARKER_HASK['"']}${className}${MARKER_HASK['"']}${MARKER_HASK['>']}${text.substring(start, end)}${MARKER_HASK['<']}/span${MARKER_HASK['>']}`
25+
: `<span class="${className}">${text.substring(start, end)}</span>`
2426
pos = end
2527
}
2628
if (pos !== text.length) {
@@ -142,7 +144,7 @@ export default function renderLeafBlock (block, cursor, activeBlocks, matches, u
142144
}
143145
children = ''
144146
} else if (type === 'span' && functionType === 'codeLine') {
145-
const code = escapeHtml(getHighlightHtml(text, highlights))
147+
const code = escapeHtml(getHighlightHtml(text, highlights, true))
146148
.replace(new RegExp(MARKER_HASK['<'], 'g'), '<')
147149
.replace(new RegExp(MARKER_HASK['>'], 'g'), '>')
148150
.replace(new RegExp(MARKER_HASK['"'], 'g'), '"')

0 commit comments

Comments
 (0)