Allow code highlight for notes

main
Thomas Sileo 2022-07-04 19:43:37 +02:00
parent 5f34c2aee6
commit d18bf7c7d5
3 changed files with 98 additions and 2 deletions

View File

@ -33,6 +33,10 @@ color: $primary-color;
} }
} }
.codehilite {
margin: 50px 0;
}
.activity-main { .activity-main {
a { a {
color: $text-color; color: $text-color;

View File

@ -88,6 +88,6 @@ async def markdownify(
# Handle custom emoji # Handle custom emoji
tags.extend(emoji.tags(content)) tags.extend(emoji.tags(content))
content = markdown(content, extensions=["mdx_linkify"]) content = markdown(content, extensions=["mdx_linkify", "fenced_code", "codehilite"])
return content, tags, mentioned_actors return content, tags, mentioned_actors

View File

@ -3,6 +3,7 @@ from datetime import datetime
from datetime import timezone from datetime import timezone
from functools import lru_cache from functools import lru_cache
from typing import Any from typing import Any
from typing import Callable
from urllib.parse import urlparse from urllib.parse import urlparse
import bleach import bleach
@ -153,13 +154,104 @@ ALLOWED_TAGS = [
"colgroup", "colgroup",
"caption", "caption",
"img", "img",
"div",
"span",
] ]
ALLOWED_ATTRIBUTES = { ALLOWED_CSS_CLASSES = [
"highlight",
"codehilite",
"hll",
"c",
"err",
"g",
"k",
"l",
"n",
"o",
"x",
"p",
"ch",
"cm",
"cp",
"cpf",
"c1",
"cs",
"gd",
"ge",
"gr",
"gh",
"gi",
"go",
"gp",
"gs",
"gu",
"gt",
"kc",
"kd",
"kn",
"kp",
"kr",
"kt",
"ld",
"m",
"s",
"na",
"nb",
"nc",
"no",
"nd",
"ni",
"ne",
"nf",
"nl",
"nn",
"nx",
"py",
"nt",
"nv",
"ow",
"w",
"mb",
"mf",
"mh",
"mi",
"mo",
"sa",
"sb",
"sc",
"dl",
"sd",
"s2",
"se",
"sh",
"si",
"sx",
"sr",
"s1",
"ss",
"bp",
"fm",
"vc",
"vg",
"vi",
"vm",
"il",
]
def _allow_class(_tag: str, name: str, value: str) -> bool:
return name == "class" and value in ALLOWED_CSS_CLASSES
ALLOWED_ATTRIBUTES: dict[str, list[str] | Callable[[str, str, str], bool]] = {
"a": ["href", "title"], "a": ["href", "title"],
"abbr": ["title"], "abbr": ["title"],
"acronym": ["title"], "acronym": ["title"],
"img": ["src", "alt", "title"], "img": ["src", "alt", "title"],
"div": _allow_class,
"span": _allow_class,
"code": _allow_class,
} }