Skip to content

Commit a90b930

Browse files
wooormTrott
andauthored
Fix handling of reference links with inline code
This fixes text content (“phrasing”, such as emphasis or code) inside labels (of links, images). Closes GH-24. Closes GH-25. Closes remarkjs/remark#850. Co-authored-by: Rich Trott <[email protected]>
1 parent 385a431 commit a90b930

File tree

5 files changed

+621
-8
lines changed

5 files changed

+621
-8
lines changed

dev/lib/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import {parse} from 'micromark/lib/parse.js'
8585
import {preprocess} from 'micromark/lib/preprocess.js'
8686
import {postprocess} from 'micromark/lib/postprocess.js'
8787
import {decodeNumericCharacterReference} from 'micromark-util-decode-numeric-character-reference'
88+
import {decodeString} from 'micromark-util-decode-string'
8889
import {normalizeIdentifier} from 'micromark-util-normalize-identifier'
8990
import {codes} from 'micromark-util-symbol/codes.js'
9091
import {constants} from 'micromark-util-symbol/constants.js'
@@ -866,13 +867,14 @@ function compiler(options = {}) {
866867

867868
/** @type {Handle} */
868869
function onexitlabeltext(token) {
869-
const ancestor = /** @type {(Link|Image) & {identifier: string}} */ (
870-
this.stack[this.stack.length - 2]
871-
)
870+
const ancestor =
871+
/** @type {(Link|Image) & {identifier: string, label: string}} */ (
872+
this.stack[this.stack.length - 2]
873+
)
874+
const string = this.sliceSerialize(token)
872875

873-
ancestor.identifier = normalizeIdentifier(
874-
this.sliceSerialize(token)
875-
).toLowerCase()
876+
ancestor.label = decodeString(string)
877+
ancestor.identifier = normalizeIdentifier(string).toLowerCase()
876878
}
877879

878880
/** @type {Handle} */
@@ -884,8 +886,6 @@ function compiler(options = {}) {
884886
this.stack[this.stack.length - 1]
885887
)
886888

887-
node.label = value
888-
889889
// Assume a reference.
890890
setData('inReference', true)
891891

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"mdast-util-to-string": "^3.1.0",
4747
"micromark": "^3.0.0",
4848
"micromark-util-decode-numeric-character-reference": "^1.0.0",
49+
"micromark-util-decode-string": "^1.0.0",
4950
"micromark-util-normalize-identifier": "^1.0.0",
5051
"micromark-util-symbol": "^1.0.0",
5152
"micromark-util-types": "^1.0.0",

0 commit comments

Comments
 (0)