Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new AlertMacro #225

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions landslide/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Generator(object):
macro_module.FxMacro,
macro_module.NotesMacro,
macro_module.QRMacro,
macro_module.AlertMacro,
]
user_css = []
user_js = []
Expand Down
13 changes: 13 additions & 0 deletions landslide/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<p>\.(info|success|danger):\s?(.*?)</p>', r'<p class="alert alert-\1">\2</p>', content)

if content != new_content:
classes.append(u'has_alert')

return new_content, classes
13 changes: 13 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p>foo</p>\n<p>.info: bar</p>\n<p>baz</p>')
self.assertEqual(r[0].find('<p class="alert alert-info">bar</p>'), 11)
self.assertEqual(r[1], [u'has_alert'])

# .danger
r = g.process_macros('<p>foo</p>\n<p>.danger: bar</p>\n<p>baz</p>')
self.assertEqual(r[0].find('<p class="alert alert-danger">bar</p>'), 11)
self.assertEqual(r[1], [u'has_alert'])


def test_register_macro(self):
g = Generator(os.path.join(DATA_DIR, 'test.md'))

Expand Down