diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-09-27 13:36:58 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-09-27 13:36:58 +0200 |
commit | ec6f3e51bb7f33594c7d0151fc3bf1f09db4115a (patch) | |
tree | af8925f3a75c6b5454ac5005a4263c2446e0d351 /org-roam-ui.el | |
parent | cb29db132f79f9d35b323ae12524137cf5985018 (diff) |
feat: get org text from emacs
Diffstat (limited to 'org-roam-ui.el')
-rw-r--r-- | org-roam-ui.el | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/org-roam-ui.el b/org-roam-ui.el index 2cde148..df21f7c 100644 --- a/org-roam-ui.el +++ b/org-roam-ui.el @@ -206,6 +206,8 @@ This serves the web-build and API over HTTP." (org-roam-capture- :node (org-roam-node-create :title (alist-get 'title data)) :props '(:finalize find-file)))) + ((string= command "getText") + (org-roam-ui--send-text (alist-get 'id data) oru-ws)) (t (message "Something went wrong when receiving a message from Org-Roam-UI"))))) :on-close (lambda (_websocket) (remove-hook 'after-save-hook #'org-roam-ui--on-save) @@ -219,12 +221,26 @@ This serves the web-build and API over HTTP." (remove-hook 'after-save-hook #'org-roam-ui--on-save) (org-roam-ui-follow-mode -1))))) +(defun org-roam-ui--send-text (id ws) + "Send the text from org-node ID through the websocket WS." + (let* +((node (org-roam-populate (org-roam-node-create + :id id))) + (pos (org-roam-node-point node)) + (file (org-roam-node-file node)) + (text)) + (org-roam-with-temp-buffer + file + (setq text (buffer-substring-no-properties (buffer-end -1) (buffer-end 1))) + text) + (websocket-send-text ws + (json-encode `((type . "orgText") (data . ,text)))))) + (defun org-roam-ui--on-save () "Send graphdata on saving an org-roam buffer." (when (org-roam-buffer-p) (org-roam-ui--send-graphdata))) - (defun org-roam-ui--check-orb-keywords () "Check if the default keywords are in `orb-preformat-keywords', if not, add them." (when (and org-roam-ui-retitle-ref-nodes (boundp 'orb-preformat-keywords)) @@ -394,32 +410,6 @@ ROWS is the sql result, while COLUMN-NAMES is the columns to use." (setq rows nil))) res)) -;; (defservlet* id/:id text/html () -;; (let ((node (org-roam-populate (org-roam-node-create :id id))) -;; html-string) -;; (org-roam-with-temp-buffer (org-roam-node-file node) -;; (progn -;; (setq-local org-export-with-toc nil) -;; (setq-local org-export-with-broken-links t) -;; (setq-local org-export-with-sub-superscripts nil) -;; (replace-string "[[id:" "[[./") -;; (let* ((file-string (buffer-string)) -;; (matches (s-match-strings-all "\\[\\[\\(file:\\|\\.\\/\\)\\(.*\\.\\(png\\|jpg\\|jpeg\\|gif\\|svg\\)\\)\\]\\(\\[.*\\]\\)?\\]" file-string))) -;; (dolist (match matches) -;; (let ((path (elt match 2)) -;; (link (elt match 0))) -;; (unless (file-name-absolute-p path) -;; (setq path (concat (file-name-directory (org-roam-node-file-node)) path))) -;; (setq path (f-full path)) -;; (if (file-exists-p path) -;; (setq file-string -;; (s-replace link (format "[[image:%s]]" path) file-string))))) -;; (erase-buffer) -;; (insert file-string)) -;; (setq html-string (org-export-as 'html)))) -;; (insert html-string) -;; (httpd-send-header t "text/html" 200 :Access-Control-Allow-Origin "*"))) - (defun org-roam-ui-get-theme () "Attempt to bring the current theme into a standardized format." (list `(bg . ,(face-background hl-line-face)) |