diff --git a/plugin.py b/plugin.py index 56d0fb6..cf449fc 100644 --- a/plugin.py +++ b/plugin.py @@ -1086,13 +1086,13 @@ def on_result(self, response: str) -> None: # The `encoded_position` argument for the open_file command was introduced in ST 4127 # https://github.com/sublimehq/sublime_text/issues/4800 markdown_content = re.sub( - r"\[(.+?:\d+)\]\(file:///.+?#\d+\)", - r"""\1""", + r"\[(.+?:\d+)\]\((file:///.+?)#(\d+)\)", + self._link_replacement, markdown_content) else: markdown_content = re.sub( - r"\[(.+?)(:\d+)\]\(file:///.+?#\d+\)", - r"""\1\2""", + r"\[(.+?:\d+)\]\((file:///.+?)#\d+\)", + lambda match: self._link_replacement(match, False), markdown_content) content = frontmatter + toolbar + markdown_content @@ -1103,6 +1103,13 @@ def input(self, args: dict) -> Optional[sublime_plugin.TextInputHandler]: if "word" not in args: return WordInputHandler() + def _link_replacement(self, match: 're.Match', encoded_position: bool = True) -> str: + path = parse_uri(match.group(2))[1].replace('\\', '\\\\') + if encoded_position: + return """{}""".format( + path, match.group(3), match.group(1)) + return """{}""".format(path, match.group(1)) + class WordInputHandler(sublime_plugin.TextInputHandler): def placeholder(self) -> str: