Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into refactor-galleries-gain
  • Loading branch information
ralsina committed Jun 10, 2015
2 parents 1ef5871 + 5e45dd7 commit 90ac2ae
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -12,6 +12,9 @@ Features
Bugfixes
--------

* Handle missing ws4py better in auto plugin (Issue #1803)
* IDNA mixing unicode/bytes in python 3 (Issue #1802)
* Cleaner splitting of metadata in onefile posts (Issue #973)
* It's markdown extra, not extras (Issue #1799)

New in v7.5.0
Expand Down
3 changes: 2 additions & 1 deletion nikola/nikola.py
Expand Up @@ -1026,7 +1026,8 @@ def url_replacer(self, src, dst, lang=None, url_type=None):
# python 3: already unicode
pass
nl = nl.encode('idna')

if isinstance(nl, utils.bytes_str):
nl = nl.decode('latin-1') # so idna stays unchanged
dst = urlunsplit((dst_url.scheme,
nl,
dst_url.path,
Expand Down
12 changes: 12 additions & 0 deletions nikola/plugin_categories.py
Expand Up @@ -27,6 +27,7 @@
from __future__ import absolute_import
import sys
import os
import re

from yapsy.IPlugin import IPlugin
from doit.cmd_base import Command as DoitCommand
Expand Down Expand Up @@ -270,6 +271,17 @@ def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False,
"""
return {}

def split_metadata(self, data):
"""Split data from metadata in the raw post content.
This splits in the first empty line that is NOT at the beginning
of the document."""
split_result = re.split('(\n\n|\r\n\r\n)', data.lstrip(), maxsplit=1)
if len(split_result) == 1:
return '', split_result[0]
# ['metadata', '\n\n', 'post content']
return split_result[0], split_result[-1]


class RestExtension(BasePlugin):
name = "dummy_rest_extension"
Expand Down
4 changes: 2 additions & 2 deletions nikola/plugins/command/auto/__init__.py
Expand Up @@ -46,7 +46,7 @@
from ws4py.server.wsgiutils import WebSocketWSGIApplication
from ws4py.messaging import TextMessage
except ImportError:
WebSocket = None
WebSocket = object
try:
import pyinotify
except ImportError:
Expand Down Expand Up @@ -115,7 +115,7 @@ def _execute(self, options, args):

self.logger = get_logger('auto', self.site.loghandlers)

if WebSocket is None:
if WebSocket is object:
req_missing(['ws4py'], 'use the "auto" command')
return
if pyinotify is None:
Expand Down
5 changes: 1 addition & 4 deletions nikola/plugins/compile/html.py
Expand Up @@ -29,14 +29,11 @@
from __future__ import unicode_literals

import os
import re
import io

from nikola.plugin_categories import PageCompiler
from nikola.utils import makedirs, write_metadata

_META_SEPARATOR = '(' + os.linesep * 2 + '|' + ('\n' * 2) + '|' + ("\r\n" * 2) + ')'


class CompileHtml(PageCompiler):
"""Compile HTML into HTML."""
Expand All @@ -48,7 +45,7 @@ def compile_html(self, source, dest, is_two_file=True):
with io.open(source, "r", encoding="utf8") as in_file:
data = in_file.read()
if not is_two_file:
data = re.split(_META_SEPARATOR, data, maxsplit=1)[-1]
_, data = self.split_metadata(data)
out_file.write(data)
return True

Expand Down
3 changes: 1 addition & 2 deletions nikola/plugins/compile/markdown/__init__.py
Expand Up @@ -30,7 +30,6 @@

import io
import os
import re

try:
from markdown import markdown
Expand Down Expand Up @@ -76,7 +75,7 @@ def compile_html(self, source, dest, is_two_file=True):
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]
_, data = self.split_metadata(data)
output = markdown(data, self.extensions)
out_file.write(output)

Expand Down
15 changes: 5 additions & 10 deletions nikola/plugins/compile/rest/__init__.py
Expand Up @@ -27,7 +27,6 @@
from __future__ import unicode_literals
import io
import os
import re

import docutils.core
import docutils.nodes
Expand Down Expand Up @@ -62,17 +61,13 @@ def register_extra_dependencies(self, post):

def compile_html_string(self, data, source_path=None, is_two_file=True):
"""Compile reSt into HTML strings."""
# If errors occur, this will be added to the line number reported by
# docutils so the line number matches the actual line number (off by
# 7 with default metadata, could be more or less depending on the post).
add_ln = 0
if not is_two_file:
spl = re.split('(\n\n|\r\n\r\n)', data, maxsplit=1)
data = spl[-1]
if len(spl) != 1:
# If errors occur, this will be added to the line
# number reported by docutils so the line number
# matches the actual line number (off by 7 with default
# metadata, could be more or less depending on the post
# author).
add_ln = len(spl[0].splitlines()) + 1
m_data, data = self.split_metadata(data)
add_ln = len(m_data.splitlines()) + 1

default_template_path = os.path.join(os.path.dirname(__file__), 'template.txt')
output, error_level, deps = rst2html(
Expand Down

0 comments on commit 90ac2ae

Please sign in to comment.