-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
32 lines (22 loc) · 773 Bytes
/
Copy pathutil.py
File metadata and controls
32 lines (22 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import functools
from bs4 import Tag
# Unicode LINE SEPARATOR character
LINE_SEPARATOR = "\u2028"
# Tags within which we should not be replacing content
VERBATIM_TAGS = ("pre", "code")
# Tag within which we should not perform text substitutions
LINK_TAG = "link"
def keep_verbatim(tag: Tag) -> bool:
return tag.name in VERBATIM_TAGS or any(
filter(lambda t: t.name in VERBATIM_TAGS, tag.parents)
)
def is_link_component(tag: Tag) -> bool:
return tag.name == LINK_TAG or any(
filter(lambda t: t.name == LINK_TAG, tag.parents)
)
__html_escape_lut = str.maketrans(
{"&": "&", "<": "<", ">": ">", '"': """, "'": "'"}
)
@functools.lru_cache()
def html_escape(value):
return value.translate(__html_escape_lut)