summaryrefslogtreecommitdiff
path: root/org-roam-ui.el
diff options
context:
space:
mode:
authorErik Hetzner <[email protected]>2022-01-17 07:38:57 -0800
committerErik Hetzner <[email protected]>2022-01-17 08:12:03 -0800
commitbb7036f4cfd279de388e9850b452b252fefb8e5b (patch)
tree0c0e7f260643a59cdb0be2716c06b056e08f9c7d /org-roam-ui.el
parent5ecd418060bf606924ac86faa1aa4036d4c785fb (diff)
Do not assume that a node is the entire file
A roam node is no longer necessarily an entire file. It can be a file, or any heading with an id. Fixes #106
Diffstat (limited to 'org-roam-ui.el')
-rw-r--r--org-roam-ui.el29
1 files changed, 15 insertions, 14 deletions
diff --git a/org-roam-ui.el b/org-roam-ui.el
index 165e5ed..f95245a 100644
--- a/org-roam-ui.el
+++ b/org-roam-ui.el
@@ -276,32 +276,33 @@ TODO: Be able to delete individual nodes."
(org-roam-ui-follow-mode -1)
(message "Connection with org-roam-ui closed."))
-(defun org-roam-ui--send-text (id ws)
- "Send the text from org-node ID through the websocket WS."
+(defun org-roam-ui--get-text (id)
+ "Retrieve the text from org-node ID."
(let*
((node (org-roam-populate (org-roam-node-create
:id id)))
- (file (org-roam-node-file node))
- (text))
+ (file (org-roam-node-file node)))
(org-roam-with-temp-buffer
file
- (setq text
- (buffer-substring-no-properties (buffer-end -1) (buffer-end 1)))
- text)
+ (when (> (org-roam-node-level node) 0)
+ ;; Heading nodes have level 1 and greater.
+ (goto-char (org-roam-node-point node))
+ (org-narrow-to-element))
+ (buffer-substring-no-properties (buffer-end -1) (buffer-end 1)))))
+
+(defun org-roam-ui--send-text (id ws)
+ "Send the text from org-node ID through the websocket WS."
+ (let ((text (org-roam-ui--get-text id)))
(websocket-send-text ws
(json-encode
`((type . "orgText")
(data . ,text))))))
-(defservlet* file/:file text/plain ()
- "Servlet for accessing file contents of org-roam files.
-
-Just sends the complete content of org-roam files rather than the specific
-node, as it's much faster to do that on the UI side."
- (insert-file-contents-literally (org-link-decode file))
+(defservlet* node/:id text/plain ()
+ "Servlet for accessing node content."
+ (insert (org-roam-ui--get-text (org-link-decode id)))
(httpd-send-header t "text/plain" 200 :Access-Control-Allow-Origin "*"))
-
(defservlet* img/:file text/plain ()
"Servlet for accessing images found in org-roam files."
(progn