diff --git a/lib/parse.js b/lib/parse.js index 4be56a2ee..7b86c91d0 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -4577,10 +4577,6 @@ function tokenizeReference(eat, value, silent) { index++; } - if (!queue) { - return; - } - subvalue = text = queue; character = value.charAt(index); @@ -4606,6 +4602,10 @@ function tokenizeReference(eat, value, silent) { character = value.charAt(index); if (character !== C_BRACKET_OPEN) { + if (!text) { + return; + } + identifier = text; } else { identifier = EMPTY; @@ -4699,7 +4699,7 @@ function tokenizeReference(eat, value, silent) { node.children = self.tokenizeInline(text, now); exitLink(); } else if (type === T_IMAGE) { - node.alt = decode(self.descape(text), eat); + node.alt = decode(self.descape(text), eat) || null; } return eat(subvalue)(node); diff --git a/lib/stringify.js b/lib/stringify.js index 3d57afb0f..1faadb905 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -1954,7 +1954,7 @@ compilerPrototype.linkReference = function (node) { * @return {string} - Markdown image reference. */ compilerPrototype.imageReference = function (node) { - var alt = this.encode(node.alt, node); + var alt = this.encode(node.alt, node) || EMPTY; return EXCLAMATION_MARK + SQUARE_BRACKET_OPEN + alt + SQUARE_BRACKET_CLOSE + diff --git a/test/input/reference-image-empty-alt.text b/test/input/reference-image-empty-alt.text new file mode 100644 index 000000000..806cd2c64 --- /dev/null +++ b/test/input/reference-image-empty-alt.text @@ -0,0 +1,3 @@ +![][1] + +[1]: /xyz.png diff --git a/test/tree/reference-image-empty-alt.json b/test/tree/reference-image-empty-alt.json new file mode 100644 index 000000000..50b5b6ebe --- /dev/null +++ b/test/tree/reference-image-empty-alt.json @@ -0,0 +1,65 @@ +{ + "type": "root", + "children": [ + { + "type": "paragraph", + "children": [ + { + "type": "imageReference", + "identifier": "1", + "referenceType": "full", + "alt": null, + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + }, + "indent": [] + } + }, + { + "type": "definition", + "identifier": "1", + "title": null, + "link": "/xyz.png", + "position": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 14 + }, + "indent": [] + } + } + ], + "position": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 4, + "column": 1 + } + } +}