Skip to content

Commit

Permalink
Shortcode support for mistune
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Sep 24, 2016
1 parent 651995c commit 0c5f6a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion v7/mistune/mistune.plugin
Expand Up @@ -7,6 +7,6 @@ plugincategory = Compiler

[Documentation]
Author = Roberto Alsina
Version = 0.1
Version = 0.2
Website = http://plugins.getnikola.com/#mistune
Description = Compile Markdown into HTML with Mistune instead of python-markdown
14 changes: 13 additions & 1 deletion v7/mistune/mistune.py
Expand Up @@ -48,7 +48,7 @@
class CompileMistune(PageCompiler):
"""Compile Markdown into HTML using Mistune."""

name = "commonmark"
name = "mistune"
demote_headers = True

def __init__(self, *args, **kwargs):
Expand All @@ -60,13 +60,25 @@ def compile_html(self, source, dest, is_two_file=True):
if mistune is None:
req_missing(['mistune'], 'build this site (compile with mistune)')
makedirs(os.path.dirname(dest))
try:
post = self.site.post_per_input_file[source]
except KeyError:
post = None
with codecs.open(dest, "w+", "utf8") as out_file:
with codecs.open(source, "r", "utf8") as in_file:
data = in_file.read()
if not is_two_file:
data = re.split('(\n\n|\r\n\r\n)', data, maxsplit=1)[-1]
output = self.parser(data)
output, shortcode_deps = self.site.apply_shortcodes(output, filename=source, with_dependencies=True, extra_context=dict(post=post))
out_file.write(output)
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} due to unregistered source file name",
source)
else:
post._depfile[dest] += shortcode_deps

def create_post(self, path, **kw):
content = kw.pop('content', 'Write your post here.')
Expand Down

0 comments on commit 0c5f6a4

Please sign in to comment.