Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2759 from getnikola/use-new-shortcodes
More new-shortcode support
  • Loading branch information
ralsina committed May 12, 2017
2 parents 5246265 + 4ccbc6f commit 4f1f5f7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion nikola/plugins/compile/html.py
Expand Up @@ -31,6 +31,7 @@
import os
import io

from nikola import shortcodes as sc
from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, write_metadata

Expand All @@ -45,7 +46,8 @@ def compile_string(self, data, source_path=None, is_two_file=True, post=None, la
"""Compile HTML into HTML strings, with shortcode support."""
if not is_two_file:
_, data = self.split_metadata(data)
return self.site.apply_shortcodes(data, with_dependencies=True, extra_context={'post': post})
new_data, shortcodes = sc.extract_shortcodes(data)
return self.site.apply_shortcodes_uuid(new_data, shortcodes, filename=source_path, with_dependencies=True, extra_context=dict(post=post))

def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
Expand Down
6 changes: 4 additions & 2 deletions nikola/plugins/compile/ipynb.py
Expand Up @@ -61,6 +61,7 @@
flag = None
ipy_modern = None

from nikola import shortcodes as sc
from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, req_missing, get_logger, STDERR_HANDLER

Expand Down Expand Up @@ -94,8 +95,9 @@ def _nbformat_read(in_file):

def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None):
"""Compile notebooks into HTML strings."""
output = self._compile_string(nbformat.reads(data, current_nbformat))
return self.site.apply_shortcodes(output, filename=source_path, with_dependencies=True, extra_context={'post': post})
new_data, shortcodes = sc.extract_shortcodes(data)
output = self._compile_string(nbformat.reads(new_data, current_nbformat))
return self.site.apply_shortcodes_uuid(output, shortcodes, filename=source_path, with_dependencies=True, extra_context=dict(post=post))

# TODO remove in v8
def compile_html_string(self, source, is_two_file=True):
Expand Down
6 changes: 4 additions & 2 deletions nikola/plugins/compile/markdown/__init__.py
Expand Up @@ -40,6 +40,7 @@
gist_extension = None
podcast_extension = None

from nikola import shortcodes as sc
from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, req_missing, write_metadata

Expand Down Expand Up @@ -91,8 +92,9 @@ def compile_string(self, data, source_path=None, is_two_file=True, post=None, la
req_missing(['markdown'], 'build this site (compile Markdown)')
if not is_two_file:
_, data = self.split_metadata(data)
output = self.converter.convert(data)
output, shortcode_deps = self.site.apply_shortcodes(output, filename=source_path, with_dependencies=True, extra_context={'post': post})
new_data, shortcodes = sc.extract_shortcodes(data)
output = self.converter.convert(new_data)
output, shortcode_deps = self.site.apply_shortcodes_uuid(output, shortcodes, filename=source_path, 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):
Expand Down
3 changes: 3 additions & 0 deletions nikola/shortcodes.py
Expand Up @@ -221,6 +221,9 @@ def extract_shortcodes(data):
shortcodes = {}
splitted = _split_shortcodes(data)

if not data: # Empty
return '', {}

def extract_data_chunk(data):
"""Take a list of splitted shortcodes and return a string and a tail.
Expand Down

0 comments on commit 4f1f5f7

Please sign in to comment.