Skip to content

Commit 559b846

Browse files
committed
Fix to properly parse character references
1 parent 1a84ea1 commit 559b846

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

index.js

+4-24
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @typedef {ContainerDirective|LeafDirective|TextDirective} Directive
1515
*/
1616

17-
import {decodeEntity} from 'parse-entities/decode-entity.js'
17+
import {parseEntities} from 'parse-entities'
1818
import {stringifyEntitiesLight} from 'stringify-entities'
1919
import {visitParents} from 'unist-util-visit-parents'
2020
import {containerFlow} from 'mdast-util-to-markdown/lib/util/container-flow.js'
@@ -152,23 +152,23 @@ function exitAttributeIdValue(token) {
152152
const list = /** @type {Array.<[string, string]>} */ (
153153
this.getData('directiveAttributes')
154154
)
155-
list.push(['id', decodeLight(this.sliceSerialize(token))])
155+
list.push(['id', parseEntities(this.sliceSerialize(token))])
156156
}
157157

158158
/** @type {FromMarkdownHandle} */
159159
function exitAttributeClassValue(token) {
160160
const list = /** @type {Array.<[string, string]>} */ (
161161
this.getData('directiveAttributes')
162162
)
163-
list.push(['class', decodeLight(this.sliceSerialize(token))])
163+
list.push(['class', parseEntities(this.sliceSerialize(token))])
164164
}
165165

166166
/** @type {FromMarkdownHandle} */
167167
function exitAttributeValue(token) {
168168
const list = /** @type {Array.<[string, string]>} */ (
169169
this.getData('directiveAttributes')
170170
)
171-
list[list.length - 1][1] = decodeLight(this.sliceSerialize(token))
171+
list[list.length - 1][1] = parseEntities(this.sliceSerialize(token))
172172
}
173173

174174
/** @type {FromMarkdownHandle} */
@@ -372,26 +372,6 @@ function inlineDirectiveLabel(node) {
372372
)
373373
}
374374

375-
/**
376-
* @param {string} value
377-
* @returns {string}
378-
*/
379-
function decodeLight(value) {
380-
return value.replace(
381-
/&(#(\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi,
382-
decodeIfPossible
383-
)
384-
}
385-
386-
/**
387-
* @param {string} $0
388-
* @param {string} $1
389-
* @returns {string}
390-
*/
391-
function decodeIfPossible($0, $1) {
392-
return decodeEntity($1) || $0
393-
}
394-
395375
/**
396376
* @param {Directive} node
397377
* @returns {string}

0 commit comments

Comments
 (0)