Skip to content
Permalink
Browse files

Implement media rst directive as shortcode for markdown (Issue #2170)

  • Loading branch information
ralsina committed Feb 14, 2016
1 parent 7638ac8 commit 3a67fc6d1c2e74e180159664cbf9553147c4d756
Showing with 26 additions and 6 deletions.
  1. +8 −0 CHANGES.txt
  2. +7 −0 docs/manual.txt
  3. +10 −6 nikola/plugins/compile/rest/media.py
  4. +1 −0 nikola/shortcodes.py
@@ -1,3 +1,11 @@
New in master
=============

Features
--------

* New Oembed-based media shortcode (Issue #2170)

New in v7.7.5
=============

@@ -828,6 +828,13 @@ Built-in shortcodes

post-list
Will show a list of posts, see the `Post List directive for details <#post-list>`__

media
Display media embedded from a URL, for example, this will embed a youtube video::

{{% media https://www.youtube.com/watch?v=Nck6BZga7TQ %}}

In restructured text this shortcode will fail because docutils turns that URL to a link and everything breaks, use the `media directive <#media>`__ instead.


Template-based shortcodes
@@ -48,6 +48,7 @@ def set_site(self, site):
"""Set Nikola site."""
self.site = site
directives.register_directive('media', Media)
self.site.register_shortcode('media', _gen_html)
return super(Plugin, self).set_site(site)


@@ -60,9 +61,12 @@ 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')]

providers = micawber.bootstrap_basic()
return [nodes.raw('', micawber.parse_text(" ".join(self.arguments), providers), format='html')]
html = _gen_html(" ".join(self.arguments))
return [nodes.raw('', html, format='html')]

def _gen_html(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)
@@ -186,6 +186,7 @@ def _parse_shortcode_args(data, start, shortcode_name, start_pos):
try:
pos = _skip_whitespace(data, pos, must_be_nontrivial=True)
except ParsingError:
from doit.tools import set_trace; set_trace()
if not args and not kwargs:
raise ParsingError("Shortcode '{0}' starting at {1} is not terminated correctly with '%}}}}'!".format(shortcode_name, _format_position(data, start_pos)))
else:

0 comments on commit 3a67fc6

Please sign in to comment.