Skip to content

Commit 3325c33

Browse files
wooormrubys
andauthored
remark: Add support for label to associations
* remark-parse: add label to definition, footnote definition, link reference, image reference, footnote reference * remark-stringify: use full reference if no type is set Related to syntax-tree/mdast#23. Related to syntax-tree/mdast-util-to-hast#22. Supersedes GH-346. Closes GH-363. Reviewed-by: Christian Murphy <[email protected]> Co-authored-by: Sam Ruby <[email protected]>
1 parent fe241aa commit 3325c33

File tree

173 files changed

+1142
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+1142
-10
lines changed

packages/remark-parse/lib/tokenize/definition.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ function definition(eat, value, silent) {
255255
return eat(subvalue)({
256256
type: 'definition',
257257
identifier: normalize(identifier),
258+
label: identifier,
258259
title: title || null,
259260
url: url
260261
});

packages/remark-parse/lib/tokenize/footnote-definition.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function footnoteDefinition(eat, value, silent) {
9393
return true;
9494
}
9595

96-
identifier = normalize(queue);
96+
identifier = queue;
9797
subvalue += queue + C_BRACKET_CLOSE + C_COLON;
9898
index = subvalue.length;
9999

@@ -179,7 +179,8 @@ function footnoteDefinition(eat, value, silent) {
179179

180180
return add({
181181
type: 'footnoteDefinition',
182-
identifier: identifier,
182+
identifier: normalize(identifier),
183+
label: identifier,
183184
children: content
184185
});
185186
}

packages/remark-parse/lib/tokenize/reference.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ function reference(eat, value, silent) {
193193

194194
node = {
195195
type: type + 'Reference',
196-
identifier: normalize(identifier)
196+
identifier: normalize(identifier),
197+
label: identifier
197198
};
198199

199200
if (type === T_LINK || type === T_IMAGE) {

packages/remark-stringify/lib/util/label.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ module.exports = label;
1010
* changes. */
1111
function label(node) {
1212
var type = node.referenceType;
13-
var value = type === 'full' ? node.identifier : '';
1413

15-
return type === 'shortcut' ? value : '[' + value + ']';
14+
if (type === 'shortcut') {
15+
return '';
16+
}
17+
18+
return type === 'collapsed' ? '[]' : '[' + (node.label || node.identifier) + ']';
1619
}

packages/remark-stringify/lib/visitors/definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ function definition(node) {
1919
content += ' ' + title(node.title);
2020
}
2121

22-
return '[' + node.identifier + ']: ' + content;
22+
return '[' + (node.label || node.identifier) + ']: ' + content;
2323
}

packages/remark-stringify/lib/visitors/footnote-definition.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ var repeat = require('repeat-string');
55
module.exports = footnoteDefinition;
66

77
function footnoteDefinition(node) {
8-
var id = node.identifier.toLowerCase();
98
var content = this.all(node).join('\n\n' + repeat(' ', 4));
109

11-
return '[^' + id + ']: ' + content;
10+
return '[^' + (node.label || node.identifier) + ']: ' + content;
1211
}

packages/remark-stringify/lib/visitors/footnote-reference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
module.exports = footnoteReference;
44

55
function footnoteReference(node) {
6-
return '[^' + node.identifier + ']';
6+
return '[^' + (node.label || node.identifier) + ']';
77
}

packages/remark-stringify/lib/visitors/link-reference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function linkReference(node) {
1414
exit();
1515

1616
if (type === 'shortcut' || type === 'collapsed') {
17-
value = copy(value, node.identifier);
17+
value = copy(value, node.label || node.identifier);
1818
}
1919

2020
return '[' + value + ']' + label(node);

test/fixtures/tree/amps-and-angles-encoding.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
{
234234
"type": "linkReference",
235235
"identifier": "1",
236+
"label": "1",
236237
"referenceType": "full",
237238
"children": [
238239
{
@@ -322,6 +323,7 @@
322323
{
323324
"type": "linkReference",
324325
"identifier": "2",
326+
"label": "2",
325327
"referenceType": "full",
326328
"children": [
327329
{
@@ -569,6 +571,7 @@
569571
{
570572
"type": "definition",
571573
"identifier": "1",
574+
"label": "1",
572575
"title": null,
573576
"url": "http://example.com/?foo=1&bar=2",
574577
"position": {
@@ -588,6 +591,7 @@
588591
{
589592
"type": "definition",
590593
"identifier": "2",
594+
"label": "2",
591595
"title": "AT&T",
592596
"url": "http://att.com/",
593597
"position": {

0 commit comments

Comments
 (0)