Skip to content

Commit

Permalink
Fix links to local files in the documentation sheet
Browse files Browse the repository at this point in the history
The server doesn't put the entire path into the link label anymore, so
we need to apply additional logic to parse the path from the link target.
  • Loading branch information
jwortmann committed Jan 19, 2024
1 parent f5e15df commit 8f7668d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""<a href='subl:lsp_julia_open_file {"file": "\1", "encoded_position": true}'>\1</a>""",
r"\[(.+?:\d+)\]\((file:///.+?)#(\d+)\)",
self._link_replacement,
markdown_content)
else:
markdown_content = re.sub(
r"\[(.+?)(:\d+)\]\(file:///.+?#\d+\)",
r"""<a href='subl:lsp_julia_open_file {"file": "\1"}'>\1\2</a>""",
r"\[(.+?:\d+)\]\((file:///.+?)#\d+\)",
lambda match: self._link_replacement(match, False),
markdown_content)

content = frontmatter + toolbar + markdown_content
Expand All @@ -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 """<a href='subl:lsp_julia_open_file {{"file": "{}:{}", "encoded_position": true}}'>{}</a>""".format(
path, match.group(3), match.group(1))
return """<a href='subl:lsp_julia_open_file {{"file": "{}"}}'>{}</a>""".format(path, match.group(1))


class WordInputHandler(sublime_plugin.TextInputHandler):
def placeholder(self) -> str:
Expand Down

0 comments on commit 8f7668d

Please sign in to comment.