From: David Lukes <email@example.com>
Cc: David Lukes <firstname.lastname@example.org>
Subject: [PATCH] oc-basic.el: Better handling of CSL-JSON dates
Date: Fri, 25 Feb 2022 14:21:44 +0100 [thread overview]
Message-ID: <email@example.com> (raw)
* lisp/oc-basic.el (org-cite-basic--parse-json): Make date-parsing and
year extraction more resilient. Provide more informative errors when it
A string-based date is not only indicated by the key 'raw, but also
possibly by the key 'literal.
String-based dates come in various formats, not necessarily yyyy-mm-dd.
So extracting the first sequence of 4 digits is arguably a better
heuristic for getting the publication year than splitting the string on
- and getting the car of that.
On error, include `value' in the message, which contains the original
value with actionable information, whereas the previously included
`date' is always nil in that case.
lisp/oc-basic.el | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el
index d82406aff..81b7e4471 100644
@@ -178,21 +178,29 @@ Return a hash table with citation references as keys and fields alist as values.
" and ")))
;; Date are expressed as an array
- ;; (`date-parts') or a "string (`raw').
- ;; In both cases, extract the year and
- ;; associate it to `year' field, for
- ;; compatibility with BibTeX format.
+ ;; (`date-parts') or a "string (`raw'
+ ;; or `literal'). In both cases,
+ ;; extract the year and associate it
+ ;; to `year' field, for compatibility
+ ;; with BibTeX format.
(let ((date (or (alist-get 'date-parts value)
+ (alist-get 'literal value)
(alist-get 'raw value))))
- (car (split-string date "-")))
+ (minimal-match (zero-or-more anything))
+ (group-n 1 (repeat 4 digit))
+ (zero-or-more anything))
+ (rx (backref 1))
(error "Unknown CSL-JSON date format: %S"
(cons field value))))
next reply other threads:[~2022-02-25 14:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-25 13:21 David Lukes [this message]
2022-02-26 9:25 ` [PATCH] oc-basic.el: Better handling of CSL-JSON dates Nicolas Goaziou
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).