diff --git a/packages/remark-parse/lib/tokenize/definition.js b/packages/remark-parse/lib/tokenize/definition.js index 1cce274cf..3f9e51a64 100644 --- a/packages/remark-parse/lib/tokenize/definition.js +++ b/packages/remark-parse/lib/tokenize/definition.js @@ -255,6 +255,7 @@ function definition(eat, value, silent) { return eat(subvalue)({ type: 'definition', identifier: normalize(identifier), + label: identifier, title: title || null, url: url }); diff --git a/packages/remark-parse/lib/tokenize/footnote-definition.js b/packages/remark-parse/lib/tokenize/footnote-definition.js index f48ff9bb7..4174a129f 100644 --- a/packages/remark-parse/lib/tokenize/footnote-definition.js +++ b/packages/remark-parse/lib/tokenize/footnote-definition.js @@ -93,7 +93,7 @@ function footnoteDefinition(eat, value, silent) { return true; } - identifier = normalize(queue); + identifier = queue; subvalue += queue + C_BRACKET_CLOSE + C_COLON; index = subvalue.length; @@ -179,7 +179,8 @@ function footnoteDefinition(eat, value, silent) { return add({ type: 'footnoteDefinition', - identifier: identifier, + identifier: normalize(identifier), + label: identifier, children: content }); } diff --git a/packages/remark-parse/lib/tokenize/reference.js b/packages/remark-parse/lib/tokenize/reference.js index 0db5eb3c6..27947dbe4 100644 --- a/packages/remark-parse/lib/tokenize/reference.js +++ b/packages/remark-parse/lib/tokenize/reference.js @@ -193,7 +193,8 @@ function reference(eat, value, silent) { node = { type: type + 'Reference', - identifier: normalize(identifier) + identifier: normalize(identifier), + label: identifier }; if (type === T_LINK || type === T_IMAGE) { diff --git a/packages/remark-stringify/lib/util/label.js b/packages/remark-stringify/lib/util/label.js index bf6f5876b..e4fe8460e 100644 --- a/packages/remark-stringify/lib/util/label.js +++ b/packages/remark-stringify/lib/util/label.js @@ -10,7 +10,10 @@ module.exports = label; * changes. */ function label(node) { var type = node.referenceType; - var value = type === 'full' ? node.identifier : ''; - return type === 'shortcut' ? value : '[' + value + ']'; + if (type === 'shortcut') { + return ''; + } + + return type === 'collapsed' ? '[]' : '[' + (node.label || node.identifier) + ']'; } diff --git a/packages/remark-stringify/lib/visitors/definition.js b/packages/remark-stringify/lib/visitors/definition.js index 0fc855560..d6abb2ab4 100644 --- a/packages/remark-stringify/lib/visitors/definition.js +++ b/packages/remark-stringify/lib/visitors/definition.js @@ -19,5 +19,5 @@ function definition(node) { content += ' ' + title(node.title); } - return '[' + node.identifier + ']: ' + content; + return '[' + (node.label || node.identifier) + ']: ' + content; } diff --git a/packages/remark-stringify/lib/visitors/footnote-definition.js b/packages/remark-stringify/lib/visitors/footnote-definition.js index 158f98ed9..a2e5daad8 100644 --- a/packages/remark-stringify/lib/visitors/footnote-definition.js +++ b/packages/remark-stringify/lib/visitors/footnote-definition.js @@ -5,8 +5,7 @@ var repeat = require('repeat-string'); module.exports = footnoteDefinition; function footnoteDefinition(node) { - var id = node.identifier.toLowerCase(); var content = this.all(node).join('\n\n' + repeat(' ', 4)); - return '[^' + id + ']: ' + content; + return '[^' + (node.label || node.identifier) + ']: ' + content; } diff --git a/packages/remark-stringify/lib/visitors/footnote-reference.js b/packages/remark-stringify/lib/visitors/footnote-reference.js index c6dccc4cd..b1273b447 100644 --- a/packages/remark-stringify/lib/visitors/footnote-reference.js +++ b/packages/remark-stringify/lib/visitors/footnote-reference.js @@ -3,5 +3,5 @@ module.exports = footnoteReference; function footnoteReference(node) { - return '[^' + node.identifier + ']'; + return '[^' + (node.label || node.identifier) + ']'; } diff --git a/packages/remark-stringify/lib/visitors/link-reference.js b/packages/remark-stringify/lib/visitors/link-reference.js index a8e52a4d4..b8b7cc9d3 100644 --- a/packages/remark-stringify/lib/visitors/link-reference.js +++ b/packages/remark-stringify/lib/visitors/link-reference.js @@ -14,7 +14,7 @@ function linkReference(node) { exit(); if (type === 'shortcut' || type === 'collapsed') { - value = copy(value, node.identifier); + value = copy(value, node.label || node.identifier); } return '[' + value + ']' + label(node); diff --git a/test/fixtures/input/footnote-proto.nooutput.text b/test/fixtures/input/footnote-proto.text similarity index 100% rename from test/fixtures/input/footnote-proto.nooutput.text rename to test/fixtures/input/footnote-proto.text diff --git a/test/fixtures/tree/amps-and-angles-encoding.json b/test/fixtures/tree/amps-and-angles-encoding.json index 98ba2e4e4..97fd4b776 100644 --- a/test/fixtures/tree/amps-and-angles-encoding.json +++ b/test/fixtures/tree/amps-and-angles-encoding.json @@ -233,6 +233,7 @@ { "type": "linkReference", "identifier": "1", + "label": "1", "referenceType": "full", "children": [ { @@ -322,6 +323,7 @@ { "type": "linkReference", "identifier": "2", + "label": "2", "referenceType": "full", "children": [ { @@ -569,6 +571,7 @@ { "type": "definition", "identifier": "1", + "label": "1", "title": null, "url": "http://example.com/?foo=1&bar=2", "position": { @@ -588,6 +591,7 @@ { "type": "definition", "identifier": "2", + "label": "2", "title": "AT&T", "url": "http://att.com/", "position": { diff --git a/test/fixtures/tree/auto-link-url.nogfm.json b/test/fixtures/tree/auto-link-url.nogfm.json index 6543edaa4..63cf3bc77 100644 --- a/test/fixtures/tree/auto-link-url.nogfm.json +++ b/test/fixtures/tree/auto-link-url.nogfm.json @@ -59,6 +59,7 @@ { "type": "linkReference", "identifier": "world", + "label": "world", "referenceType": "shortcut", "children": [ { diff --git a/test/fixtures/tree/case-insensitive-refs.json b/test/fixtures/tree/case-insensitive-refs.json index e9a5b9722..3142ea6a1 100644 --- a/test/fixtures/tree/case-insensitive-refs.json +++ b/test/fixtures/tree/case-insensitive-refs.json @@ -7,6 +7,7 @@ { "type": "linkReference", "identifier": "hi", + "label": "hi", "referenceType": "shortcut", "children": [ { @@ -59,6 +60,7 @@ { "type": "definition", "identifier": "hi", + "label": "HI", "title": null, "url": "/url", "position": { diff --git a/test/fixtures/tree/def-blocks.commonmark.json b/test/fixtures/tree/def-blocks.commonmark.json index 07649e888..bad8410a3 100644 --- a/test/fixtures/tree/def-blocks.commonmark.json +++ b/test/fixtures/tree/def-blocks.commonmark.json @@ -29,6 +29,7 @@ { "type": "linkReference", "identifier": "1", + "label": "1", "referenceType": "shortcut", "children": [ { @@ -158,6 +159,7 @@ { "type": "linkReference", "identifier": "2", + "label": "2", "referenceType": "shortcut", "children": [ { @@ -315,6 +317,7 @@ { "type": "linkReference", "identifier": "3", + "label": "3", "referenceType": "shortcut", "children": [ { @@ -449,6 +452,7 @@ { "type": "linkReference", "identifier": "4", + "label": "4", "referenceType": "shortcut", "children": [ { @@ -580,6 +584,7 @@ { "type": "linkReference", "identifier": "1", + "label": "1", "referenceType": "shortcut", "children": [ { diff --git a/test/fixtures/tree/def-blocks.json b/test/fixtures/tree/def-blocks.json index aa75ea77a..c0254c7b9 100644 --- a/test/fixtures/tree/def-blocks.json +++ b/test/fixtures/tree/def-blocks.json @@ -45,6 +45,7 @@ { "type": "linkReference", "identifier": "1", + "label": "1", "referenceType": "shortcut", "children": [ { @@ -200,6 +201,7 @@ { "type": "definition", "identifier": "2", + "label": "2", "title": null, "url": "hello", "position": { @@ -288,6 +290,7 @@ { "type": "linkReference", "identifier": "3", + "label": "3", "referenceType": "shortcut", "children": [ { @@ -465,6 +468,7 @@ { "type": "definition", "identifier": "4", + "label": "4", "title": null, "url": "hello", "position": { @@ -543,6 +547,7 @@ { "type": "definition", "identifier": "1", + "label": "1", "title": null, "url": "foo", "position": { diff --git a/test/fixtures/tree/definition-newline.commonmark.json b/test/fixtures/tree/definition-newline.commonmark.json index d9a6a4488..e82ee82b6 100644 --- a/test/fixtures/tree/definition-newline.commonmark.json +++ b/test/fixtures/tree/definition-newline.commonmark.json @@ -7,6 +7,7 @@ { "type": "linkReference", "identifier": "baz", + "label": "baz", "referenceType": "shortcut", "children": [ { @@ -83,6 +84,7 @@ { "type": "linkReference", "identifier": "foo", + "label": "foo", "referenceType": "shortcut", "children": [ { @@ -159,6 +161,7 @@ { "type": "linkReference", "identifier": "bar", + "label": "bar", "referenceType": "shortcut", "children": [ { @@ -216,6 +219,7 @@ { "type": "linkReference", "identifier": "baz", + "label": "baz", "referenceType": "shortcut", "children": [ { @@ -291,6 +295,7 @@ { "type": "definition", "identifier": "baz", + "label": "baz", "title": "foo\nbar", "url": "/url", "position": { @@ -312,6 +317,7 @@ { "type": "definition", "identifier": "baz", + "label": "baz", "title": "foo\nbar", "url": "/url", "position": { @@ -336,6 +342,7 @@ { "type": "linkReference", "identifier": "baz", + "label": "baz", "referenceType": "shortcut", "children": [ { diff --git a/test/fixtures/tree/definition-newline.json b/test/fixtures/tree/definition-newline.json index f2e198dbc..6d43b85eb 100644 --- a/test/fixtures/tree/definition-newline.json +++ b/test/fixtures/tree/definition-newline.json @@ -7,6 +7,7 @@ { "type": "linkReference", "identifier": "baz", + "label": "baz", "referenceType": "shortcut", "children": [ { @@ -83,6 +84,7 @@ { "type": "linkReference", "identifier": "foo", + "label": "foo", "referenceType": "shortcut", "children": [ { @@ -159,6 +161,7 @@ { "type": "linkReference", "identifier": "bar", + "label": "bar", "referenceType": "shortcut", "children": [ { @@ -232,6 +235,7 @@ { "type": "definition", "identifier": "baz", + "label": "baz", "title": "foo\nbar", "url": "/url", "position": { @@ -253,6 +257,7 @@ { "type": "definition", "identifier": "baz", + "label": "baz", "title": "foo\nbar", "url": "/url", "position": { @@ -274,6 +279,7 @@ { "type": "definition", "identifier": "baz", + "label": "baz", "title": "foo\nbar", "url": "/url", "position": { @@ -298,6 +304,7 @@ { "type": "linkReference", "identifier": "baz", + "label": "baz", "referenceType": "shortcut", "children": [ { diff --git a/test/fixtures/tree/definition-unclosed-attribute.json b/test/fixtures/tree/definition-unclosed-attribute.json index 4bb12e91d..e36b83dec 100644 --- a/test/fixtures/tree/definition-unclosed-attribute.json +++ b/test/fixtures/tree/definition-unclosed-attribute.json @@ -7,6 +7,7 @@ { "type": "linkReference", "identifier": "baz", + "label": "baz", "referenceType": "shortcut", "children": [ { @@ -79,6 +80,7 @@ { "type": "linkReference", "identifier": "foo", + "label": "foo", "referenceType": "shortcut", "children": [ { @@ -151,6 +153,7 @@ { "type": "linkReference", "identifier": "bar", + "label": "bar", "referenceType": "shortcut", "children": [ { @@ -223,6 +226,7 @@ { "type": "linkReference", "identifier": "baz", + "label": "baz", "referenceType": "shortcut", "children": [ { @@ -295,6 +299,7 @@ { "type": "linkReference", "identifier": "foo", + "label": "foo", "referenceType": "shortcut", "children": [ { @@ -367,6 +372,7 @@ { "type": "linkReference", "identifier": "bar", + "label": "bar", "referenceType": "shortcut", "children": [ { @@ -439,6 +445,7 @@ { "type": "linkReference", "identifier": "baz", + "label": "baz", "referenceType": "shortcut", "children": [ { @@ -545,6 +552,7 @@ { "type": "linkReference", "identifier": "foo", + "label": "foo", "referenceType": "shortcut", "children": [ { @@ -651,6 +659,7 @@ { "type": "linkReference", "identifier": "bar", + "label": "bar", "referenceType": "shortcut", "children": [ { diff --git a/test/fixtures/tree/definition-unclosed.commonmark.json b/test/fixtures/tree/definition-unclosed.commonmark.json index 490209d26..6a4815c0f 100644 --- a/test/fixtures/tree/definition-unclosed.commonmark.json +++ b/test/fixtures/tree/definition-unclosed.commonmark.json @@ -7,6 +7,7 @@ { "type": "linkReference", "identifier": "foo", + "label": "foo", "referenceType": "shortcut", "children": [ { @@ -79,6 +80,7 @@ { "type": "linkReference", "identifier": "bar", + "label": "bar", "referenceType": "shortcut", "children": [ { @@ -151,6 +153,7 @@ { "type": "linkReference", "identifier": "foo", + "label": "foo", "referenceType": "shortcut", "children": [ { diff --git a/test/fixtures/tree/definition-unclosed.json b/test/fixtures/tree/definition-unclosed.json index c6df27147..5d2c0ccaf 100644 --- a/test/fixtures/tree/definition-unclosed.json +++ b/test/fixtures/tree/definition-unclosed.json @@ -7,6 +7,7 @@ { "type": "linkReference", "identifier": "foo", + "label": "foo", "referenceType": "shortcut", "children": [ { @@ -76,6 +77,7 @@ { "type": "definition", "identifier": "bar", + "label": "bar", "title": null, "url": "