Shortcodes for YouTube and iframes

Added shortcodes 2.5.0 as dependency; Earlier versions corrupted
non-ASCII characters, see
https://github.com/dmulholland/shortcodes/issues/6

The rendered elements have a `shortcode` CSS class.

The YouTube shortcode supports various ways to refer to a video:

    - `{youtube VideoID}`
    - `{youtube youtube.com or youtu.be URL}`

URLs containing an '=' should be quoted, or otherwise the shortcodes
library will parse it as "key=value" pair.

The IFrame shortcode supports the `cap` and `nocap` attributes. `cap`
indicates the required capability the user should have in order to
render the tag. If `nocap` is given, its contents are shown as a message
to users who do not have this tag; without it, the iframe is silently
hidden.

`{iframe src='https://source' cap='subscriber' nocap='Subscribe to view'}`

Merged test code + added HTML class for shortcode iframes
This commit is contained in:
2018-03-26 11:58:09 +02:00
parent 0841d52dd1
commit f4e0b9185b
9 changed files with 443 additions and 23 deletions

View File

@@ -23,9 +23,21 @@ class MarkdownTest(unittest.TestCase):
def test_markdowned(self):
from pillar.web import jinja
self.assertEqual(None, jinja.do_markdowned({'eek': None}, 'eek'))
self.assertEqual('', jinja.do_markdowned({'eek': None}, 'eek'))
self.assertEqual('<p>ook</p>\n', jinja.do_markdowned({'eek': 'ook'}, 'eek'))
self.assertEqual('<p>ook</p>\n', jinja.do_markdowned(
{'eek': 'ook', '_eek_html': None}, 'eek'))
self.assertEqual('prerendered', jinja.do_markdowned(
{'eek': 'ook', '_eek_html': 'prerendered'}, 'eek'))
def test_markdowned_with_shortcodes(self):
from pillar.web import jinja
self.assertEqual(
'<dl><dt>test</dt><dt>a</dt><dd>b</dd><dt>c</dt><dd>d</dd></dl>\n',
jinja.do_markdowned({'eek': '{test a="b" c="d"}'}, 'eek'))
self.assertEqual(
'<h1>Title</h1>\n<p>Before</p>\n'
'<dl><dt>test</dt><dt>a</dt><dd>b</dd><dt>c</dt><dd>d</dd></dl>\n',
jinja.do_markdowned({'eek': '# Title\n\nBefore\n{test a="b" c="d"}'}, 'eek'))