diff --git a/landslide/generator.py b/landslide/generator.py index ed8bed2..0e44ec6 100644 --- a/landslide/generator.py +++ b/landslide/generator.py @@ -36,6 +36,7 @@ class Generator(object): macro_module.FxMacro, macro_module.NotesMacro, macro_module.QRMacro, + macro_module.AlertMacro, ] user_css = [] user_js = [] diff --git a/landslide/macro.py b/landslide/macro.py index 746b4f8..7ae0bd2 100644 --- a/landslide/macro.py +++ b/landslide/macro.py @@ -171,3 +171,16 @@ def process(self, content, source=None): classes.append(u'has_qr') return new_content, classes + +class AlertMacro(Macro): + """Adds 3 types of alerts: .info:, .success:, .danger""" + + def process(self, content, source=None): + classes = [] + + new_content = re.sub(r'

\.(info|success|danger):\s?(.*?)

', r'

\2

', content) + + if content != new_content: + classes.append(u'has_alert') + + return new_content, classes diff --git a/tests.py b/tests.py index 77d9823..0b0b3f6 100644 --- a/tests.py +++ b/tests.py @@ -109,6 +109,19 @@ def test_process_macros(self): self.assertEqual(r[1][0], 'blah') self.assertEqual(r[1][1], 'blob') + def test_macro_alert(self): + g = Generator(os.path.join(DATA_DIR, 'test.md')) + # .info + r = g.process_macros('

foo

\n

.info: bar

\n

baz

') + self.assertEqual(r[0].find('

bar

'), 11) + self.assertEqual(r[1], [u'has_alert']) + + # .danger + r = g.process_macros('

foo

\n

.danger: bar

\n

baz

') + self.assertEqual(r[0].find('

bar

'), 11) + self.assertEqual(r[1], [u'has_alert']) + + def test_register_macro(self): g = Generator(os.path.join(DATA_DIR, 'test.md'))