From 67bb12b3e508b389f18efb6a992cc390680a7235 Mon Sep 17 00:00:00 2001 From: WhiteWinterWolf Date: Fri, 8 Sep 2017 13:45:19 +0200 Subject: Add the possibility to set additional classes Additional CSS classes names can be appended to the admonition name using spaces as separators. The following markdown: !!! note floatright This is a floating note. Generates the following HTML code:

Note

This is a floating note.

--- markdown/extensions/admonition.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'markdown') diff --git a/markdown/extensions/admonition.py b/markdown/extensions/admonition.py index 8576638..b001957 100644 --- a/markdown/extensions/admonition.py +++ b/markdown/extensions/admonition.py @@ -41,7 +41,8 @@ class AdmonitionProcessor(BlockProcessor): CLASSNAME = 'admonition' CLASSNAME_TITLE = 'admonition-title' - RE = re.compile(r'(?:^|\n)!!! ?([\w\-]+)(?: +"(.*?)")? *(?:\n|$)') + RE = re.compile(r'(?:^|\n)!!! ?([\w\-]+(?: +[\w\-]+)*)(?: +"(.*?)")? *(?:\n|$)') + RE_SPACES = re.compile(' +') def test(self, parent, block): sibling = self.lastChild(parent) @@ -80,11 +81,12 @@ class AdmonitionProcessor(BlockProcessor): def get_class_and_title(self, match): klass, title = match.group(1).lower(), match.group(2) + klass = self.RE_SPACES.sub(' ', klass) if title is None: # no title was provided, use the capitalized classname as title # e.g.: `!!! note` will render # `

Note

` - title = klass.capitalize() + title = klass.split(' ', 1)[0].capitalize() elif title == '': # an explicit blank title should not be rendered # e.g.: `!!! warning ""` will *not* render `p` with a title -- cgit v1.2.3