diff options
author | WhiteWinterWolf <github@whitewinterwolf.com> | 2017-09-08 13:45:19 +0200 |
---|---|---|
committer | Waylan Limberg <waylan.limberg@icloud.com> | 2018-07-24 14:42:42 -0400 |
commit | 67bb12b3e508b389f18efb6a992cc390680a7235 (patch) | |
tree | f9d45a6eee6e9f93d8ebab8bb20991deb05fec16 /markdown | |
parent | d7764996e4e08faefaf3564fa71c19751847b55f (diff) | |
download | python-markdown-67bb12b3e508b389f18efb6a992cc390680a7235.tar.gz |
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:
<div class="admonition note floatright">
<p class="admonition-title">Note</p>
<p>This is a floating note.</p>
</div>
Diffstat (limited to 'markdown')
-rw-r--r-- | markdown/extensions/admonition.py | 6 |
1 files changed, 4 insertions, 2 deletions
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 # `<p class="admonition-title">Note</p>` - 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 |