From 99e734cb71f26d2a3cafa71a6f6373fbb0c8fda5 Mon Sep 17 00:00:00 2001 From: Jeff Dairiki Date: Thu, 16 Oct 2014 06:56:43 -0700 Subject: [PATCH 1/2] Add tests for abbr_role. Refs #949 --- pelican/tests/test_rstdirectives.py | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pelican/tests/test_rstdirectives.py diff --git a/pelican/tests/test_rstdirectives.py b/pelican/tests/test_rstdirectives.py new file mode 100644 index 00000000..ae863b30 --- /dev/null +++ b/pelican/tests/test_rstdirectives.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals, print_function + +from mock import Mock +from pelican.tests.support import unittest + +class Test_abbr_role(unittest.TestCase): + def call_it(self, text): + from pelican.rstdirectives import abbr_role + rawtext = text + lineno = 42 + inliner = Mock(name='inliner') + nodes, system_messages = abbr_role( + 'abbr', rawtext, text, lineno, inliner) + self.assertEqual(system_messages, []) + self.assertEqual(len(nodes), 1) + return nodes[0] + + def test(self): + node = self.call_it("Abbr (Abbreviation)") + self.assertEqual(node.astext(), "Abbr") + self.assertEqual(node['explanation'], "Abbreviation") + + def test_newlines_in_explanation(self): + node = self.call_it("CUL (See you\nlater)") + self.assertEqual(node.astext(), "CUL") + self.assertEqual(node['explanation'], "See you\nlater") + + def test_newlines_in_abbr(self): + node = self.call_it("US of\nA \n (USA)") + self.assertEqual(node.astext(), "US of\nA") + self.assertEqual(node['explanation'], "USA") From 10c0002af1ac347d378cba6393120c4fec41c19c Mon Sep 17 00:00:00 2001 From: Jeff Dairiki Date: Thu, 16 Oct 2014 06:59:32 -0700 Subject: [PATCH 2/2] Fix bug with custom reST :abbr: role. Fixes #949 This fixes things so that newlines are allowed within the explanation of an :abbr: role in reST mark-up. --- pelican/rstdirectives.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/rstdirectives.py b/pelican/rstdirectives.py index 1bf6971c..1c25cc42 100644 --- a/pelican/rstdirectives.py +++ b/pelican/rstdirectives.py @@ -70,7 +70,7 @@ directives.register_directive('code-block', Pygments) directives.register_directive('sourcecode', Pygments) -_abbr_re = re.compile('\((.*)\)$') +_abbr_re = re.compile('\((.*)\)$', re.DOTALL) class abbreviation(nodes.Inline, nodes.TextElement):