Skip to content
Closed
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
4 changes: 4 additions & 0 deletions packages/remark-parse/lib/tokenize/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ function reference(eat, value, silent) {
};

if (type === T_LINK || type === T_IMAGE) {
if (referenceType === 'full' && node.identifier !== identifier) {
node.reference = identifier;
}

node.referenceType = referenceType;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/remark-stringify/lib/util/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = label;
* changes. */
function label(node) {
var type = node.referenceType;
var value = type === 'full' ? node.identifier : '';
var value = type === 'full' ? (node.reference || node.identifier) : '';

return type === 'shortcut' ? value : '[' + value + ']';
}
1 change: 1 addition & 0 deletions test/fixtures/tree/links-reference-proto.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{
"type": "linkReference",
"identifier": "tostring",
"reference": "toString",
"referenceType": "full",
"children": [
{
Expand Down
24 changes: 24 additions & 0 deletions test/remark-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,30 @@ test('remark().stringify(ast, file)', function (t) {
});
});

t.test('undefined references should fallback to original', function (st) {
/* Data-driven tests in the format: [name, input, expected] */
var tests = [
['capitalized link references - full', '[alpha][Bravo]'],
['capitalized link references - collapsed', '[Bravo][]'],
['capitalized link references - shortcut', '[Bravo]'],
['capitalized image references - full', '![alpha][Bravo]'],
['capitalized image references - collapsed', '![Bravo][]'],
['capitalized image references - shortcut', '![Bravo]'],
['capitalized footnote references', '[^Alpha]']
];

st.plan(tests.length);
tests.forEach(function (test) {
st.equal(
remark()
.processSync(test[1])
.toString(),
test[1] + '\n',
test[0]
);
});
});

t.test('should support `stringLength`', function (st) {
st.plan(2);

Expand Down