Skip to content

Commit

Permalink
Fixes fossasia#311 Add support for markdown constructs not in commonmark
Browse files Browse the repository at this point in the history
  • Loading branch information
pri22296 committed Aug 24, 2017
1 parent 6641394 commit 89731f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions modules/scripts/markdown.py
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)
4 changes: 2 additions & 2 deletions modules/templates/conf.py_t
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ import os
import sys
import mock
import pkg_resources
from recommonmark.parser import CommonMarkParser
from recommonmark.transform import AutoStructify

# Adding scripts and extensions directory to sys.path
sys.path.insert(0, os.path.abspath('scripts'))
sys.path.insert(0, os.path.join(os.path.abspath('scripts'), 'extensions'))

from config.serializer import deserialize
from markdown import MarkdownParser

{% if autoapi_python == true %}
for (dirpath, dirnames, filenames) in os.walk('{{ root_dir }}'):
Expand Down Expand Up @@ -107,7 +107,7 @@ templates_path = ['{{ dot }}templates']

# The parser(s) of source files
source_parsers = {
'.md': CommonMarkParser,
'.md': MarkdownParser,
}

# The suffix(es) of source filenames.
Expand Down

0 comments on commit 89731f2

Please sign in to comment.