-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add linkTitle syntas. Change the scope of code span escaping and its …
…metadata behavior. Cleanup. Improve docs.
- Loading branch information
1 parent
edece12
commit e00c32c
Showing
23 changed files
with
339 additions
and
90 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dist | ||
tools/output | ||
test/mytest* | ||
test/browser/* |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,21 +1,33 @@ | ||
const BACKTICK_RUN_RE = /(^`*)|(`+(?!.))|`+/; | ||
const longestBacktickString = (str) => { | ||
const m = str.match(/`+/g); | ||
return m | ||
? m.reduce((longest, current) => ( | ||
current.length > longest.length ? current : longest | ||
), '') | ||
: ''; | ||
}; | ||
|
||
function processBacktickRun({ match: [m, start, end] }) { | ||
if (start !== undefined || m.length >= this.metadata.delimiter.length) { | ||
this.metadata.delimiter = `${m}\``; | ||
} | ||
if (start !== undefined) { | ||
this.metadata.space = start.length > 0 ? ' ' : ''; | ||
} | ||
if (end && !this.metadata.space) { | ||
this.metadata.space = ' '; | ||
} | ||
return m; | ||
const SHOULD_ADD_SPACE_RE = /^`|^[ \r\n].*?[^ \r\n].*[ \r\n]$|`$/; | ||
|
||
function scanDelimiters(input) { | ||
const x = this.metadata; | ||
x.extraBacktickString = longestBacktickString(input); | ||
x.extraSpace = SHOULD_ADD_SPACE_RE.test(input) ? ' ' : ''; | ||
return input; | ||
} | ||
|
||
function addDelimiterExtras(output) { | ||
const x = this.metadata; | ||
const before = x.extraBacktickString + x.extraSpace; | ||
const after = x.extraSpace + x.extraBacktickString; | ||
return `${before}${output}${after}`; | ||
} | ||
|
||
/** | ||
* Escape parentheses <, > and whitespace either as entites or in URL encoding. | ||
* Adjust leading and trailing code span part according to contets and | ||
* set metadata. | ||
*/ | ||
export default function codeSpanReplace() { | ||
this.replacer.addReplacement(BACKTICK_RUN_RE, processBacktickRun, true); | ||
this.preprocessors.push(scanDelimiters); | ||
this.postprocessors.unshift(addDelimiterExtras); | ||
} |
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
Oops, something went wrong.