From c53a2be96a836212234b4bec473a55d3e8cf8fa1 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 18 Sep 2021 18:30:26 -0700 Subject: [PATCH] Fix handling of reference links with inline code This fixes the AST so that certain kinds of reference links are not broken when converted back to markdown. Fixes: https://github.com/remarkjs/remark/issues/850 --- dev/lib/index.js | 2 +- test/index.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/dev/lib/index.js b/dev/lib/index.js index 0737087..52f5049 100644 --- a/dev/lib/index.js +++ b/dev/lib/index.js @@ -884,7 +884,7 @@ function compiler(options = {}) { this.stack[this.stack.length - 1] ) - node.label = value + node.label = node.identifier // Assume a reference. setData('inReference', true) diff --git a/test/index.js b/test/index.js index ec3a8ca..fdf1a9a 100644 --- a/test/index.js +++ b/test/index.js @@ -866,6 +866,40 @@ test('mdast-util-from-markdown', (t) => { 'should parse a link (collapsed reference)' ) + t.deepEqual( + fromMarkdown('[`a`][]\n\n[`a`]: b').children[0], + { + type: 'paragraph', + children: [ + { + type: 'linkReference', + children: [ + { + type: 'inlineCode', + value: 'a', + position: { + start: {line: 1, column: 2, offset: 1}, + end: {line: 1, column: 5, offset: 4} + } + } + ], + position: { + start: {line: 1, column: 1, offset: 0}, + end: {line: 1, column: 8, offset: 7} + }, + identifier: '`a`', + label: '`a`', + referenceType: 'collapsed' + } + ], + position: { + start: {line: 1, column: 1, offset: 0}, + end: {line: 1, column: 8, offset: 7} + } + }, + 'should parse a link (collapsed reference) with inline code in the label' + ) + t.deepEqual( fromMarkdown('[a][b]\n\n[b]: c').children[0], {