Skip to content

Commit

Permalink
Fix handling of reference links with inline code
Browse files Browse the repository at this point in the history
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 <rtrott@gmail.com>
  • Loading branch information
wooorm and Trott committed Sep 19, 2021
1 parent 385a431 commit a90b930
Show file tree
Hide file tree
Showing 5 changed files with 621 additions and 8 deletions.
16 changes: 8 additions & 8 deletions dev/lib/index.js
Expand Up @@ -85,6 +85,7 @@ import {parse} from 'micromark/lib/parse.js'
import {preprocess} from 'micromark/lib/preprocess.js'
import {postprocess} from 'micromark/lib/postprocess.js'
import {decodeNumericCharacterReference} from 'micromark-util-decode-numeric-character-reference'
import {decodeString} from 'micromark-util-decode-string'
import {normalizeIdentifier} from 'micromark-util-normalize-identifier'
import {codes} from 'micromark-util-symbol/codes.js'
import {constants} from 'micromark-util-symbol/constants.js'
Expand Down Expand Up @@ -866,13 +867,14 @@ function compiler(options = {}) {

/** @type {Handle} */
function onexitlabeltext(token) {
const ancestor = /** @type {(Link|Image) & {identifier: string}} */ (
this.stack[this.stack.length - 2]
)
const ancestor =
/** @type {(Link|Image) & {identifier: string, label: string}} */ (
this.stack[this.stack.length - 2]
)
const string = this.sliceSerialize(token)

ancestor.identifier = normalizeIdentifier(
this.sliceSerialize(token)
).toLowerCase()
ancestor.label = decodeString(string)
ancestor.identifier = normalizeIdentifier(string).toLowerCase()
}

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

node.label = value

// Assume a reference.
setData('inReference', true)

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -46,6 +46,7 @@
"mdast-util-to-string": "^3.1.0",
"micromark": "^3.0.0",
"micromark-util-decode-numeric-character-reference": "^1.0.0",
"micromark-util-decode-string": "^1.0.0",
"micromark-util-normalize-identifier": "^1.0.0",
"micromark-util-symbol": "^1.0.0",
"micromark-util-types": "^1.0.0",
Expand Down

0 comments on commit a90b930

Please sign in to comment.