diff options
Diffstat (limited to 'org-roam-ui.el')
-rw-r--r-- | org-roam-ui.el | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/org-roam-ui.el b/org-roam-ui.el index abbfe61..e1431ff 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 |