(fix): Check if link-description is empty prior to inserting in db (#927)

* (fix): Check if link-description is empty prior to inserting in db

Caused problems with plain links, i.e., those not framed by
brackets (e.g. `file:foo.org` or `id:$uuid`).
This commit is contained in:
Leo Vivier
2020-07-11 23:42:05 +02:00
committed by GitHub
parent f9fea29c44
commit 7a4b15fd36

View File

@ -567,39 +567,40 @@ it as FILE-PATH."
(start (org-element-property :begin link))) (start (org-element-property :begin link)))
(goto-char start) (goto-char start)
(let* ((element (org-element-at-point)) (let* ((element (org-element-at-point))
(begin (or (org-element-property :content-begin element) (begin (or (org-element-property :content-begin element)
(org-element-property :begin element))) (org-element-property :begin element)))
(content (or (org-element-property :raw-value element) (content (or (org-element-property :raw-value element)
(buffer-substring-no-properties (buffer-substring-no-properties
begin begin
(or (org-element-property :content-end element) (or (org-element-property :content-end element)
(org-element-property :end element))))) (org-element-property :end element)))))
(content (string-trim content)) (content (string-trim content))
;; Expand all relative links to absolute links ;; Expand all relative links to absolute links
(content (org-roam--expand-links content file-path))) (content (org-roam--expand-links content file-path)))
(let ((properties (list :outline (mapcar (lambda (path) (let ((properties (list :outline (mapcar (lambda (path)
(org-roam--expand-links path file-path)) (org-roam--expand-links path file-path))
(org-roam--get-outline-path)) (org-roam--get-outline-path))
:content content :content content
:point begin)) :point begin))
(names (pcase type (names (pcase type
("file" ("file"
(list (file-truename (expand-file-name path (file-name-directory file-path))))) (list (file-truename (expand-file-name path (file-name-directory file-path)))))
("id" ("id"
(list (car (org-roam-id-find path)))) (list (car (org-roam-id-find path))))
((pred (lambda (typ) ((pred (lambda (typ)
(and (boundp 'org-ref-cite-types) (and (boundp 'org-ref-cite-types)
(-contains? org-ref-cite-types typ)))) (-contains? org-ref-cite-types typ))))
(setq type "cite") (setq type "cite")
(org-ref-split-and-strip-string path)) (org-ref-split-and-strip-string path))
(_ (list (org-element-property :raw-link link)))))) (_ (list (org-element-property :raw-link link))))))
(seq-do (lambda (name) (seq-do (lambda (name)
(when name
(push (vector file-path (push (vector file-path
name name
type type
properties) properties)
links)) links)))
names)))))) names))))))
links)) links))
(defun org-roam--extract-headlines (&optional file-path) (defun org-roam--extract-headlines (&optional file-path)