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

@@ -1,12 +1,9 @@
import copy
from pillar.tests import AbstractPillarTest
from pillar.tests import common_test_data as ctd
class CoerceMarkdownTest(AbstractPillarTest):
def test_node_description(self):
from pillar.markdown import markdown
pid, uid = self.create_project_with_admin(24 * 'a')
self.create_valid_auth_token(uid, 'token-a')
node = {
@@ -23,10 +20,10 @@ class CoerceMarkdownTest(AbstractPillarTest):
node_id = created_data['_id']
json_node = self.get(f'/api/nodes/{node_id}', auth_token='token-a').json()
self.assertEqual(markdown(node['description']), json_node['_description_html'])
self.assertEqual('<h1>Title</h1>\n<p>This is content.</p>\n',
json_node['_description_html'])
def test_project_description(self):
from pillar.markdown import markdown
from pillar.api.utils import remove_private_keys
uid = self.create_user(24 * 'a', token='token-a')
@@ -50,4 +47,25 @@ class CoerceMarkdownTest(AbstractPillarTest):
json_proj.pop('node_types', None) # just to make it easier to print
import pprint
pprint.pprint(json_proj)
self.assertEqual(markdown(proj['description']), json_proj['_description_html'])
self.assertEqual('<h1>Title</h1>\n<p>This is content.</p>\n',
json_proj['_description_html'])
def test_comment_shortcodes(self):
pid, uid = self.create_project_with_admin(24 * 'a')
self.create_valid_auth_token(uid, 'token-a')
node = {
'node_type': 'group',
'name': 'Test group',
'description': '# Title\n\n{test a="b"}',
'properties': {},
'project': pid,
'user': uid,
}
created_data = self.post('/api/nodes', json=node, expected_status=201,
auth_token='token-a').json()
node_id = created_data['_id']
json_node = self.get(f'/api/nodes/{node_id}', auth_token='token-a').json()
expect = '<h1>Title</h1>\n<!-- {test a="b"} -->\n'
self.assertEqual(expect, json_node['_description_html'])