This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: treat
bash
the same as sh
for specifying code fence language (
#401)
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
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,32 @@ | ||
// This plugin allows for code fences written in certain languages to be rendered | ||
// as though they'd been written in a different language, e.g., | ||
// | ||
// ```bash | ||
// $ marky-markdown test.md | ||
// ``` | ||
// | ||
// can have the exact same output as | ||
// | ||
// ```sh | ||
// $ marky-markdown test.md | ||
// ``` | ||
// | ||
// (doing the normal thing and setting up a syntax highlighter mapping in our | ||
// render module would almost work, except the wrapping <div> still has the | ||
// "bash" class applied) | ||
// | ||
|
||
var plugin = module.exports = function (md, opts) { | ||
var previousFenceRule = md.renderer.rules.fence | ||
md.renderer.rules.fence = function (tokens, idx, options, env, slf) { | ||
// code fence language marker is in token.info; do we have an alias? | ||
if (languageAliases.hasOwnProperty(tokens[idx].info)) { | ||
tokens[idx].info = languageAliases[tokens[idx].info] | ||
} | ||
return previousFenceRule.call(this, tokens, idx, options, env, slf) | ||
} | ||
} | ||
|
||
var languageAliases = plugin.languageAliases = { | ||
bash: 'sh' | ||
} |
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 |
---|---|---|
|
@@ -27,6 +27,10 @@ app.listen(3000) | |
echo hi | ||
``` | ||
|
||
```bash | ||
echo hi | ||
``` | ||
|
||
```coffeescript | ||
alert "hi" | ||
``` | ||
|
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