Skip to content
Permalink
Browse files

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 4f1f5f76e1fb0f8830bbd4cc6cafe9f0c1f11397
@@ -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

@@ -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."""
@@ -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

@@ -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):
@@ -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

@@ -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):
@@ -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.

0 comments on commit 4f1f5f7

Please sign in to comment.
You can’t perform that action at this time.