From 6c170cccddda4df6b80fabbc7d1be683e27c7519 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Mon, 31 Oct 2022 22:26:26 -0500 Subject: [PATCH] Add markdown for sample --- judge/jinja2/markdown/__init__.py | 17 ++++++++++++++++- resources/content-description.scss | 9 +++++++++ resources/pagedown/Markdown.Editor.js | 2 -- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/judge/jinja2/markdown/__init__.py b/judge/jinja2/markdown/__init__.py index eecb402..fde9a00 100644 --- a/judge/jinja2/markdown/__init__.py +++ b/judge/jinja2/markdown/__init__.py @@ -3,6 +3,7 @@ import markdown as _markdown import bleach from django.utils.html import escape from bs4 import BeautifulSoup +from pymdownx import superfences EXTENSIONS = [ @@ -22,6 +23,18 @@ EXTENSIONS = [ "mdx_breakless_lists", ] +EXTENSION_CONFIGS = { + "pymdownx.superfences": { + "custom_fences": [ + { + "name": "sample", + "class": "no-border", + "format": superfences.fence_code_format, + } + ] + }, +} + ALLOWED_TAGS = bleach.sanitizer.ALLOWED_TAGS + [ "img", "center", @@ -60,7 +73,9 @@ ALLOWED_ATTRS = ["src", "width", "height", "href", "class", "open"] @registry.filter def markdown(value, lazy_load=False): extensions = EXTENSIONS - html = _markdown.markdown(value, extensions=extensions) + html = _markdown.markdown( + value, extensions=extensions, extension_configs=EXTENSION_CONFIGS + ) html = bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS) if not html: html = escape(value) diff --git a/resources/content-description.scss b/resources/content-description.scss index d380596..bb09700 100644 --- a/resources/content-description.scss +++ b/resources/content-description.scss @@ -37,6 +37,7 @@ background: transparent; font-size: 1em; color: black; + } white-space: pre-wrap; @@ -49,6 +50,14 @@ border-radius: $widget_border_radius; } + pre.no-border { + margin-top: -0.7em; + padding: 0.5em; + border: none; + background-color: inherit; + border-radius: none; + } + b, strong { font-weight: bold; } diff --git a/resources/pagedown/Markdown.Editor.js b/resources/pagedown/Markdown.Editor.js index 72b21d7..ada1ad6 100644 --- a/resources/pagedown/Markdown.Editor.js +++ b/resources/pagedown/Markdown.Editor.js @@ -1457,7 +1457,6 @@ } } else { - console.log(button); button.classList.remove("wmd-button-active"); button.classList.add("wmd-button-inactive"); button.onclick = function () { }; @@ -1538,7 +1537,6 @@ } function setUndoRedoButtonStates() { - console.log(undoManager.canUndo()); if (undoManager) { setupButton(buttons.undo, undoManager.canUndo()); setupButton(buttons.redo, undoManager.canRedo());