Add markdown for sample
This commit is contained in:
parent
409d2e3115
commit
6c170cccdd
3 changed files with 25 additions and 3 deletions
|
@ -3,6 +3,7 @@ import markdown as _markdown
|
||||||
import bleach
|
import bleach
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from pymdownx import superfences
|
||||||
|
|
||||||
|
|
||||||
EXTENSIONS = [
|
EXTENSIONS = [
|
||||||
|
@ -22,6 +23,18 @@ EXTENSIONS = [
|
||||||
"mdx_breakless_lists",
|
"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 + [
|
ALLOWED_TAGS = bleach.sanitizer.ALLOWED_TAGS + [
|
||||||
"img",
|
"img",
|
||||||
"center",
|
"center",
|
||||||
|
@ -60,7 +73,9 @@ ALLOWED_ATTRS = ["src", "width", "height", "href", "class", "open"]
|
||||||
@registry.filter
|
@registry.filter
|
||||||
def markdown(value, lazy_load=False):
|
def markdown(value, lazy_load=False):
|
||||||
extensions = EXTENSIONS
|
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)
|
html = bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS)
|
||||||
if not html:
|
if not html:
|
||||||
html = escape(value)
|
html = escape(value)
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
background: transparent;
|
background: transparent;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
color: black;
|
color: black;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
|
@ -49,6 +50,14 @@
|
||||||
border-radius: $widget_border_radius;
|
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 {
|
b, strong {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1457,7 +1457,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(button);
|
|
||||||
button.classList.remove("wmd-button-active");
|
button.classList.remove("wmd-button-active");
|
||||||
button.classList.add("wmd-button-inactive");
|
button.classList.add("wmd-button-inactive");
|
||||||
button.onclick = function () { };
|
button.onclick = function () { };
|
||||||
|
@ -1538,7 +1537,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUndoRedoButtonStates() {
|
function setUndoRedoButtonStates() {
|
||||||
console.log(undoManager.canUndo());
|
|
||||||
if (undoManager) {
|
if (undoManager) {
|
||||||
setupButton(buttons.undo, undoManager.canUndo());
|
setupButton(buttons.undo, undoManager.canUndo());
|
||||||
setupButton(buttons.redo, undoManager.canRedo());
|
setupButton(buttons.redo, undoManager.canRedo());
|
||||||
|
|
Loading…
Add table
Reference in a new issue