forked from fossasia/yaydoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes fossasia#311 Add support for markdown constructs not in commonmark
- Loading branch information
Showing
2 changed files
with
23 additions
and
2 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,21 @@ | ||
import re | ||
from recommonmark.parser import CommonMarkParser | ||
from md2rst import md2rst | ||
|
||
|
||
MARKDOWN_PLUS_REGEX = re.compile('<!--\s+markdown\+\s+-->(.*?)<!--\s+endmarkdown\+\s+-->', re.DOTALL) | ||
EVAL_RST_TEMPLATE = "```eval_rst\n{content}\n```" | ||
|
||
|
||
def preprocess_markdown(inputstring): | ||
def callback(match_object): | ||
text = match_object.group(1) | ||
return EVAL_RST_TEMPLATE.format(content=md2rst(text)) | ||
|
||
return re.sub(MARKDOWN_PLUS_REGEX, callback, inputstring) | ||
|
||
|
||
class MarkdownParser(CommonMarkParser): | ||
def parse(self, inputstring, document): | ||
content = preprocess_markdown(inputstring) | ||
CommonMarkParser.parse(self, content, document) |
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