(feat)db: support org-ref v3 (#1977)

Org-ref v3 introduced a new citation syntax, and removed some functions
that org-roam had previously relied upon (e.g. for extracting keys from
multi-citations).

This commit introduces support on two fronts:

1. Add `org-roam-org-ref-path-to-keys` which converts a link path to a
list of keys. This supports both Org-ref v2 and v3.

2. Adds support for parsing multi-citations in refs.
This commit is contained in:
Jethro Kuan
2021-11-20 16:33:12 +08:00
committed by GitHub
parent d93423d4e1
commit a2e46db808
2 changed files with 24 additions and 9 deletions

View File

@ -485,7 +485,13 @@ INFO is the org-element parsed buffer."
(cond ((string-prefix-p "@" ref)
(push (vector node-id (substring ref 1) "cite") rows))
((string-match org-link-plain-re ref)
(push (vector node-id (match-string 2 ref) (match-string 1 ref)) rows))
(let ((link-type (match-string 1 ref))
(path (match-string 2 ref)))
(if (and (boundp 'org-ref-cite-types)
(or (assoc link-type org-ref-cite-types)
(member link-type org-ref-cite-types)))
(dolist (key (org-roam-org-ref-path-to-keys path))
(push (vector node-id key link-type) rows)))))
(t
(lwarn '(org-roam) :warning
"%s:%s\tInvalid ref %s, skipping..." (buffer-file-name) (point) ref)))))
@ -507,14 +513,13 @@ INFO is the org-element parsed buffer."
;; For Org-ref links, we need to split the path into the cite keys
(when (and source path)
(if (and (boundp 'org-ref-cite-types)
(fboundp 'org-ref-split-and-strip-string)
(member type org-ref-cite-types))
(progn
(setq path (org-ref-split-and-strip-string path))
(org-roam-db-query
[:insert :into citations
:values $v1]
(mapcar (lambda (p) (vector source p (point) properties)) path)))
(or (assoc type org-ref-cite-types)
(member type org-ref-cite-types)))
(org-roam-db-query
[:insert :into citations
:values $v1]
(mapcar (lambda (k) (vector source k (point) properties))
(org-roam-org-ref-path-to-keys path)))
(org-roam-db-query
[:insert :into links
:values $v1]