summaryrefslogtreecommitdiff
path: root/markdown/extensions
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2020-10-08 13:18:28 -0400
committerGitHub <noreply@github.com>2020-10-08 13:18:28 -0400
commitc0b1dc5d315624799ac1ba380eced9838e7f4bca (patch)
tree90383350bcfc72c1d16ee3f660e4738bb47f6825 /markdown/extensions
parentc2904eac1a6daf8a3aaef6af0791b101e1971544 (diff)
downloadpython-markdown-c0b1dc5d315624799ac1ba380eced9838e7f4bca.tar.gz
Ensure consistent handling of classes by fenced_code and codehilite (#1033)
* All non-language classes should always be assigned to the pre tag. * The language identifying class should never be included with the general list of classes. Fixes #1032
Diffstat (limited to 'markdown/extensions')
-rw-r--r--markdown/extensions/fenced_code.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py
index e3b3f1b..716b467 100644
--- a/markdown/extensions/fenced_code.py
+++ b/markdown/extensions/fenced_code.py
@@ -88,11 +88,10 @@ class FencedBlockPreprocessor(Preprocessor):
if m.group('attrs'):
id, classes, config = self.handle_attrs(get_attrs(m.group('attrs')))
if len(classes):
- lang = classes[0]
+ lang = classes.pop(0)
else:
if m.group('lang'):
lang = m.group('lang')
- classes.append(lang)
if m.group('hl_lines'):
# Support hl_lines outside of attrs for backward-compatibility
config['hl_lines'] = parse_hl_lines(m.group('hl_lines'))
@@ -119,12 +118,11 @@ class FencedBlockPreprocessor(Preprocessor):
code = highliter.hilite()
else:
- id_attr = class_attr = kv_pairs = ''
+ id_attr = lang_attr = class_attr = kv_pairs = ''
+ if lang:
+ lang_attr = ' class="{}{}"'.format(self.config.get('lang_prefix', 'language-'), lang)
if classes:
- class_attr = ' class="{}{}"'.format(
- self.config.get('lang_prefix', 'language-'),
- ' '.join(classes)
- )
+ class_attr = ' class="{}"'.format(' '.join(classes))
if id:
id_attr = ' id="{}"'.format(id)
if self.use_attr_list and config and not config.get('use_pygments', False):
@@ -134,9 +132,10 @@ class FencedBlockPreprocessor(Preprocessor):
kv_pairs = ' ' + ' '.join(
'{k}="{v}"'.format(k=k, v=v) for k, v in config.items() if k != 'use_pygments'
)
- code = '<pre{id}><code{cls}{kv}>{code}</code></pre>'.format(
+ code = '<pre{id}{cls}><code{lang}{kv}>{code}</code></pre>'.format(
id=id_attr,
cls=class_attr,
+ lang=lang_attr,
kv=kv_pairs,
code=self._escape(m.group('code'))
)