aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/compile/markdown
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2015-07-08 07:35:06 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2015-07-08 07:35:06 -0300
commit055d72d76b44b0e627c8a17c48dbecd62e44197b (patch)
treee2c8d5475477c46115461fe9547c1ee797873635 /nikola/plugins/compile/markdown
parent61f3aad02cd6492cb38e41b66f2ed8ec56e98981 (diff)
parentb0b24795b24ee6809397fbbadf42f31f310a219f (diff)
Merge tag 'upstream/7.6.0'
Upstream version 7.6.0
Diffstat (limited to 'nikola/plugins/compile/markdown')
-rw-r--r--nikola/plugins/compile/markdown/__init__.py12
-rw-r--r--nikola/plugins/compile/markdown/mdx_gist.py48
-rw-r--r--nikola/plugins/compile/markdown/mdx_nikola.py4
-rw-r--r--nikola/plugins/compile/markdown/mdx_podcast.py2
4 files changed, 30 insertions, 36 deletions
diff --git a/nikola/plugins/compile/markdown/__init__.py b/nikola/plugins/compile/markdown/__init__.py
index 47c7c9b..fbe049d 100644
--- a/nikola/plugins/compile/markdown/__init__.py
+++ b/nikola/plugins/compile/markdown/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright © 2012-2014 Roberto Alsina and others.
+# Copyright © 2012-2015 Roberto Alsina and others.
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
@@ -30,7 +30,6 @@ from __future__ import unicode_literals
import io
import os
-import re
try:
from markdown import markdown
@@ -45,24 +44,27 @@ from nikola.utils import makedirs, req_missing, write_metadata
class CompileMarkdown(PageCompiler):
- """Compile markdown into HTML."""
+ """Compile Markdown into HTML."""
name = "markdown"
+ friendly_name = "Markdown"
demote_headers = True
extensions = []
site = None
def set_site(self, site):
+ self.config_dependencies = []
for plugin_info in site.plugin_manager.getPluginsOfCategory("MarkdownExtension"):
if plugin_info.name in site.config['DISABLED_PLUGINS']:
site.plugin_manager.removePluginFromCategory(plugin_info, "MarkdownExtension")
continue
-
+ self.config_dependencies.append(plugin_info.name)
site.plugin_manager.activatePluginByName(plugin_info.name)
plugin_info.plugin_object.set_site(site)
self.extensions.append(plugin_info.plugin_object)
plugin_info.plugin_object.short_help = plugin_info.description
+ self.config_dependencies.append(str(sorted(site.config.get("MARKDOWN_EXTENSIONS"))))
return super(CompileMarkdown, self).set_site(site)
def compile_html(self, source, dest, is_two_file=True):
@@ -74,7 +76,7 @@ class CompileMarkdown(PageCompiler):
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)
diff --git a/nikola/plugins/compile/markdown/mdx_gist.py b/nikola/plugins/compile/markdown/mdx_gist.py
index 4209bdd..70e7394 100644
--- a/nikola/plugins/compile/markdown/mdx_gist.py
+++ b/nikola/plugins/compile/markdown/mdx_gist.py
@@ -203,14 +203,11 @@ except ImportError:
Extension = Pattern = object
from nikola.plugin_categories import MarkdownExtension
-from nikola.utils import get_logger, req_missing, STDERR_HANDLER
+from nikola.utils import get_logger, STDERR_HANDLER
-LOGGER = get_logger('compile_markdown.mdx_gist', STDERR_HANDLER)
+import requests
-try:
- import requests
-except ImportError:
- requests = None # NOQA
+LOGGER = get_logger('compile_markdown.mdx_gist', STDERR_HANDLER)
GIST_JS_URL = "https://gist.github.com/{0}.js"
GIST_FILE_JS_URL = "https://gist.github.com/{0}.js?file={1}"
@@ -261,32 +258,27 @@ class GistPattern(Pattern):
gist_elem.set('class', 'gist')
script_elem = etree.SubElement(gist_elem, 'script')
- if requests:
- noscript_elem = etree.SubElement(gist_elem, 'noscript')
-
- try:
- if gist_file:
- script_elem.set('src', GIST_FILE_JS_URL.format(
- gist_id, gist_file))
- raw_gist = (self.get_raw_gist_with_filename(
- gist_id, gist_file))
+ noscript_elem = etree.SubElement(gist_elem, 'noscript')
- else:
- script_elem.set('src', GIST_JS_URL.format(
- gist_id))
- raw_gist = (self.get_raw_gist(gist_id))
+ try:
+ if gist_file:
+ script_elem.set('src', GIST_FILE_JS_URL.format(
+ gist_id, gist_file))
+ raw_gist = (self.get_raw_gist_with_filename(
+ gist_id, gist_file))
- # Insert source as <pre/> within <noscript>
- pre_elem = etree.SubElement(noscript_elem, 'pre')
- pre_elem.text = AtomicString(raw_gist)
+ else:
+ script_elem.set('src', GIST_JS_URL.format(gist_id))
+ raw_gist = (self.get_raw_gist(gist_id))
- except GistFetchException as e:
- LOGGER.warn(e.message)
- warning_comment = etree.Comment(' WARNING: {0} '.format(e.message))
- noscript_elem.append(warning_comment)
+ # Insert source as <pre/> within <noscript>
+ pre_elem = etree.SubElement(noscript_elem, 'pre')
+ pre_elem.text = AtomicString(raw_gist)
- else:
- req_missing('requests', 'have inline gist source', optional=True)
+ except GistFetchException as e:
+ LOGGER.warn(e.message)
+ warning_comment = etree.Comment(' WARNING: {0} '.format(e.message))
+ noscript_elem.append(warning_comment)
return gist_elem
diff --git a/nikola/plugins/compile/markdown/mdx_nikola.py b/nikola/plugins/compile/markdown/mdx_nikola.py
index ca67511..a03547f 100644
--- a/nikola/plugins/compile/markdown/mdx_nikola.py
+++ b/nikola/plugins/compile/markdown/mdx_nikola.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright © 2012-2014 Roberto Alsina and others.
+# Copyright © 2012-2015 Roberto Alsina and others.
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
@@ -37,7 +37,6 @@ except ImportError:
from nikola.plugin_categories import MarkdownExtension
-# FIXME: duplicated with listings.py
CODERE = re.compile('<div class="codehilite"><pre>(.*?)</pre></div>', flags=re.MULTILINE | re.DOTALL)
@@ -47,6 +46,7 @@ class NikolaPostProcessor(Postprocessor):
# python-markdown's highlighter uses <div class="codehilite"><pre>
# for code. We switch it to reST's <pre class="code">.
+ # TODO: monkey-patch for CodeHilite that uses nikola.utils.NikolaPygmentsHTML
output = CODERE.sub('<pre class="code literal-block">\\1</pre>', output)
return output
diff --git a/nikola/plugins/compile/markdown/mdx_podcast.py b/nikola/plugins/compile/markdown/mdx_podcast.py
index 9a67910..670973a 100644
--- a/nikola/plugins/compile/markdown/mdx_podcast.py
+++ b/nikola/plugins/compile/markdown/mdx_podcast.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# Copyright © 2013-2014 Michael Rabbitt, Roberto Alsina and others.
+# Copyright © 2013-2015 Michael Rabbitt, Roberto Alsina and others.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the