diff --git a/OZprivate/scss/tour.scss b/OZprivate/scss/tour.scss index f16d121e..a00b559f 100644 --- a/OZprivate/scss/tour.scss +++ b/OZprivate/scss/tour.scss @@ -110,6 +110,10 @@ flex-shrink: 10; overflow-y: auto; } + .window_text > p:last-child { + /* Remove margins from final paragraph within window_text */ + margin-bottom: 0; + } .tour_container > iframe, .tour_container > a.embed-image, .tour_container > .embed-audio, .tour_container > .embed-video { flex-grow: 1000; diff --git a/modules/embed.py b/modules/embed.py index 5123ef53..d1dd0bfb 100644 --- a/modules/embed.py +++ b/modules/embed.py @@ -123,7 +123,7 @@ def humanise_url(url): return """
""".format(**opts) + >©""".format(**opts) if m.group(2) in ('ogv', 'webm', 'mpg', 'mpeg'): return """""".format(**opts) + >©""".format(**opts) if m.group(2) in ('ogv', 'webm', 'mpg', 'mpeg'): return """', + 'href="https://commons.wikimedia.org/wiki/File:Turdus_philomelos.ogg">©', ]) self.assertEqual(media_embed('https://commons.wikimedia.org/wiki/File:Intense_bone_fluorescence_reveals_hidden_patterns_in_pumpkin_toadlets_-_video_1_-_41598_2019_41959_MOESM2_ESM.webm'), [ diff --git a/tests/unit/test_modules_markdown.py b/tests/unit/test_modules_markdown.py new file mode 100644 index 00000000..37b32706 --- /dev/null +++ b/tests/unit/test_modules_markdown.py @@ -0,0 +1,42 @@ +""" +Run with:: + + ./web2py-run tests/unit/test_modules_markdown.py + +""" +import re +import unittest + +from gluon.globals import Request +from gluon.http import HTTP + +from applications.OZtree.tests.unit import util + +import markdown + + +class TestMarkdown(unittest.TestCase): + maxDiff = None + + def test_markdown_safemode(self): + """Raw HTML isn't allowed""" + self.assertEqual(markdown.markdown(""" +*Hello there* + +I am in your HTML +""").strip(), """ +Hello there
+ +<b>I am in your HTML</b>
+""".strip()) + +if __name__ == '__main__': + import sys + + if current.globalenv['is_testing'] != True: + raise RuntimeError("Do not run tests in production environments, ensure is_testing = True") + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestMarkdown)) + result = unittest.TextTestRunner(verbosity=2).run(suite) + if not result.wasSuccessful(): + sys.exit(1) diff --git a/views/tour/data.html b/views/tour/data.html index fd4b2a06..5a49c86d 100644 --- a/views/tour/data.html +++ b/views/tour/data.html @@ -1,5 +1,6 @@ {{ from applications.OZtree.modules.embed import media_embed +from applications.OZtree.modules.markdown import markdown ts_classes = ( # CSS classes that can be added to template_data as boolean properties 'visible-transition_in', 'visible-transition_in_wait', @@ -54,8 +55,8 @@ {{for k, tag in ts_fields:}}{{if tdata.get(k, ''):}}{{for value in tdata[k] if isinstance(tdata[k], list) else [tdata[k]]:}} {{content_dict = value if isinstance(value, dict) else dict(text=value)}} - <{{=tag}} class="{{=' '.join(key for key, value in content_dict.items() if value is True)}}" - >{{=T(content_dict['text'])}}{{=tag}}>{{pass}}{{pass}}{{pass}} + <{{=tag}} class="{{=k}} {{=' '.join(key for key, value in content_dict.items() if value is True)}}" + >{{=XML(markdown(content_dict['text']))}}{{=tag}}>{{pass}}{{pass}}{{pass}} {{if len(tdata.get('media', [])) > 0:}}{{for url in tdata['media']:}} {{=XML(media_embed(url, defaults=dict(ts_autoplay='tsstate-active_wait', url_base='https://onezoom.github.io/tours/')))}} {{pass}}{{pass}}