aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/compile/rest/media.py
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/plugins/compile/rest/media.py')
-rw-r--r--nikola/plugins/compile/rest/media.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/nikola/plugins/compile/rest/media.py b/nikola/plugins/compile/rest/media.py
index 345e331..8a69586 100644
--- a/nikola/plugins/compile/rest/media.py
+++ b/nikola/plugins/compile/rest/media.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright © 2012-2015 Roberto Alsina and others.
+# Copyright © 2012-2016 Roberto Alsina and others.
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
@@ -40,7 +40,6 @@ from nikola.utils import req_missing
class Plugin(RestExtension):
-
"""Plugin for reST media directive."""
name = "rest_media"
@@ -49,11 +48,11 @@ class Plugin(RestExtension):
"""Set Nikola site."""
self.site = site
directives.register_directive('media', Media)
+ self.site.register_shortcode('media', _gen_media_embed)
return super(Plugin, self).set_site(site)
class Media(Directive):
-
"""reST extension for inserting any sort of media using micawber."""
has_content = False
@@ -62,9 +61,13 @@ class Media(Directive):
def run(self):
"""Run media directive."""
- if micawber is None:
- msg = req_missing(['micawber'], 'use the media directive', optional=True)
- return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]
+ html = _gen_media_embed(" ".join(self.arguments))
+ return [nodes.raw('', html, format='html')]
+
- providers = micawber.bootstrap_basic()
- return [nodes.raw('', micawber.parse_text(" ".join(self.arguments), providers), format='html')]
+def _gen_media_embed(url, *q, **kw):
+ if micawber is None:
+ msg = req_missing(['micawber'], 'use the media directive', optional=True)
+ return '<div class="text-error">{0}</div>'.format(msg)
+ providers = micawber.bootstrap_basic()
+ return micawber.parse_text(url, providers)