Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/plugins
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: af7d4f404807
Choose a base ref
...
head repository: getnikola/plugins
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 67eec05a2d19
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 8, 2018

  1. minor fixes

    Roberto Alsina committed Mar 8, 2018
    Copy the full SHA
    3d0b85b View commit details
  2. modern shortcode support

    Roberto Alsina committed Mar 8, 2018
    Copy the full SHA
    67eec05 View commit details
Showing with 31 additions and 22 deletions.
  1. +3 −3 v7/bbcode/bbcode.py
  2. +28 −19 v7/commonmark/commonmark.py
6 changes: 3 additions & 3 deletions v7/bbcode/bbcode.py
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ def compile(self, source, dest, is_two_file=True, post=None, lang=None):
output, error_level, deps, shortcode_deps = self.compile_string(data, source, is_two_file, post, lang)
out_file.write(output)
if post is None:
if deps.list:
if deps:
self.logger.error(
"Cannot save dependencies for post {0} (post unknown)",
source)
@@ -106,9 +106,9 @@ def create_post(self, path, **kw):
makedirs(os.path.dirname(path))
if not content.endswith('\n'):
content += '\n'
with io.open(path, "wb+", encoding="utf8") as fd:
with io.open(path, "w+", encoding="utf8") as fd:
if onefile:
fd.write('[note]\n')
fd.write(write_metadata(metadata))
fd.write(write_metadata(metadata).strip())
fd.write('[/note]\n\n')
fd.write(content)
47 changes: 28 additions & 19 deletions v7/commonmark/commonmark.py
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@

from __future__ import unicode_literals

import codecs
import io
import os
import re

@@ -62,21 +62,33 @@ def compile(self, source, dest, is_two_file=True, post=None, lang=None):
if CommonMark is None:
req_missing(['commonmark'], 'build this site (compile with CommonMark)')
makedirs(os.path.dirname(dest))
with codecs.open(dest, "w+", "utf8") as out_file:
with codecs.open(source, "r", "utf8") as in_file:
makedirs(os.path.dirname(dest))
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 = re.split('(\n\n|\r\n\r\n)', data, maxsplit=1)[-1]
output = self.renderer.render(self.parser.parse(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} (post unknown)",
source)
output, error_level, deps, shortcode_deps = self.compile_string(data, source, is_two_file, post, lang)
out_file.write(output)
if post is None:
if deps:
self.logger.error(
"Cannot save dependencies for post {0} (post unknown)",
source)
else:
post._depfile[dest] += shortcode_deps
if error_level == 0:
return True
else:
post._depfile[dest] += shortcode_deps
return False

def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None):
"""Compile asciidoc into HTML strings."""
if not is_two_file:
_, data = self.split_metadata(data, post, lang)
from nikola import shortcodes as sc
new_data, shortcodes = sc.extract_shortcodes(data)
output = self.renderer.render(self.parser.parse(new_data))
output, shortcode_deps = self.site.apply_shortcodes_uuid(output, shortcodes, filename=source_path, extra_context={'post': post})
return output, 0, [], shortcode_deps

def compile_html(self, source, dest, is_two_file=True):
"""Compile the post into HTML (deprecated API)."""
@@ -97,9 +109,6 @@ def create_post(self, path, **kw):
makedirs(os.path.dirname(path))
if not content.endswith('\n'):
content += '\n'
with codecs.open(path, "wb+", "utf8") as fd:
with io.open(path, "w+", encoding="utf8") as fd:
if onefile:
fd.write('<!-- \n')
fd.write(write_metadata(metadata))
fd.write('-->\n\n')
fd.write(content)
fd.write('<!--\n{}-->\n\n'.format(write_metadata(metadata).strip()))