-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for GitHub style callouts
- Loading branch information
1 parent
2eec7c4
commit f9950e0
Showing
8 changed files
with
230 additions
and
52 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
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,36 @@ | ||
export const blockquoteCompiler = ({ renderer }) => | ||
(renderer.blockquote = function ({ tokens }) { | ||
const calloutData = | ||
tokens[0].type === 'paragraph' && | ||
// 0: Match "[!TIP] My Title" | ||
// 1: Mark "[!TIP]" | ||
// 2: Type "TIP" | ||
tokens[0].raw.match(/^(\[!(\w+)\])/); | ||
|
||
let openTag = '<blockquote>'; | ||
let closeTag = '</blockquote>'; | ||
|
||
if (calloutData) { | ||
const calloutMark = calloutData[1]; // "[!TIP]" | ||
const calloutType = calloutData[2].toLowerCase(); // "tip" | ||
const token = tokens[0].tokens[0]; | ||
|
||
// Remove callout mark from tokens | ||
['raw', 'text'].forEach(key => { | ||
token[key] = token[key].replace(calloutMark, '').trimStart(); | ||
}); | ||
|
||
// Remove empty paragraph | ||
if (tokens.length > 1 && !token.raw.trim()) { | ||
tokens = tokens.slice(1); | ||
} | ||
|
||
openTag = `<div class="callout ${calloutType}">`; | ||
closeTag = `</div>`; | ||
} | ||
|
||
const body = this.parser.parse(tokens); | ||
const html = `${openTag}${body}${closeTag}`; | ||
|
||
return html; | ||
}); |
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
Oops, something went wrong.