From bb7036f4cfd279de388e9850b452b252fefb8e5b Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 17 Jan 2022 07:38:57 -0800 Subject: 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 --- org-roam-ui.el | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'org-roam-ui.el') 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 -- cgit v1.2.3