-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mapping of references without definitions
* CommonMark seems to have changed in that it now always maps undefined references back to markdown Closes GH-20. Closes GH-21.
- Loading branch information
Showing
6 changed files
with
96 additions
and
116 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict' | ||
|
||
module.exports = revert | ||
|
||
var u = require('unist-builder') | ||
var all = require('./all') | ||
|
||
/* Return the content of a reference without definition as markdown. */ | ||
function revert(h, node) { | ||
var subtype = node.referenceType | ||
var suffix = ']' | ||
var contents | ||
var head | ||
var tail | ||
|
||
if (subtype === 'collapsed') { | ||
suffix += '[]' | ||
} else if (subtype === 'full') { | ||
suffix += '[' + node.identifier + ']' | ||
} | ||
|
||
if (node.type === 'imageReference') { | ||
return u('text', '![' + node.alt + suffix) | ||
} | ||
|
||
contents = all(h, node) | ||
head = contents[0] | ||
|
||
if (head && head.type === 'text') { | ||
head.value = '[' + head.value | ||
} else { | ||
contents.unshift(u('text', '[')) | ||
} | ||
|
||
tail = contents[contents.length - 1] | ||
|
||
if (tail && tail.type === 'text') { | ||
tail.value += suffix | ||
} else { | ||
contents.push(u('text', suffix)) | ||
} | ||
|
||
return contents | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters