Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/handle/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

import {stringifyEntities} from 'stringify-entities'

const htmlCommentRegex = /^>|^->|<!--|-->|--!>|<!-$/g

// Declare arrays as variables so it can be cached by `stringifyEntities`
const bogusCommentEntitySubset = ['>']
const commentEntitySubset = ['<', '>']

/**
* Serialize a comment.
*
Expand All @@ -27,10 +33,12 @@ export function comment(node, _1, _2, state) {
? '<?' +
stringifyEntities(
node.value,
Object.assign({}, state.settings.characterReferences, {subset: ['>']})
Object.assign({}, state.settings.characterReferences, {
subset: bogusCommentEntitySubset
})
) +
'>'
: '<!--' + node.value.replace(/^>|^->|<!--|-->|--!>|<!-$/g, encode) + '-->'
: '<!--' + node.value.replace(htmlCommentRegex, encode) + '-->'

/**
* @param {string} $0
Expand All @@ -39,7 +47,7 @@ export function comment(node, _1, _2, state) {
return stringifyEntities(
$0,
Object.assign({}, state.settings.characterReferences, {
subset: ['<', '>']
subset: commentEntitySubset
})
)
}
Expand Down
5 changes: 4 additions & 1 deletion lib/handle/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import {stringifyEntities} from 'stringify-entities'

// Declare array as variable so it can be cached by `stringifyEntities`
const textEntitySubset = ['<', '&']

/**
* Serialize a text node.
*
Expand All @@ -32,7 +35,7 @@ export function text(node, _, parent, state) {
: stringifyEntities(
node.value,
Object.assign({}, state.settings.characterReferences, {
subset: ['<', '&']
subset: textEntitySubset
})
)
}