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: d10f06ddce61
Choose a base ref
...
head repository: getnikola/plugins
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: db3059a0e974
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Mar 8, 2018

  1. bump version

    Roberto Alsina committed Mar 8, 2018
    Copy the full SHA
    3bb5759 View commit details
  2. Support for new style shortcodes

    Roberto Alsina committed Mar 8, 2018
    Copy the full SHA
    ece3826 View commit details
  3. Support for new style shortcodes

    Roberto Alsina committed Mar 8, 2018
    Copy the full SHA
    db3059a View commit details
Showing with 42 additions and 24 deletions.
  1. +1 −1 v7/commonmark/commonmark.plugin
  2. +1 −1 v7/kramdown/kramdown.plugin
  3. +40 −22 v7/kramdown/kramdown.py
2 changes: 1 addition & 1 deletion v7/commonmark/commonmark.plugin
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@ PluginCategory = Compiler

[Documentation]
Author = Roberto Alsina
Version = 0.3
Version = 0.4
Website = http://plugins.getnikola.com/#commonmark
Description = Compile Markdown into HTML with CommonMark instead of python-markdown
2 changes: 1 addition & 1 deletion v7/kramdown/kramdown.plugin
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@ PluginCategory = Compiler

[Documentation]
Author = Mike Ray
Version = 0.1
Version = 0.2
Website = http://kramdown.gettalong.org/
Description = Compile kramdown into HTML
62 changes: 40 additions & 22 deletions v7/kramdown/kramdown.py
Original file line number Diff line number Diff line change
@@ -34,10 +34,10 @@
"""

import codecs
import io
import os
from os.path import abspath
import subprocess
import tempfile

from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, write_metadata
@@ -52,25 +52,43 @@ class CompileKramdown(PageCompiler):
def compile(self, source, dest, is_two_file=True, post=None, lang=None):
"""Compile the source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
command = ['kramdown', '-o', 'html', '--no-auto-ids', abspath(source)]

# Windows kludge
if os.name == 'nt':
command[4] = command[4].replace("\\", "\\\\")

with open(abspath(dest), 'wt') as f:
subprocess.check_call(command, stdout=f)
with open(dest, 'r', encoding='utf-8') as inf:
output, shortcode_deps = self.site.apply_shortcodes(inf.read(), with_dependencies=True)
with open(dest, 'w', encoding='utf-8') as outf:
outf.write(output)
if post is None:
if shortcode_deps:
self.logger.error(
"Cannot save dependencies for post {0} (post unknown)",
source)
with io.open(dest, "w+", encoding="utf8") as out_file:
with io.open(source, "r", encoding="utf8") as in_file:
data = in_file.read()
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:
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 kramdown into HTML strings."""

from nikola import shortcodes as sc
new_data, shortcodes = sc.extract_shortcodes(data)
with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as dest:
with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as source:
source.write(new_data.encode('utf8'))
command = ['kramdown', '-o', 'html', '--no-auto-ids', source.name]
# Windows kludge
if os.name == 'nt':
command[4] = command[4].replace("\\", "\\\\")
subprocess.check_call(command, stdout=dest)
os.unlink(source.name)
with open(dest.name) as inf:
output = inf.read()
os.unlink(dest.name)
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)."""
@@ -92,9 +110,9 @@ 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(write_metadata(metadata).strip())
fd.write("-->\n\n")
fd.write(content)