You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
i think it might be useful to have an escape character for the aliases. Here is an idea to use \ as the escape character, such that if |some_alias| is defined, typing \|some_alias| will escape it and write verbatim |some_alias| instead.
I defined the ALIAS_RE with a lookbehind for the \ character, then do the replacements in 2 steps: replace the non-escaped aliases with their definition; then replace the escaped aliases with their verbatim word, without the \.
What do you think?
--- a/ford/_markdown.py+++ b/ford/_markdown.py@@ -133,7 +133,8 @@ class AliasPreprocessor(Preprocessor):
"""Substitute text aliases of the form ``|foo|`` from a dictionary
of aliases and their replacements"""
- ALIAS_RE = re.compile(r"\|([^ ].*?[^ ]?)\|")+ # pattern to match alias only if not preceded by `\`+ ALIAS_RE = re.compile(r"(?<!\\)\|([^ ].*?[^ ]?)\|")
def __init__(self, md: Markdown, aliases: Dict[str, str]):
self.aliases = aliases
@@ -149,7 +150,11 @@ class AliasPreprocessor(Preprocessor):
def run(self, lines: List[str]) -> List[str]:
for line_num, line in enumerate(lines):
- lines[line_num] = self.ALIAS_RE.sub(self._lookup, line)+ # replace the real aliases+ line = self.ALIAS_RE.sub(self._lookup, line)+ # replace the escaped aliases verbatim, without the preceding escape char `\`+ line = re.sub(r"\\(\|([^ ].*?[^ ]?)\|)", r"\g<1>",line)+ lines[line_num]=line
return lines
The text was updated successfully, but these errors were encountered:
Hello,
i think it might be useful to have an escape character for the
alias
es. Here is an idea to use\
as the escape character, such that if|some_alias|
is defined, typing\|some_alias|
will escape it and write verbatim|some_alias|
instead.I defined the
ALIAS_RE
with a lookbehind for the\
character, then do the replacements in 2 steps: replace the non-escaped aliases with their definition; then replace the escaped aliases with their verbatim word, without the\
.What do you think?
The text was updated successfully, but these errors were encountered: