Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Matching API of ReST compiler.
  • Loading branch information
felixfontein committed Jan 8, 2017
1 parent b6617b8 commit 0a904e0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions nikola/plugins/compile/markdown/__init__.py
Expand Up @@ -63,14 +63,16 @@ def set_site(self, site):

self.config_dependencies.append(str(sorted(site.config.get("MARKDOWN_EXTENSIONS"))))

def compile_to_string(self, content):
"""Compile the content into HTML."""
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 += self.site.config.get("MARKDOWN_EXTENSIONS")
if not is_two_file:
_, content = self.split_metadata(content)
output = markdown(content, self.extensions, output_format="html5")
output, _ = self.site.apply_shortcodes(output, filename=source, with_dependencies=True, extra_context=dict(post=post))
return output
output, shortcode_deps = self.site.apply_shortcodes(output, filename=source, with_dependencies=True, extra_context=dict(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."""
Expand All @@ -81,10 +83,7 @@ def compile(self, source, dest, is_two_file=True, post=None, lang=None):
with io.open(dest, "w+", encoding="utf8") as out_file:
with io.open(source, "r", encoding="utf8") as in_file:
data = in_file.read()
if not is_two_file:
_, data = self.split_metadata(data)
output = markdown(data, self.extensions, output_format="html5")
output, shortcode_deps = self.site.apply_shortcodes(output, filename=source, with_dependencies=True, extra_context=dict(post=post))
output, shortcode_deps = self.compile_string(data, source, is_two_file)
out_file.write(output)
if post is None:
if shortcode_deps:
Expand Down

0 comments on commit 0a904e0

Please sign in to comment.