summaryrefslogtreecommitdiff
path: root/org-roam-ui.el
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2022-01-29 15:46:24 +0100
committerGitHub <[email protected]>2022-01-29 15:46:24 +0100
commit835c0029db437c7c2efff18f718a792ae5a1ccc0 (patch)
treeca9f60e54206f5d4736253955e327b4c48156fb2 /org-roam-ui.el
parentf1e1769d97e4f44d7336839db587b0acbb918d99 (diff)
parentb38fa6ad4f00e6f81e11590d2fa3d612ced47e7b (diff)
Merge pull request #203 from egh/fix/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 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