Skip to content

Commit

Permalink
Fix to properly parse character references
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 19, 2021
1 parent 1a84ea1 commit 559b846
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @typedef {ContainerDirective|LeafDirective|TextDirective} Directive
*/

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

/** @type {FromMarkdownHandle} */
function exitAttributeClassValue(token) {
const list = /** @type {Array.<[string, string]>} */ (
this.getData('directiveAttributes')
)
list.push(['class', decodeLight(this.sliceSerialize(token))])
list.push(['class', parseEntities(this.sliceSerialize(token))])
}

/** @type {FromMarkdownHandle} */
function exitAttributeValue(token) {
const list = /** @type {Array.<[string, string]>} */ (
this.getData('directiveAttributes')
)
list[list.length - 1][1] = decodeLight(this.sliceSerialize(token))
list[list.length - 1][1] = parseEntities(this.sliceSerialize(token))
}

/** @type {FromMarkdownHandle} */
Expand Down Expand Up @@ -372,26 +372,6 @@ function inlineDirectiveLabel(node) {
)
}

/**
* @param {string} value
* @returns {string}
*/
function decodeLight(value) {
return value.replace(
/&(#(\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi,
decodeIfPossible
)
}

/**
* @param {string} $0
* @param {string} $1
* @returns {string}
*/
function decodeIfPossible($0, $1) {
return decodeEntity($1) || $0
}

/**
* @param {Directive} node
* @returns {string}
Expand Down

0 comments on commit 559b846

Please sign in to comment.