From: Vladimír Vondruš Date: Sat, 19 May 2018 11:31:02 +0000 (+0200) Subject: m.code: don't blow up if inline literal doesn't have language. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=c33a060ac7ad0b4e8001997894b0e01db15db543;p=blog.git m.code: don't blow up if inline literal doesn't have language. --- diff --git a/pelican-plugins/m/code.py b/pelican-plugins/m/code.py index 4bf996d3..cc999e9e 100644 --- a/pelican-plugins/m/code.py +++ b/pelican-plugins/m/code.py @@ -183,9 +183,16 @@ def code(role, rawtext, text, lineno, inliner, options={}, content=[]): classes += options['classes'] del options['classes'] - # Not sure why language is duplicated in classes? - language = options.get('language', '') + # If language is not specified, render a simple literal + if not 'language' in options: + content = nodes.raw('', utils.unescape(text), format='html') + node = nodes.literal(rawtext, '', **options) + node.append(content) + return [node], [] + + language = options['language'] del options['language'] + # Not sure why language is duplicated in classes? if language in classes: classes.remove(language) class_, highlighted = _highlight(utils.unescape(text), language, options) diff --git a/pelican-plugins/m/test/code/page.html b/pelican-plugins/m/test/code/page.html index 16406a9d..6be7cc2e 100644 --- a/pelican-plugins/m/test/code/page.html +++ b/pelican-plugins/m/test/code/page.html @@ -29,7 +29,8 @@
int main() {
     return 1;
 }
-

Inline code is here: constexpr

+

Inline code is here: constexpr. Code without a language should be +rendered as plain monospace text: code.

![mosra@don-perverzo m.css]$ ls
 CONTRIBUTING.rst  CREDITS.rst  doc      pelican-plugins  README.rst
 COPYING           css          doxygen  pelican-theme    site
diff --git a/pelican-plugins/m/test/code/page.rst b/pelican-plugins/m/test/code/page.rst index 7cccd0a8..48c5906a 100644 --- a/pelican-plugins/m/test/code/page.rst +++ b/pelican-plugins/m/test/code/page.rst @@ -20,7 +20,8 @@ m.code return 1; } -Inline code is here: :cpp:`constexpr` +Inline code is here: :cpp:`constexpr`. Code without a language should be +rendered as plain monospace text: :code:`code`. .. include:: console.ansi :code: ansi