Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/remark-parse/lib/tokenize/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ function definition(eat, value, silent) {
return eat(subvalue)({
type: 'definition',
identifier: normalize(identifier),
label: identifier,
title: title || null,
url: url
});
Expand Down
5 changes: 3 additions & 2 deletions packages/remark-parse/lib/tokenize/footnote-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -179,7 +179,8 @@ function footnoteDefinition(eat, value, silent) {

return add({
type: 'footnoteDefinition',
identifier: identifier,
identifier: normalize(identifier),
label: identifier,
children: content
});
}
3 changes: 2 additions & 1 deletion packages/remark-parse/lib/tokenize/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions packages/remark-stringify/lib/util/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ']';
}
2 changes: 1 addition & 1 deletion packages/remark-stringify/lib/visitors/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ function definition(node) {
content += ' ' + title(node.title);
}

return '[' + node.identifier + ']: ' + content;
return '[' + (node.label || node.identifier) + ']: ' + content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
module.exports = footnoteReference;

function footnoteReference(node) {
return '[^' + node.identifier + ']';
return '[^' + (node.label || node.identifier) + ']';
}
2 changes: 1 addition & 1 deletion packages/remark-stringify/lib/visitors/link-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/tree/amps-and-angles-encoding.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
{
"type": "linkReference",
"identifier": "1",
"label": "1",
"referenceType": "full",
"children": [
{
Expand Down Expand Up @@ -322,6 +323,7 @@
{
"type": "linkReference",
"identifier": "2",
"label": "2",
"referenceType": "full",
"children": [
{
Expand Down Expand Up @@ -569,6 +571,7 @@
{
"type": "definition",
"identifier": "1",
"label": "1",
"title": null,
"url": "http://example.com/?foo=1&bar=2",
"position": {
Expand All @@ -588,6 +591,7 @@
{
"type": "definition",
"identifier": "2",
"label": "2",
"title": "AT&T",
"url": "http://att.com/",
"position": {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/tree/auto-link-url.nogfm.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
{
"type": "linkReference",
"identifier": "world",
"label": "world",
"referenceType": "shortcut",
"children": [
{
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/tree/case-insensitive-refs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{
"type": "linkReference",
"identifier": "hi",
"label": "hi",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -59,6 +60,7 @@
{
"type": "definition",
"identifier": "hi",
"label": "HI",
"title": null,
"url": "/url",
"position": {
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/tree/def-blocks.commonmark.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{
"type": "linkReference",
"identifier": "1",
"label": "1",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -158,6 +159,7 @@
{
"type": "linkReference",
"identifier": "2",
"label": "2",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -315,6 +317,7 @@
{
"type": "linkReference",
"identifier": "3",
"label": "3",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -449,6 +452,7 @@
{
"type": "linkReference",
"identifier": "4",
"label": "4",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -580,6 +584,7 @@
{
"type": "linkReference",
"identifier": "1",
"label": "1",
"referenceType": "shortcut",
"children": [
{
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/tree/def-blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
{
"type": "linkReference",
"identifier": "1",
"label": "1",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -200,6 +201,7 @@
{
"type": "definition",
"identifier": "2",
"label": "2",
"title": null,
"url": "hello",
"position": {
Expand Down Expand Up @@ -288,6 +290,7 @@
{
"type": "linkReference",
"identifier": "3",
"label": "3",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -465,6 +468,7 @@
{
"type": "definition",
"identifier": "4",
"label": "4",
"title": null,
"url": "hello",
"position": {
Expand Down Expand Up @@ -543,6 +547,7 @@
{
"type": "definition",
"identifier": "1",
"label": "1",
"title": null,
"url": "foo",
"position": {
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/tree/definition-newline.commonmark.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{
"type": "linkReference",
"identifier": "baz",
"label": "baz",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -83,6 +84,7 @@
{
"type": "linkReference",
"identifier": "foo",
"label": "foo",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -159,6 +161,7 @@
{
"type": "linkReference",
"identifier": "bar",
"label": "bar",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -216,6 +219,7 @@
{
"type": "linkReference",
"identifier": "baz",
"label": "baz",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -291,6 +295,7 @@
{
"type": "definition",
"identifier": "baz",
"label": "baz",
"title": "foo\nbar",
"url": "/url",
"position": {
Expand All @@ -312,6 +317,7 @@
{
"type": "definition",
"identifier": "baz",
"label": "baz",
"title": "foo\nbar",
"url": "/url",
"position": {
Expand All @@ -336,6 +342,7 @@
{
"type": "linkReference",
"identifier": "baz",
"label": "baz",
"referenceType": "shortcut",
"children": [
{
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/tree/definition-newline.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{
"type": "linkReference",
"identifier": "baz",
"label": "baz",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -83,6 +84,7 @@
{
"type": "linkReference",
"identifier": "foo",
"label": "foo",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -159,6 +161,7 @@
{
"type": "linkReference",
"identifier": "bar",
"label": "bar",
"referenceType": "shortcut",
"children": [
{
Expand Down Expand Up @@ -232,6 +235,7 @@
{
"type": "definition",
"identifier": "baz",
"label": "baz",
"title": "foo\nbar",
"url": "/url",
"position": {
Expand All @@ -253,6 +257,7 @@
{
"type": "definition",
"identifier": "baz",
"label": "baz",
"title": "foo\nbar",
"url": "/url",
"position": {
Expand All @@ -274,6 +279,7 @@
{
"type": "definition",
"identifier": "baz",
"label": "baz",
"title": "foo\nbar",
"url": "/url",
"position": {
Expand All @@ -298,6 +304,7 @@
{
"type": "linkReference",
"identifier": "baz",
"label": "baz",
"referenceType": "shortcut",
"children": [
{
Expand Down
Loading