summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2024-08-20 11:08:46 -0400
committerDan Davison <dandavison7@gmail.com>2024-08-20 11:08:46 -0400
commit95457d30c9ab63db76ea4acacad806fc74e97914 (patch)
tree3d2592b75c78dcca3569fb7d088fc76f2e557a91
parent9889aedebd5fde193a94027c0434d99ba8b39097 (diff)
Evolve python hyperlink server example
-rw-r--r--manual/src/hyperlinks.md7
1 files changed, 6 insertions, 1 deletions
diff --git a/manual/src/hyperlinks.md b/manual/src/hyperlinks.md
index 5e0a9db..c6f3b15 100644
--- a/manual/src/hyperlinks.md
+++ b/manual/src/hyperlinks.md
@@ -40,18 +40,23 @@ If your editor does not have its own URL protocol, then there are still many pos
from subprocess import call
from urllib.parse import parse_qs, urlparse
+
class OpenInEditor(BaseHTTPRequestHandler):
def do_GET(self):
if self.path.startswith("/open-in-editor"):
query = parse_qs(urlparse(self.path).query)
[path], [line] = query["path"], query["line"]
+ # TODO: You might need to change this to construct the correct root directory for the
+ # project that the file is in, so that your IDE opens in the project workspace.
+ cwd = Path(path).parent
# TODO: Replace with the appropriate command for your editor
- call(["code", "-g", f"{path}:{line}"], cwd=Path(path).parent)
+ call(["code", "-g", f"{path}:{line}"], cwd=cwd)
self.send_response(200)
else:
self.send_response(404)
self.end_headers()
+
print("Starting httpd server on port 8000...")
HTTPServer(("", 8000), OpenInEditor).serve_forever()
```