aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/compile/markdown
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/plugins/compile/markdown')
-rw-r--r--nikola/plugins/compile/markdown/__init__.py13
-rw-r--r--nikola/plugins/compile/markdown/mdx_gist.plugin17
-rw-r--r--nikola/plugins/compile/markdown/mdx_gist.py68
-rw-r--r--nikola/plugins/compile/markdown/mdx_nikola.plugin17
-rw-r--r--nikola/plugins/compile/markdown/mdx_nikola.py14
-rw-r--r--nikola/plugins/compile/markdown/mdx_podcast.plugin17
-rw-r--r--nikola/plugins/compile/markdown/mdx_podcast.py27
7 files changed, 108 insertions, 65 deletions
diff --git a/nikola/plugins/compile/markdown/__init__.py b/nikola/plugins/compile/markdown/__init__.py
index fbe049d..c1425a1 100644
--- a/nikola/plugins/compile/markdown/__init__.py
+++ b/nikola/plugins/compile/markdown/__init__.py
@@ -44,6 +44,7 @@ from nikola.utils import makedirs, req_missing, write_metadata
class CompileMarkdown(PageCompiler):
+
"""Compile Markdown into HTML."""
name = "markdown"
@@ -53,21 +54,18 @@ class CompileMarkdown(PageCompiler):
site = None
def set_site(self, site):
+ """Set Nikola site."""
+ super(CompileMarkdown, self).set_site(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
+ for plugin_info in self.get_compiler_extensions():
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):
+ """Compile source file into HTML and save as dest."""
if markdown is None:
req_missing(['markdown'], 'build this site (compile Markdown)')
makedirs(os.path.dirname(dest))
@@ -81,6 +79,7 @@ class CompileMarkdown(PageCompiler):
out_file.write(output)
def create_post(self, path, **kw):
+ """Create a new post."""
content = kw.pop('content', None)
onefile = kw.pop('onefile', False)
# is_page is not used by create_post as of now.
diff --git a/nikola/plugins/compile/markdown/mdx_gist.plugin b/nikola/plugins/compile/markdown/mdx_gist.plugin
index 0e5c578..7fe676c 100644
--- a/nikola/plugins/compile/markdown/mdx_gist.plugin
+++ b/nikola/plugins/compile/markdown/mdx_gist.plugin
@@ -1,9 +1,14 @@
[Core]
-Name = mdx_gist
-Module = mdx_gist
+name = mdx_gist
+module = mdx_gist
+
+[Nikola]
+compiler = markdown
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Extension for embedding gists
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Extension for embedding gists
+
diff --git a/nikola/plugins/compile/markdown/mdx_gist.py b/nikola/plugins/compile/markdown/mdx_gist.py
index 70e7394..f439fa2 100644
--- a/nikola/plugins/compile/markdown/mdx_gist.py
+++ b/nikola/plugins/compile/markdown/mdx_gist.py
@@ -26,16 +26,16 @@
#
# Inspired by "[Python] reStructuredText GitHub Gist directive"
# (https://gist.github.com/brianhsu/1407759), public domain by Brian Hsu
-'''
-Extension to Python Markdown for Embedded Gists (gist.github.com)
+"""
+Extension to Python Markdown for Embedded Gists (gist.github.com).
Basic Example:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: 4747847]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -50,10 +50,10 @@ Basic Example:
Example with filename:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: 4747847 zen.py]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -68,10 +68,10 @@ Example with filename:
Basic Example with hexidecimal id:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: c4a43d6fdce612284ac0]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -86,10 +86,10 @@ Basic Example with hexidecimal id:
Example with hexidecimal id filename:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: c4a43d6fdce612284ac0 cow.txt]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -104,10 +104,10 @@ Example with hexidecimal id filename:
Example using reStructuredText syntax:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... .. gist:: 4747847 zen.py
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -122,10 +122,10 @@ Example using reStructuredText syntax:
Example using hexidecimal ID with reStructuredText syntax:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... .. gist:: c4a43d6fdce612284ac0
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -140,10 +140,10 @@ Example using hexidecimal ID with reStructuredText syntax:
Example using hexidecimal ID and filename with reStructuredText syntax:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... .. gist:: c4a43d6fdce612284ac0 cow.txt
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -158,38 +158,36 @@ Example using hexidecimal ID and filename with reStructuredText syntax:
Error Case: non-existent Gist ID:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: 0]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
<div class="gist">
<script src="https://gist.github.com/0.js"></script>
- <noscript><!-- WARNING: Received a 404 response from Gist URL: \
-https://gist.githubusercontent.com/raw/0 --></noscript>
+ <noscript><!-- WARNING: Received a 404 response from Gist URL: https://gist.githubusercontent.com/raw/0 --></noscript>
</div>
</p>
Error Case: non-existent file:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: 4747847 doesntexist.py]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
<div class="gist">
<script src="https://gist.github.com/4747847.js?file=doesntexist.py"></script>
- <noscript><!-- WARNING: Received a 404 response from Gist URL: \
-https://gist.githubusercontent.com/raw/4747847/doesntexist.py --></noscript>
+ <noscript><!-- WARNING: Received a 404 response from Gist URL: https://gist.githubusercontent.com/raw/4747847/doesntexist.py --></noscript>
</div>
</p>
+"""
-'''
from __future__ import unicode_literals, print_function
try:
@@ -219,20 +217,26 @@ GIST_RST_RE = r'(?m)^\.\.\s*gist::\s*(?P<gist_id>[^\]\s]+)(?:\s*(?P<filename>.+?
class GistFetchException(Exception):
- '''Raised when attempt to fetch content of a Gist from github.com fails.'''
+
+ """Raised when attempt to fetch content of a Gist from github.com fails."""
+
def __init__(self, url, status_code):
+ """Initialize the exception."""
Exception.__init__(self)
self.message = 'Received a {0} response from Gist URL: {1}'.format(
status_code, url)
class GistPattern(Pattern):
- """ InlinePattern for footnote markers in a document's body text. """
+
+ """InlinePattern for footnote markers in a document's body text."""
def __init__(self, pattern, configs):
+ """Initialize the pattern."""
Pattern.__init__(self, pattern)
def get_raw_gist_with_filename(self, gist_id, filename):
+ """Get raw gist text for a filename."""
url = GIST_FILE_RAW_URL.format(gist_id, filename)
resp = requests.get(url)
@@ -242,6 +246,7 @@ class GistPattern(Pattern):
return resp.text
def get_raw_gist(self, gist_id):
+ """Get raw gist text."""
url = GIST_RAW_URL.format(gist_id)
resp = requests.get(url)
@@ -251,6 +256,7 @@ class GistPattern(Pattern):
return resp.text
def handleMatch(self, m):
+ """Handle pattern match."""
gist_id = m.group('gist_id')
gist_file = m.group('filename')
@@ -284,7 +290,11 @@ class GistPattern(Pattern):
class GistExtension(MarkdownExtension, Extension):
+
+ """Gist extension for Markdown."""
+
def __init__(self, configs={}):
+ """Initialize the extension."""
# set extension defaults
self.config = {}
@@ -293,6 +303,7 @@ class GistExtension(MarkdownExtension, Extension):
self.setConfig(key, value)
def extendMarkdown(self, md, md_globals):
+ """Extend Markdown."""
gist_md_pattern = GistPattern(GIST_MD_RE, self.getConfigs())
gist_md_pattern.md = md
md.inlinePatterns.add('gist', gist_md_pattern, "<not_strong")
@@ -304,7 +315,8 @@ class GistExtension(MarkdownExtension, Extension):
md.registerExtension(self)
-def makeExtension(configs=None):
+def makeExtension(configs=None): # pragma: no cover
+ """Make Markdown extension."""
return GistExtension(configs)
if __name__ == '__main__':
diff --git a/nikola/plugins/compile/markdown/mdx_nikola.plugin b/nikola/plugins/compile/markdown/mdx_nikola.plugin
index 7af52a4..12e4fb6 100644
--- a/nikola/plugins/compile/markdown/mdx_nikola.plugin
+++ b/nikola/plugins/compile/markdown/mdx_nikola.plugin
@@ -1,9 +1,14 @@
[Core]
-Name = mdx_nikola
-Module = mdx_nikola
+name = mdx_nikola
+module = mdx_nikola
+
+[Nikola]
+compiler = markdown
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Nikola-specific Markdown extensions
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Nikola-specific Markdown extensions
+
diff --git a/nikola/plugins/compile/markdown/mdx_nikola.py b/nikola/plugins/compile/markdown/mdx_nikola.py
index a03547f..54cc18c 100644
--- a/nikola/plugins/compile/markdown/mdx_nikola.py
+++ b/nikola/plugins/compile/markdown/mdx_nikola.py
@@ -24,7 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-"""Markdown Extension for Nikola-specific post-processing"""
+"""Markdown Extension for Nikola-specific post-processing."""
+
from __future__ import unicode_literals
import re
try:
@@ -41,7 +42,11 @@ CODERE = re.compile('<div class="codehilite"><pre>(.*?)</pre></div>', flags=re.M
class NikolaPostProcessor(Postprocessor):
+
+ """Nikola-specific post-processing for Markdown."""
+
def run(self, text):
+ """Run the postprocessor."""
output = text
# python-markdown's highlighter uses <div class="codehilite"><pre>
@@ -52,11 +57,16 @@ class NikolaPostProcessor(Postprocessor):
class NikolaExtension(MarkdownExtension, Extension):
+
+ """Extension for injecting the postprocessor."""
+
def extendMarkdown(self, md, md_globals):
+ """Extend Markdown with the postprocessor."""
pp = NikolaPostProcessor()
md.postprocessors.add('nikola_post_processor', pp, '_end')
md.registerExtension(self)
-def makeExtension(configs=None):
+def makeExtension(configs=None): # pragma: no cover
+ """Make extension."""
return NikolaExtension(configs)
diff --git a/nikola/plugins/compile/markdown/mdx_podcast.plugin b/nikola/plugins/compile/markdown/mdx_podcast.plugin
index dc16044..c92a8a0 100644
--- a/nikola/plugins/compile/markdown/mdx_podcast.plugin
+++ b/nikola/plugins/compile/markdown/mdx_podcast.plugin
@@ -1,9 +1,14 @@
[Core]
-Name = mdx_podcast
-Module = mdx_podcast
+name = mdx_podcast
+module = mdx_podcast
+
+[Nikola]
+compiler = markdown
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Markdown extensions for embedding podcasts and other audio files
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Markdown extensions for embedding podcasts and other audio files
+
diff --git a/nikola/plugins/compile/markdown/mdx_podcast.py b/nikola/plugins/compile/markdown/mdx_podcast.py
index 670973a..61afdbf 100644
--- a/nikola/plugins/compile/markdown/mdx_podcast.py
+++ b/nikola/plugins/compile/markdown/mdx_podcast.py
@@ -24,21 +24,19 @@
# Inspired by "[Python] reStructuredText GitHub Podcast directive"
# (https://gist.github.com/brianhsu/1407759), public domain by Brian Hsu
-from __future__ import print_function, unicode_literals
-
-
-'''
-Extension to Python Markdown for Embedded Audio
+"""
+Extension to Python Markdown for Embedded Audio.
Basic Example:
>>> import markdown
->>> text = """[podcast]http://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3[/podcast]"""
+>>> text = "[podcast]http://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3[/podcast]"
>>> html = markdown.markdown(text, [PodcastExtension()])
>>> print(html)
-<p><audio src="http://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3"></audio></p>
-'''
+<p><audio controls=""><source src="http://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3" type="audio/mpeg"></source></audio></p>
+"""
+from __future__ import print_function, unicode_literals
from nikola.plugin_categories import MarkdownExtension
try:
from markdown.extensions import Extension
@@ -53,12 +51,15 @@ PODCAST_RE = r'\[podcast\](?P<url>.+)\[/podcast\]'
class PodcastPattern(Pattern):
- """ InlinePattern for footnote markers in a document's body text. """
+
+ """InlinePattern for footnote markers in a document's body text."""
def __init__(self, pattern, configs):
+ """Initialize pattern."""
Pattern.__init__(self, pattern)
def handleMatch(self, m):
+ """Handle pattern matches."""
url = m.group('url').strip()
audio_elem = etree.Element('audio')
audio_elem.set('controls', '')
@@ -69,7 +70,11 @@ class PodcastPattern(Pattern):
class PodcastExtension(MarkdownExtension, Extension):
+
+ """"Podcast extension for Markdown."""
+
def __init__(self, configs={}):
+ """Initialize extension."""
# set extension defaults
self.config = {}
@@ -78,13 +83,15 @@ class PodcastExtension(MarkdownExtension, Extension):
self.setConfig(key, value)
def extendMarkdown(self, md, md_globals):
+ """Extend Markdown."""
podcast_md_pattern = PodcastPattern(PODCAST_RE, self.getConfigs())
podcast_md_pattern.md = md
md.inlinePatterns.add('podcast', podcast_md_pattern, "<not_strong")
md.registerExtension(self)
-def makeExtension(configs=None):
+def makeExtension(configs=None): # pragma: no cover
+ """Make Markdown extension."""
return PodcastExtension(configs)
if __name__ == '__main__':