UV: Document pack islands features and new ui #104468
@ -49,20 +49,51 @@ def check_word(w):
|
|||||||
return dict_spelling.check(w)
|
return dict_spelling.check(w)
|
||||||
|
|
||||||
|
|
||||||
# Match HTML link `Text <url>`__
|
def regex_key_raise(x):
|
||||||
|
raise Exception("Unknown role! " + "".join(x.groups()))
|
||||||
|
|
||||||
|
|
||||||
|
# A table of regex and their replacement functions.
|
||||||
|
#
|
||||||
|
# This is used to clean up text from `docutils.nodes.NodeVisitor.visit_Text` which doesn't remove inline markup.
|
||||||
|
# Note that in some cases the order matters, especially with include/excluding roles.
|
||||||
|
|
||||||
|
RE_TEXT_REPLACE_ROLES_INCLUDE = ("menuselection", "guilabel")
|
||||||
|
RE_TEXT_REPLACE_ROLES_EXCLUDE = ("kbd", "ref", "doc", "abbr")
|
||||||
|
|
||||||
|
RE_TEXT_REPLACE_TABLE = (
|
||||||
|
# Match HTML link: `Text <url>`__
|
||||||
# A URL may span multiple lines.
|
# A URL may span multiple lines.
|
||||||
RE_URL_LINKS = re.compile(r"(`)([^`<]+)(<[^`>]+>)(`)(__)", re.MULTILINE)
|
(
|
||||||
|
re.compile(r"(`)([^`<]+)(<[^`>]+>)(`)(__)", re.MULTILINE),
|
||||||
# Match `|substitution|` for removal.
|
lambda x: x.groups()[1].strip(),
|
||||||
RE_SUBST = re.compile(r"\|[a-zA-Z0-9_]+\|")
|
),
|
||||||
|
# Roles with plain-text: :some_role:`Text <ref>`
|
||||||
# :some_role:`Text <ref>`
|
(
|
||||||
RE_ROLE_WITH_TEXT = re.compile(r"(:[A-Za-z_]+:)(`)([^`<]+)(<[^`>]+>)(`)", flags=re.MULTILINE)
|
re.compile(r"(:[A-Za-z_]+:)(`)([^`<]+)(<[^`>]+>)(`)", flags=re.MULTILINE),
|
||||||
|
lambda x: x.groups()[2].strip(),
|
||||||
RE_ROLE_INCLUDE = re.compile(r"(:(menuselection|guilabel):)(`)([^`]+)(`)", flags=re.MULTILINE)
|
),
|
||||||
RE_ROLE_EXCLUDE = re.compile(r"(:(kbd|ref|doc|abbr):)(`)([^`]+)(`)", flags=re.MULTILINE)
|
# Roles to always include.
|
||||||
|
(
|
||||||
RE_ROLE_ANY = re.compile(r"(:[A-Za-z_]+:)(`)([^`]+)(`)", flags=re.MULTILINE)
|
re.compile(r"(:(" + ("|".join(RE_TEXT_REPLACE_ROLES_INCLUDE)) + r"):)(`)([^`]+)(`)", flags=re.MULTILINE),
|
||||||
|
lambda x: x.groups()[3].strip(),
|
||||||
|
),
|
||||||
|
# Roles to always exclude.
|
||||||
|
(
|
||||||
|
re.compile(r"(:(" + ("|".join(RE_TEXT_REPLACE_ROLES_EXCLUDE)) + r"):)(`)([^`]+)(`)", flags=re.MULTILINE),
|
||||||
|
lambda _: " ",
|
||||||
|
),
|
||||||
|
# Ensure all roles are handled.
|
||||||
|
(
|
||||||
|
re.compile(r"(:[A-Za-z_]+:)(`)([^`]+)(`)", flags=re.MULTILINE),
|
||||||
|
regex_key_raise,
|
||||||
|
),
|
||||||
|
# Match substitution for removal: `|identifier|`
|
||||||
|
(
|
||||||
|
re.compile(r"\|[a-zA-Z0-9_]+\|"),
|
||||||
|
lambda _: " ",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
RE_WORDS = re.compile(
|
RE_WORDS = re.compile(
|
||||||
r"\b("
|
r"\b("
|
||||||
@ -74,21 +105,11 @@ RE_WORDS = re.compile(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def regex_key_raise(x):
|
|
||||||
raise Exception("Unknown role! " + "".join(x.groups()))
|
|
||||||
|
|
||||||
|
|
||||||
def check_spelling_body(text):
|
def check_spelling_body(text):
|
||||||
|
|
||||||
text = re.sub(RE_URL_LINKS, lambda x: x.groups()[1].strip(), text)
|
# Wash text or inline RST.
|
||||||
text = re.sub(RE_ROLE_WITH_TEXT, lambda x: x.groups()[2].strip(), text)
|
for re_expr, re_replace_fn in RE_TEXT_REPLACE_TABLE:
|
||||||
text = re.sub(RE_ROLE_INCLUDE, lambda x: x.groups()[3].strip(), text)
|
text = re.sub(re_expr, re_replace_fn, text)
|
||||||
|
|
||||||
text = re.sub(RE_ROLE_EXCLUDE, lambda _: " ", text)
|
|
||||||
text = re.sub(RE_ROLE_ANY, regex_key_raise, text)
|
|
||||||
|
|
||||||
# Remove substitutions.
|
|
||||||
text = re.sub(RE_SUBST, lambda _: " ", text)
|
|
||||||
|
|
||||||
for re_match in RE_WORDS.finditer(text):
|
for re_match in RE_WORDS.finditer(text):
|
||||||
w = re_match.group(0)
|
w = re_match.group(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user