-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba2a45e
commit bb6202f
Showing
9 changed files
with
77 additions
and
22 deletions.
There are no files selected for viewing
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 @@ | ||
module.exports = Tools = {} |
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
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,25 @@ | ||
Tools = require '../_tools' | ||
|
||
module.exports = class Tools.Referencer | ||
|
||
constructor: (@environment) -> | ||
|
||
resolve: (text, replacer) -> | ||
# Make curly braces within code blocks undetectable | ||
text = text.replace /\`[^\`]*\`/mg, (match) -> match.replace(/\{/mg, "\u0091").replace(/\}/mg, "\u0092") | ||
|
||
# Search for references and replace them | ||
text = text.replace /\{([^\}]*)\}/gm, (match, link) => | ||
link = link.split(' ') | ||
href = link.shift() | ||
label = link.join(' ') | ||
|
||
replacement = @environment.reference(href) | ||
|
||
if replacement != href || /\:\/\/\w+((\:\d+)?\/\S*)?/.test(href) | ||
replacer replacement, label || href | ||
else | ||
match | ||
|
||
# Restore curly braces within code blocks | ||
text = text.replace /\`[^\`]*\`/mg, (match) -> match.replace(/\u0091/mg, '{').replace(/\u0092/mg, '}') |
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