Skip to content
Browse files
Merge pull request #2622 from getnikola/markdown-to-string
Allowing to compile MarkDown posts from string to string.
  • Loading branch information
Kwpolska committed Jan 8, 2017
2 parents c2da98c + 9a1d901 commit 80abb4afca07671958f2d3b4e276b7f28815a0d9
Showing with 12 additions and 5 deletions.
  1. +12 −5 nikola/plugins/compile/markdown/
@@ -63,19 +63,26 @@ def set_site(self, site):


def compile_string(self, content, source_path=None, is_two_file=True):
"""Compile Markdown into HTML strings."""
if markdown is None:
req_missing(['markdown'], 'build this site (compile Markdown)')
self.extensions +="MARKDOWN_EXTENSIONS")
if not is_two_file:
_, content = self.split_metadata(content)
output = markdown(content, self.extensions, output_format="html5")
output, shortcode_deps =, filename=source_path, with_dependencies=True, extra_context={'post': post})
return output, shortcode_deps

def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
if markdown is None:
req_missing(['markdown'], 'build this site (compile Markdown)')
self.extensions +="MARKDOWN_EXTENSIONS")
with, "w+", encoding="utf8") as out_file:
with, "r", encoding="utf8") as in_file:
data =
if not is_two_file:
_, data = self.split_metadata(data)
output = markdown(data, self.extensions, output_format="html5")
output, shortcode_deps =, filename=source, with_dependencies=True, extra_context=dict(post=post))
output, shortcode_deps = self.compile_string(data, source, is_two_file)
if post is None:
if shortcode_deps:

0 comments on commit 80abb4a

Please sign in to comment.