From 0401703936f10a111c0937ec5d285af6754b50c3 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 4 Feb 2020 17:13:42 +0100 Subject: [PATCH 1/4] markdown: Disable Codehilite language guessing It appears that for random text the MIME lexer wins: In [4]: import pygments.lexer In [5]: pygments.lexers.guess_lexer("Hallo") Out[5]: which usually generates errors for random text: In [11]: from markdown.extensions.codehilite import CodeHilite In [12]: CodeHilite(src = 'Hallo').hilite() Out[12]: '
Hallo\n
\n' which just look ugly (red border on each line). So switch off language guessing. In that case, code blocks without a explicit language are left as is: In [13]: CodeHilite(src = 'Hallo',guess_lang=False).hilite() Out[13]: '
Hallo\n
\n' In Markdown, the language should be set explicitly, for language specific highlighting. :::python print("Hallo") --- mpicms/base/templatetags/md_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpicms/base/templatetags/md_tags.py b/mpicms/base/templatetags/md_tags.py index 1742044..7cc51ec 100644 --- a/mpicms/base/templatetags/md_tags.py +++ b/mpicms/base/templatetags/md_tags.py @@ -19,7 +19,7 @@ def markdown(text): md_processor = md_module.Markdown( extensions=[ ExtraExtension(), - CodeHiliteExtension(), + CodeHiliteExtension(guess_lang=False), Nl2BrExtension(), SaneListExtension(), SmartyExtension(smart_angled_quotes=True), From 2eb5d43ebad98442646cc1200437262d3793a1f1 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 4 Feb 2020 18:57:32 +0100 Subject: [PATCH 2/4] custom.css: Add vertical space after code The bulma style sets margin-bottom to 1em for several block-level elements (eg

). However the codehilite

s, generated by the codehilite Markdown extension don't have that. So we have 1em vertical space before a code block but not after, which just looks wrong. Add vertical space after codehilite
s. --- mpicms/static/css/custom.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mpicms/static/css/custom.css b/mpicms/static/css/custom.css index 62ff3a4..323b80b 100644 --- a/mpicms/static/css/custom.css +++ b/mpicms/static/css/custom.css @@ -736,3 +736,7 @@ a.tag:hover { .modal-image:hover, .richtext-image:hover { cursor: pointer; } + +div.codehilite:not(:last-child) { + margin-bottom: 1em; +} From 9e8f0b3e6eb8172eb40e623dcaddeec6dfe3b2bb Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 4 Feb 2020 19:18:20 +0100 Subject: [PATCH 3/4] Markdown: Add Admonition Add Admonition extension which allows to add class attributes and a title to a block. So !!!alert "Red Alert" Warp core breach becomes

Red Alert

Warp core breach

--- mpicms/base/templatetags/md_tags.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mpicms/base/templatetags/md_tags.py b/mpicms/base/templatetags/md_tags.py index 7cc51ec..ceef597 100644 --- a/mpicms/base/templatetags/md_tags.py +++ b/mpicms/base/templatetags/md_tags.py @@ -4,6 +4,7 @@ from markdown.extensions.nl2br import Nl2BrExtension from markdown.extensions.sane_lists import SaneListExtension from markdown.extensions.smarty import SmartyExtension +from markdown.extensions.admonition import AdmonitionExtension from markdown.extensions.toc import TocExtension from django import template @@ -23,6 +24,7 @@ def markdown(text): Nl2BrExtension(), SaneListExtension(), SmartyExtension(smart_angled_quotes=True), + AdmonitionExtension(), TocExtension(), ] ) From 455abb1ab1a6ef9351293241d3a57f5f309c70b7 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Tue, 4 Feb 2020 21:45:27 +0100 Subject: [PATCH 4/4] Markdown: Use monospace font for editor Add inline style to wagtailadmin/pages/edit.html to force the markdown textarea to monospaced font. --- mpicms/templates/wagtailadmin/pages/edit.html | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 mpicms/templates/wagtailadmin/pages/edit.html diff --git a/mpicms/templates/wagtailadmin/pages/edit.html b/mpicms/templates/wagtailadmin/pages/edit.html new file mode 100644 index 0000000..be8b615 --- /dev/null +++ b/mpicms/templates/wagtailadmin/pages/edit.html @@ -0,0 +1,9 @@ +{% extends "wagtailadmin/pages/edit.html" %} +{% block extra_css %} +{{ block.super }} + +{% endblock %}