Skip to content

Commit

Permalink
fix issues link references and prototypes
Browse files Browse the repository at this point in the history
Link with names that clashed with properties inherited from the
Object prototype (such as "constructor") were not expanding. This fixes
this issue.

Before this change, markdown of this form...:

    Link: [constructor][].

    [constructor]: https://example.org/

...resulted in HTML output of this form:

    <p>Link: [constructor][].</p>

With this change, it now renders as expected:

    <p>Link: <a href="https://example.org/">constructor</a>.</p>
  • Loading branch information
Trott committed Jun 28, 2018
1 parent 666e455 commit 04e04b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ block.pedantic = merge({}, block.normal, {

function Lexer(options) {
this.tokens = [];
this.tokens.links = {};
this.tokens.links = Object.create(null);
this.options = options || marked.defaults;
this.rules = block.normal;

Expand Down
14 changes: 14 additions & 0 deletions test/specs/marked/marked-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ describe('Marked Code spans', function() {
});
});

describe('Marked Links', function() {
var section = 'Links';

var shouldPassButFails = [];

var willNotBeAttemptedByCoreTeam = [];

var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);

markedSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});

describe('Marked Table cells', function() {
var section = 'Table cells';

Expand Down
6 changes: 6 additions & 0 deletions test/specs/marked/marked.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,11 @@
"markdown": "|1|2|\n|-|-|\n| |2|",
"html": "<table><thead><tr><th>1</th><th>2</th></tr></thead><tbody><tr><td></td><td>2</td></tr></tbody></table>",
"example": 9
},
{
"section": "Links",
"markdown": "Link: [constructor][].\n\n[constructor]: https://example.org/",
"html": "<p>Link: <a href=\"https://example.org/\">constructor</a>.</p>",
"example": 10
}
]

0 comments on commit 04e04b1

Please sign in to comment.