-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
62 changed files
with
501 additions
and
3 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,53 @@ | ||
from __future__ import annotations | ||
|
||
import re | ||
import xml.etree.ElementTree as etree | ||
|
||
from markdown import Markdown, util | ||
from markdown.blockprocessors import BlockQuoteProcessor | ||
from markdown.extensions import Extension | ||
|
||
|
||
# Based on https://github.com/Python-Markdown/markdown/blob/4acb949256adc535d6e6cd84c4fb47db8dda2f46/markdown/blockprocessors.py#L277 | ||
class _GitHubCalloutsBlockProcessor(BlockQuoteProcessor): | ||
REGEX = re.compile( | ||
r"((?:^|\n) *(?:[^>].*)?(?:^|\n)) {0,3}> *\[!([A-Za-z]{3,})\] *\n(?: *> *\n)*() *(?:> *[^\s\n]|[^\s\n>])" | ||
) | ||
|
||
def test(self, parent, block): | ||
return ( | ||
bool(self.REGEX.search(block)) | ||
and not self.parser.state.isstate("blockquote") | ||
and not util.nearing_recursion_limit() | ||
) | ||
|
||
def run(self, parent: etree.Element, blocks: list[str]) -> None: | ||
block = blocks.pop(0) | ||
m = self.REGEX.search(block) | ||
assert m | ||
|
||
before = block[: m.end(1)] | ||
block = "\n".join(self.clean(line) for line in block[m.end(3) :].split("\n")) | ||
self.parser.parseBlocks(parent, [before]) | ||
kind = m[2] | ||
|
||
admon = etree.SubElement(parent, "div", {"class": "admonition " + kind.lower()}) | ||
title = etree.SubElement(admon, "p", {"class": "admonition-title"}) | ||
title.text = kind.title() | ||
|
||
self.parser.state.set("blockquote") | ||
self.parser.parseChunk(admon, block) | ||
self.parser.state.reset() | ||
|
||
|
||
class GitHubCalloutsExtension(Extension): | ||
def extendMarkdown(self, md: Markdown) -> None: | ||
parser = md.parser # type: ignore | ||
parser.blockprocessors.register( | ||
_GitHubCalloutsBlockProcessor(parser), | ||
"github-callouts", | ||
21.1, # Right before blockquote | ||
) | ||
|
||
|
||
makeExtension = GitHubCalloutsExtension |
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,22 @@ | ||
input: | | ||
> [!Note] | ||
> foo | ||
NOTE: bar | ||
output: |- | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
foo | ||
</p> | ||
</div> | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
bar | ||
</p> | ||
</div> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,17 @@ | ||
input: | | ||
> [!Note] | ||
> foo | ||
> [!Note] | ||
> bar | ||
output: |- | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
foo | ||
[!Note] | ||
bar | ||
</p> | ||
</div> |
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,18 @@ | ||
input: | | ||
aaa | ||
> [!Note] | ||
> bbb | ||
ccc | ||
output: |- | ||
<p> | ||
aaa | ||
</p> | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
bbb | ||
ccc | ||
</p> | ||
</div> |
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,14 @@ | ||
input: | | ||
> aaa | ||
> [!Note] | ||
> bbb | ||
> ccc | ||
output: |- | ||
<blockquote> | ||
<p> | ||
aaa | ||
[!Note] | ||
bbb | ||
ccc | ||
</p> | ||
</blockquote> |
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,23 @@ | ||
input: | | ||
> [!Note] | ||
> foo | ||
> [!Note] | ||
> bar | ||
output: |- | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
foo | ||
</p> | ||
</div> | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
bar | ||
</p> | ||
</div> |
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 @@ | ||
input: | | ||
> [!Warning] | ||
a | ||
<!-- --> | ||
> [!Warning] | ||
>> | ||
output: |- | ||
<div class="admonition warning"> | ||
<p class="admonition-title"> | ||
Warning | ||
</p> | ||
<p> | ||
a | ||
</p> | ||
</div> | ||
<!-- --> | ||
<div class="admonition warning"> | ||
<p class="admonition-title"> | ||
Warning | ||
</p> | ||
<blockquote> | ||
</blockquote> | ||
</div> |
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,12 @@ | ||
input: | | ||
> [!Note] | ||
> Hello, world! | ||
output: |- | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
Hello, world! | ||
</p> | ||
</div> |
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 @@ | ||
input: | | ||
> [!Note] | ||
> Foo. | ||
> a | ||
> Bar. | ||
> [!Warning] | ||
> Baz. | ||
output: |- | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
Foo. | ||
</p> | ||
</div> | ||
<blockquote> | ||
<p> | ||
a | ||
Bar. | ||
</p> | ||
</blockquote> | ||
<div class="admonition warning"> | ||
<p class="admonition-title"> | ||
Warning | ||
</p> | ||
<p> | ||
Baz. | ||
</p> | ||
</div> |
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,34 @@ | ||
input: | | ||
> [!Note] | ||
> Foo. | ||
<!-- --> | ||
> a | ||
> Bar. | ||
<!-- --> | ||
> [!Warning] | ||
> Baz. | ||
output: |- | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
Foo. | ||
</p> | ||
</div> | ||
<!-- --> | ||
<blockquote> | ||
<p> | ||
a | ||
Bar. | ||
</p> | ||
</blockquote> | ||
<!-- --> | ||
<div class="admonition warning"> | ||
<p class="admonition-title"> | ||
Warning | ||
</p> | ||
<p> | ||
Baz. | ||
</p> | ||
</div> |
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,26 @@ | ||
input: | | ||
> [!Note] | ||
> Foo. | ||
> | ||
> a | ||
> Bar. | ||
> | ||
> [!Warning] | ||
> Baz. | ||
output: |- | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
Foo. | ||
</p> | ||
<p> | ||
a | ||
Bar. | ||
</p> | ||
<p> | ||
[!Warning] | ||
Baz. | ||
</p> | ||
</div> |
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,10 @@ | ||
input: | | ||
> [!Warning] | ||
> | ||
> | ||
output: |- | ||
<blockquote> | ||
<p> | ||
[!Warning] | ||
</p> | ||
</blockquote> |
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,24 @@ | ||
input: | | ||
> [!Note] | ||
> foo | ||
<!-- --> | ||
> [!Note] | ||
> foo | ||
output: |- | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
foo | ||
</p> | ||
</div> | ||
<!-- --> | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
foo | ||
</p> | ||
</div> |
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,28 @@ | ||
input: | | ||
> [!Warning] | ||
hi | ||
> [!Warning] | ||
> | ||
<!-- --> | ||
>[!Warning] | ||
output: |- | ||
<blockquote> | ||
<p> | ||
[!Warning] | ||
</p> | ||
</blockquote> | ||
<p> | ||
hi | ||
</p> | ||
<blockquote> | ||
<p> | ||
[!Warning] | ||
</p> | ||
</blockquote> | ||
<!-- --> | ||
<blockquote> | ||
<p> | ||
[!Warning] | ||
</p> | ||
</blockquote> |
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,16 @@ | ||
input: | | ||
> [!Note] | ||
> | ||
> Body. | ||
> More. | ||
output: |- | ||
<div class="admonition note"> | ||
<p class="admonition-title"> | ||
Note | ||
</p> | ||
<p> | ||
Body. | ||
<br/> | ||
More. | ||
</p> | ||
</div> |
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,11 @@ | ||
input: | | ||
> **note**: foo | ||
output: |- | ||
<blockquote> | ||
<p> | ||
<strong> | ||
note | ||
</strong> | ||
: foo | ||
</p> | ||
</blockquote> |
Oops, something went wrong.