mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(internal): use regexp search for link-extraction (#1066)
Replace call to org-element-parse-buffer with simple regexp search.
This commit is contained in:
34
org-roam.el
34
org-roam.el
@ -579,16 +579,18 @@ FILE-FROM is typically the buffer file path, but this may not exist, for example
|
||||
in temp buffers. In cases where this occurs, we do know the file path, and pass
|
||||
it as FILE-PATH."
|
||||
(require 'org-ref nil t)
|
||||
(let ((file-path (or file-path
|
||||
(file-truename (buffer-file-name))))
|
||||
links)
|
||||
(org-element-map (org-element-parse-buffer) 'link
|
||||
(lambda (link)
|
||||
(let* ((type (org-element-property :type link))
|
||||
(unless file-path
|
||||
(setq file-path (file-truename (buffer-file-name))))
|
||||
(let (links)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward org-link-any-re nil t)
|
||||
(save-excursion
|
||||
(goto-char (match-beginning 0))
|
||||
(let* ((link (org-element-link-parser))
|
||||
(type (org-element-property :type link))
|
||||
(path (org-element-property :path link))
|
||||
(start (org-element-property :begin link)))
|
||||
(goto-char start)
|
||||
(let* ((element (org-element-at-point))
|
||||
(element (org-element-at-point))
|
||||
(begin (or (org-element-property :content-begin element)
|
||||
(org-element-property :begin element)))
|
||||
(content (or (org-element-property :raw-value element)
|
||||
@ -597,9 +599,8 @@ it as FILE-PATH."
|
||||
(or (org-element-property :content-end element)
|
||||
(org-element-property :end element)))))
|
||||
(content (string-trim content))
|
||||
;; Expand all relative links to absolute links
|
||||
(content (org-roam--expand-links content file-path)))
|
||||
(let ((properties (list :outline (mapcar (lambda (path)
|
||||
(content (org-roam--expand-links content file-path))
|
||||
(properties (list :outline (mapcar (lambda (path)
|
||||
(org-roam--expand-links path file-path))
|
||||
(org-roam--get-outline-path))
|
||||
:content content
|
||||
@ -620,14 +621,9 @@ it as FILE-PATH."
|
||||
(if (f-exists? file-maybe)
|
||||
(list file-maybe)
|
||||
(list path))))))))
|
||||
(seq-do (lambda (name)
|
||||
(dolist (name names)
|
||||
(when name
|
||||
(push (vector file-path
|
||||
name
|
||||
type
|
||||
properties)
|
||||
links)))
|
||||
names))))))
|
||||
(push (vector file-path name type properties) links)))))))
|
||||
links))
|
||||
|
||||
(defun org-roam--extract-headlines (&optional file-path)
|
||||
|
Reference in New Issue
Block a user