update packages
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
;;; Code:
|
||||
|
||||
(require 'parse-time)
|
||||
(require 'compat)
|
||||
|
||||
(require 'citeproc-bibtex)
|
||||
|
||||
(defvar citeproc-blt-to-csl-types-alist
|
||||
@@ -473,7 +475,7 @@ biblatex variables in B."
|
||||
(citeproc-blt--get-standard 'address b)))
|
||||
(push (cons csl-place-var ~location) result)))
|
||||
;; url
|
||||
(-when-let (url (or (let ((u (alist-get 'url b))) (and u (citeproc-s-replace "\\" "" u)))
|
||||
(-when-let (url (or (let ((u (alist-get 'url b))) (and u (string-replace "\\" "" u)))
|
||||
(when-let ((~eprinttype (or (alist-get 'eprinttype b)
|
||||
(alist-get 'archiveprefix b)))
|
||||
(~eprint (alist-get 'eprint b))
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
(require 's)
|
||||
(require 'org)
|
||||
(require 'map)
|
||||
(require 'compat)
|
||||
;; Handle the fact that org-bibtex has been renamed to ol-bibtex -- for the time
|
||||
;; being we support both feature names.
|
||||
(or (require 'ol-bibtex nil t)
|
||||
@@ -262,7 +263,7 @@ replacements."
|
||||
(let ((wo-quotes (if (and (string= (substring s 0 1) "\"")
|
||||
(string= (substring s -1) "\""))
|
||||
(substring s 1 -1) s)))
|
||||
(citeproc-s-replace "\\&" "&" wo-quotes)))
|
||||
(string-replace "\\&" "&" wo-quotes)))
|
||||
|
||||
(defun citeproc-bt--to-csl (s &optional with-nocase)
|
||||
"Convert a BibTeX field S to a CSL one.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
;;; citeproc-cite.el --- cite and citation rendering -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2017-2021 András Simonyi
|
||||
;; Copyright (C) 2017-2024 András Simonyi
|
||||
|
||||
;; Author: András Simonyi <andras.simonyi@gmail.com>
|
||||
|
||||
@@ -40,6 +40,11 @@
|
||||
(require 'citeproc-formatters)
|
||||
(require 'citeproc-sort)
|
||||
(require 'citeproc-subbibs)
|
||||
(require 'citeproc-date)
|
||||
(require 'citeproc-biblatex)
|
||||
|
||||
|
||||
(declare-function citeproc-style-category "citeproc-style" (style))
|
||||
|
||||
(cl-defstruct (citeproc-citation (:constructor citeproc-citation-create))
|
||||
"A struct representing a citation.
|
||||
@@ -77,6 +82,35 @@ Each function takes a single argument, a rich-text, and returns a
|
||||
post-processed rich-text value. The functions are applied in the
|
||||
order they appear in the list.")
|
||||
|
||||
(defun citeproc-cite--parse-locator-extra (s)
|
||||
"Parse extra locator text S into locator-date and locator-extra.
|
||||
Return a pair (LOCATOR-DATE . LOCATOR-EXTRA) where
|
||||
- LOCATOR-DATE is a `citeproc-date' struct or nil, and
|
||||
- LOCATOR-EXTRA is a string or nil."
|
||||
(let (locator-date locator-extra)
|
||||
(if (not (string-match-p "^[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}" s))
|
||||
(setq locator-extra (and (not (s-blank-str-p s)) s))
|
||||
(setq locator-date (citeproc-date-parse (citeproc-blt--to-csl-date
|
||||
(substring s 0 10))))
|
||||
(let ((extra (substring s 10)))
|
||||
(unless (s-blank-str-p extra) (setq locator-extra extra))))
|
||||
(cons locator-date locator-extra)))
|
||||
|
||||
(defun citeproc-cite--internalize-locator (cite)
|
||||
"Internalize a CITE struct's locator by parsing it into fields.
|
||||
If the \"|\" separator is present in the locator then parse it
|
||||
into `locator', `locator-extra' and `locator-date', and update
|
||||
CITE with these fields accordingly. Returns the possibly modified
|
||||
CITE."
|
||||
(when-let ((locator (alist-get 'locator cite))
|
||||
(separator-pos (cl-position ?| locator)))
|
||||
(setf (alist-get 'locator cite) (substring locator 0 separator-pos))
|
||||
(pcase-let ((`(,locator-date . ,locator-extra) (citeproc-cite--parse-locator-extra
|
||||
(substring locator (1+ separator-pos)))))
|
||||
(when locator-date (push (cons 'locator-date locator-date) cite))
|
||||
(when locator-extra (push (cons 'locator-extra locator-extra) cite))))
|
||||
cite)
|
||||
|
||||
(defun citeproc-cite--varlist (cite)
|
||||
"Return the varlist belonging to CITE."
|
||||
(let* ((itd (alist-get 'itd cite))
|
||||
@@ -87,7 +121,8 @@ order they appear in the list.")
|
||||
'(label locator suppress-author suppress-date
|
||||
stop-rendering-at position near-note
|
||||
first-reference-note-number ignore-et-al
|
||||
bib-entry locator-only use-short-title))
|
||||
bib-entry locator-only use-short-title
|
||||
locator-extra locator-date))
|
||||
cite)))
|
||||
(nconc cite-vv item-vv)))
|
||||
|
||||
@@ -228,7 +263,8 @@ For the optional INTERNAL-LINKS argument see
|
||||
(when outer-attrs
|
||||
(setq result (list outer-attrs result)))
|
||||
;; Prepend author to textual citations
|
||||
(when (eq (citeproc-citation-mode c) 'textual)
|
||||
(when (and (eq (citeproc-citation-mode c) 'textual)
|
||||
(not (member (citeproc-style-category style) '("numeric" "label"))))
|
||||
(let* ((first-elt (car cites)) ;; First elt is either a cite or a cite group.
|
||||
;; If the latter then we need to locate the
|
||||
;; first cite as the 2nd element of the first
|
||||
|
||||
@@ -168,16 +168,6 @@ TYPED RTS is a list of (RICH-TEXT . TYPE) pairs"
|
||||
"Return the first text associated with TERM in CONTEXT."
|
||||
(citeproc-term-text-from-terms term (citeproc-context-terms context)))
|
||||
|
||||
(defun citeproc-term-inflected-text (term form number context)
|
||||
"Return the text associated with TERM having FORM and NUMBER."
|
||||
(let ((matches
|
||||
(--select (string= term (citeproc-term-name it))
|
||||
(citeproc-context-terms context))))
|
||||
(cond ((not matches) nil)
|
||||
((= (length matches) 1)
|
||||
(citeproc-term-text (car matches)))
|
||||
(t (citeproc-term--inflected-text-1 matches form number)))))
|
||||
|
||||
(defconst citeproc--term-form-fallback-alist
|
||||
'((verb-short . verb)
|
||||
(symbol . short)
|
||||
@@ -185,17 +175,21 @@ TYPED RTS is a list of (RICH-TEXT . TYPE) pairs"
|
||||
(short . long))
|
||||
"Alist containing the fallback form for each term form.")
|
||||
|
||||
(defun citeproc-term--inflected-text-1 (matches form number)
|
||||
(let ((match (--first (and (eq form (citeproc-term-form it))
|
||||
(or (not (citeproc-term-number it))
|
||||
(eq number (citeproc-term-number it))))
|
||||
matches)))
|
||||
(if match
|
||||
(citeproc-term-text match)
|
||||
(citeproc-term--inflected-text-1
|
||||
matches
|
||||
(alist-get form citeproc--term-form-fallback-alist)
|
||||
number))))
|
||||
(defun citeproc-term-inflected-text (term form number context)
|
||||
"Return the text associated with TERM having FORM and NUMBER."
|
||||
(let ((matches
|
||||
(--select (string= term (citeproc-term-name it))
|
||||
(citeproc-context-terms context))))
|
||||
(if (not matches) nil
|
||||
(let (match)
|
||||
(while (and (not match) form)
|
||||
(setq match (--first (and (eq form (citeproc-term-form it))
|
||||
(or (not (citeproc-term-number it))
|
||||
(eq number (citeproc-term-number it))))
|
||||
matches))
|
||||
(unless match
|
||||
(setq form (alist-get form citeproc--term-form-fallback-alist))))
|
||||
(when match (citeproc-term-text match))))))
|
||||
|
||||
(defun citeproc-term-get-gender (term context)
|
||||
"Return the gender of TERM or nil if none is given."
|
||||
@@ -224,6 +218,20 @@ no internal links should be produced."
|
||||
;; Else link each cite to the corresponding bib item.
|
||||
(if (eq mode 'cite) 'cited-item-no 'bib-item-no)))))
|
||||
|
||||
(defun citeproc-context-maybe-stop-rendering
|
||||
(trigger context result &optional var)
|
||||
"Stop rendering if a (`stop-rendering-at'. TRIGGER) pair is present in CONTEXT.
|
||||
In case of stopping return with RESULT. If the optional VAR
|
||||
symbol is non-nil then rendering is stopped only if VAR is eq to
|
||||
TRIGGER."
|
||||
(if (and (eq trigger (alist-get 'stop-rendering-at (citeproc-context-vars context)))
|
||||
(or (not var) (eq var trigger))
|
||||
(eq (cdr result) 'present-var))
|
||||
(let ((rt-result (car result)))
|
||||
(push '(stopped-rendering . t) (car rt-result))
|
||||
(throw 'stop-rendering (citeproc-rt-render-affixes rt-result)))
|
||||
result))
|
||||
|
||||
(defun citeproc-render-varlist-in-rt (var-alist style mode render-mode &optional
|
||||
internal-links no-external-links)
|
||||
"Render an item described by VAR-ALIST with STYLE in rich-text.
|
||||
@@ -263,7 +271,7 @@ external links."
|
||||
(citeproc-context-int-link-attrval
|
||||
style internal-links mode (alist-get 'position var-alist)))
|
||||
(cite-no-attr-val (cons cite-no-attr
|
||||
(alist-get 'citation-number var-alist))))
|
||||
(alist-get 'citation-number var-alist))))
|
||||
(cond ((consp rendered) (setf (car rendered)
|
||||
(-snoc (car rendered) cite-no-attr-val)))
|
||||
((stringp rendered) (setq rendered
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
(require 'citeproc-lib)
|
||||
(require 'citeproc-rt)
|
||||
(require 'citeproc-context)
|
||||
(require 'citeproc-number)
|
||||
|
||||
(cl-defstruct (citeproc-date (:constructor citeproc-date-create))
|
||||
"Struct for representing dates.
|
||||
@@ -94,7 +95,7 @@ Set the remaining slots to the values SEASON and CIRCA."
|
||||
(cons nil 'empty-vars)))
|
||||
(cons nil 'empty-vars))))
|
||||
;; Handle `year' citation mode by stopping if needed
|
||||
(citeproc-lib-maybe-stop-rendering 'issued context result var-sym)))
|
||||
(citeproc-context-maybe-stop-rendering 'issued context result var-sym)))
|
||||
|
||||
(defun citeproc--date-part (attrs _context &rest _body)
|
||||
"Function corresponding to the date-part CSL element."
|
||||
|
||||
@@ -33,8 +33,11 @@
|
||||
(require 's)
|
||||
(require 'cl-lib)
|
||||
|
||||
(cl-defstruct (citeproc-formatter (:constructor citeproc-formatter-create))
|
||||
"Output formatter struct with slots RT, CITE, BIB-ITEM and BIB.
|
||||
(require 'citeproc-s)
|
||||
(require 'citeproc-rt)
|
||||
|
||||
(cl-defstruct (citeproc-formatter (:constructor citeproc-formatter-create))
|
||||
"Output formatter struct with slots RT, CITE, BIB-ITEM and BIB.
|
||||
RT is a one-argument function mapping a rich-text to its
|
||||
formatted version,
|
||||
CITE is a one-argument function mapping the output of RT for a
|
||||
@@ -48,9 +51,9 @@ BIB is a two-argument function mapping a list of formatted
|
||||
bibliography,
|
||||
NO-EXTERNAL-LINKS is non-nil if the formatter doesn't support
|
||||
external linking."
|
||||
rt (cite #'identity) (bib-item (lambda (x _) x))
|
||||
(bib (lambda (x _) (mapconcat #'identity x "\n\n")))
|
||||
(no-external-links nil))
|
||||
rt (cite #'identity) (bib-item (lambda (x _) x))
|
||||
(bib (lambda (x _) (mapconcat #'identity x "\n\n")))
|
||||
(no-external-links nil))
|
||||
|
||||
(defun citeproc-formatter-fun-create (fmt-alist)
|
||||
"Return a rich-text formatter function based on FMT-ALIST.
|
||||
@@ -164,13 +167,18 @@ Performs finalization by removing unnecessary zero-width spaces."
|
||||
(setq result (citeproc-s-replace-all-seq
|
||||
result '((" " . " ") (" " . " ") ("," . ",") (";" . ";")
|
||||
(":" . ":") ("." . "."))))
|
||||
;; Starting and ending z-w spaces are also removed, but not before an
|
||||
;; asterisk to avoid creating an Org heading.
|
||||
;; Starting and ending z-w spaces are also removed, but not before an asterisk
|
||||
;; to avoid creating an Org heading.
|
||||
(when (and (= (aref result 0) 8203)
|
||||
(not (= (aref result 1) ?*)))
|
||||
(setq result (substring result 1)))
|
||||
(when (= (aref result (- (length result) 1)) 8203)
|
||||
(setq result (substring result 0 -1))))
|
||||
(setq result (substring result 0 -1)))
|
||||
;; Prepend a zero width no-break space when the text starts with
|
||||
;; superscript to make Org parse it correctly.
|
||||
;; NOTE: This is a workaround, ideally should be fixed in Org.
|
||||
(when (= (aref result 0) ?^)
|
||||
(setq result (concat "" result))))
|
||||
result))
|
||||
|
||||
;; HTML
|
||||
@@ -257,11 +265,16 @@ CSL tests."
|
||||
"Return the LaTeX-escaped version of string S."
|
||||
(replace-regexp-in-string citeproc-fmt--latex-esc-regex "\\\\\\&" s))
|
||||
|
||||
(defconst citeproc-fmt--latex-uri-esc-regex
|
||||
(regexp-opt '("#" "%"))
|
||||
"Regular expression matching characters to be escaped in URIs for LaTeX output.")
|
||||
|
||||
(defun citeproc-fmt--latex-href (text uri)
|
||||
(let ((escaped-uri (replace-regexp-in-string "%" "\\\\%" uri)))
|
||||
(if (string-prefix-p "http" text)
|
||||
(concat "\\url{" escaped-uri "}")
|
||||
(concat "\\href{" escaped-uri "}{" text "}"))))
|
||||
(let ((escaped-uri (replace-regexp-in-string
|
||||
citeproc-fmt--latex-uri-esc-regex "\\\\\\&" uri)))
|
||||
(if (string-prefix-p "http" text)
|
||||
(concat "\\url{" escaped-uri "}")
|
||||
(concat "\\href{" escaped-uri "}{" text "}"))))
|
||||
|
||||
(defconst citeproc-fmt--latex-alist
|
||||
`((unformatted . ,#'citeproc-fmt--latex-escape)
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
(setq type (cdr macro-val)))))
|
||||
;; We stop if only the title had to be rendered.
|
||||
(let ((result (cons (citeproc-rt-format-single attrs content context) type)))
|
||||
(citeproc-lib-maybe-stop-rendering
|
||||
(citeproc-context-maybe-stop-rendering
|
||||
'title context result (or (and .variable (intern .variable)) t))))))
|
||||
|
||||
(provide 'citeproc-generic-elements)
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
)
|
||||
|
||||
(defconst citeproc--date-vars
|
||||
'(accessed available-date event-date issued original-date submitted)
|
||||
'(accessed available-date event-date issued original-date submitted locator-date)
|
||||
"CSL date variables.")
|
||||
|
||||
(defconst citeproc--name-vars
|
||||
@@ -145,20 +145,6 @@ numeric content."
|
||||
(s-matches-p "\\`[[:alpha:]]?[[:digit:]]+[[:alpha:]]*\\(\\( *\\([,&-]\\|--\\) *\\)?[[:alpha:]]?[[:digit:]]+[[:alpha:]]*\\)?\\'"
|
||||
val))))
|
||||
|
||||
(defun citeproc-lib-maybe-stop-rendering
|
||||
(trigger context result &optional var)
|
||||
"Stop rendering if a (`stop-rendering-at'. TRIGGER) pair is present in CONTEXT.
|
||||
In case of stopping return with RESULT. If the optional VAR
|
||||
symbol is non-nil then rendering is stopped only if VAR is eq to
|
||||
TRIGGER."
|
||||
(if (and (eq trigger (alist-get 'stop-rendering-at (citeproc-context-vars context)))
|
||||
(or (not var) (eq var trigger))
|
||||
(eq (cdr result) 'present-var))
|
||||
(let ((rt-result (car result)))
|
||||
(push '(stopped-rendering . t) (car rt-result))
|
||||
(throw 'stop-rendering (citeproc-rt-render-affixes rt-result)))
|
||||
result))
|
||||
|
||||
(provide 'citeproc-lib)
|
||||
|
||||
;;; citeproc-lib.el ends here
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
(define-package "citeproc" "20230228.1414" "A CSL 1.0.2 Citation Processor"
|
||||
(define-package "citeproc" "20240722.1110" "A CSL 1.0.2 Citation Processor"
|
||||
'((emacs "26")
|
||||
(dash "2.13.0")
|
||||
(s "1.12.0")
|
||||
@@ -6,8 +6,9 @@
|
||||
(queue "0.2")
|
||||
(string-inflection "1.0")
|
||||
(org "9")
|
||||
(parsebib "2.4"))
|
||||
:commit "290320fc579f886255f00d7268600df7fa5cc7e8" :authors
|
||||
(parsebib "2.4")
|
||||
(compat "28.1"))
|
||||
:commit "54184baaff555b5c7993d566d75dd04ed485b5c0" :authors
|
||||
'(("András Simonyi" . "andras.simonyi@gmail.com"))
|
||||
:maintainers
|
||||
'(("András Simonyi" . "andras.simonyi@gmail.com"))
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'citeproc-s)
|
||||
|
||||
(defun citeproc-prange--end-significant (start end len)
|
||||
"Return the significant digits of the end in page range START END.
|
||||
START and END are strings of equal length containing integers. If
|
||||
|
||||
@@ -230,6 +230,14 @@ Return the PROC-internal representation of REP."
|
||||
(let ((filters (citeproc-proc-bib-filters proc)))
|
||||
(and filters (not (equal filters '(nil))))))
|
||||
|
||||
(defun citeproc-proc-max-offset (itds)
|
||||
"Return the maximal first field width of bibitems in ITDS.
|
||||
ITDS should be the value of the itemdata field of a citeproc-proc
|
||||
structure."
|
||||
(cl-loop for itd being the hash-values of itds
|
||||
when (listp (citeproc-itemdata-rawbibitem itd)) maximize
|
||||
(length (citeproc-rt-to-plain (cadr (citeproc-itemdata-rawbibitem itd))))))
|
||||
|
||||
(provide 'citeproc-proc)
|
||||
|
||||
;;; citeproc-proc.el ends here
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
(require 'cl-lib)
|
||||
(require 'let-alist)
|
||||
(require 's)
|
||||
(require 'compat)
|
||||
|
||||
(require 'citeproc-s)
|
||||
(require 'citeproc-lib)
|
||||
@@ -148,7 +149,7 @@ If optional SKIP-NOCASE is non-nil then skip spans with the
|
||||
|
||||
(defun citeproc-rt-strip-periods (rts)
|
||||
"Remove all periods from rich-texts RTS."
|
||||
(citeproc-rt-map-strings (lambda (x) (citeproc-s-replace "." "" x)) rts))
|
||||
(citeproc-rt-map-strings (lambda (x) (string-replace "." "" x)) rts))
|
||||
|
||||
(defun citeproc-rt-length (rt)
|
||||
"Return the length of rich-text RT as a string."
|
||||
@@ -532,12 +533,6 @@ The values are ordered depth-first."
|
||||
|
||||
;;; Helpers for bibliography rendering
|
||||
|
||||
(defun citeproc-rt-max-offset (itemdata)
|
||||
"Return the maximal first field width in rich-texts RTS."
|
||||
(cl-loop for itd being the hash-values of itemdata
|
||||
when (listp (citeproc-itemdata-rawbibitem itd)) maximize
|
||||
(length (citeproc-rt-to-plain (cadr (citeproc-itemdata-rawbibitem itd))))))
|
||||
|
||||
(defun citeproc-rt-subsequent-author-substitute (bib s)
|
||||
"Substitute S for subsequent author(s) in BIB.
|
||||
BIB is a list of bib entries in rich-text format. Return the
|
||||
|
||||
@@ -27,11 +27,7 @@
|
||||
|
||||
(require 'thingatpt)
|
||||
(require 's)
|
||||
|
||||
;; Handle the unavailability of `string-replace' in early Emacs versions
|
||||
(if (fboundp 'string-replace)
|
||||
(defalias 'citeproc-s-replace #'string-replace)
|
||||
(defalias 'citeproc-s-replace #'s-replace))
|
||||
(require 'compat)
|
||||
|
||||
(defun citeproc-s-camelcase-p (s)
|
||||
"Return whether string S is in camel case."
|
||||
@@ -151,12 +147,12 @@ first word is not in lowercase then return S."
|
||||
(buffer-string))
|
||||
s))
|
||||
|
||||
(defun citeproc-s-sentence-case-title (s omit-nocase)
|
||||
(defun citeproc-s-sentence-case-title (s &optional omit-nocase)
|
||||
"Return a sentence-cased version of title string S.
|
||||
If optional OMIT-NOCASE is non-nil then omit the nocase tags from the output."
|
||||
(if (s-blank-p s) s
|
||||
(let ((sliced (citeproc-s-slice-by-matches
|
||||
s "\\(<span class=\"nocase\">\\|</span>\\|: +\\w\\)"))
|
||||
s "\\(<span class=\"nocase\">\\|</span>\\|: +[\"'“‘]*[[:alpha:]]\\)"))
|
||||
(protect-level 0)
|
||||
(first t)
|
||||
result)
|
||||
@@ -165,13 +161,18 @@ If optional OMIT-NOCASE is non-nil then omit the nocase tags from the output."
|
||||
(pcase slice
|
||||
("<span class=\"nocase\">" (cl-incf protect-level) (if omit-nocase nil slice))
|
||||
("</span>" (cl-decf protect-level) (if omit-nocase nil slice))
|
||||
;; Don't touch the first letter after a colon since it is probably a subtitle.
|
||||
((pred (string-match-p "^:")) slice)
|
||||
;; Don't touch the first letter after a colon since it probably
|
||||
;; starts a subtitle.
|
||||
((pred (string-match-p "^: +[\"'“‘]*[[:alpha:]]")) (setq first nil) slice)
|
||||
(_ (cond ((< 0 protect-level) (setq first nil) slice)
|
||||
((not first) (downcase slice))
|
||||
(t (setq first nil)
|
||||
(concat (upcase (substring slice 0 1))
|
||||
(downcase (substring slice 1)))))))
|
||||
;; We upcase the first letter and downcase the rest.
|
||||
(let ((pos (string-match "[[:alpha:]]" slice)))
|
||||
(if pos (concat (substring slice 0 pos)
|
||||
(upcase (substring slice pos (1+ pos)))
|
||||
(downcase (substring slice (1+ pos))))
|
||||
slice))))))
|
||||
result))
|
||||
(apply #'concat (nreverse result)))))
|
||||
|
||||
@@ -232,7 +233,7 @@ OQ is the opening quote, CQ is the closing quote to use."
|
||||
REPLACEMENTS is an alist with (FROM . TO) elements."
|
||||
(let ((result s))
|
||||
(pcase-dolist (`(,from . ,to) replacements)
|
||||
(setq result (citeproc-s-replace from to result)))
|
||||
(setq result (string-replace from to result)))
|
||||
result))
|
||||
|
||||
(defun citeproc-s-replace-all-sim (s regex replacements)
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
(require 'citeproc-macro)
|
||||
(require 'citeproc-proc)
|
||||
(require 'citeproc-name)
|
||||
(require 'citeproc-number)
|
||||
|
||||
(defun citeproc--sort (_attrs _context &rest body)
|
||||
"Placeholder function corresponding to the cs:sort element of CSL."
|
||||
@@ -172,17 +173,17 @@ MODE is either `cite' or `bib'."
|
||||
(let ((is-sorted-bib (citeproc-style-bib-sort (citeproc-proc-style proc)))
|
||||
(is-filtered (citeproc-proc-filtered-bib-p proc)))
|
||||
(when (or is-sorted-bib is-filtered)
|
||||
(let* ((itds (hash-table-values (citeproc-proc-itemdata proc)))
|
||||
(sorted (if is-sorted-bib
|
||||
(let ((sort-orders (citeproc-style-bib-sort-orders
|
||||
(let* ((itds (citeproc-sort-itds-on-citnum
|
||||
(hash-table-values (citeproc-proc-itemdata proc)))))
|
||||
(when is-sorted-bib
|
||||
(let ((sort-orders (citeproc-style-bib-sort-orders
|
||||
(citeproc-proc-style proc))))
|
||||
(citeproc-sort-itds itds sort-orders))
|
||||
(citeproc-sort-itds-on-citnum itds))))
|
||||
(setq itds (citeproc-sort-itds itds sort-orders))))
|
||||
;; Additionally sort according to subbibliographies if there are filters.
|
||||
(when is-filtered
|
||||
(setq sorted (sort sorted #'citeproc-sort-itds-on-subbib)))
|
||||
(setq itds (sort itds #'citeproc-sort-itds-on-subbib)))
|
||||
;; Set the CSL citation-number field according to the sort order.
|
||||
(--each-indexed sorted
|
||||
(--each-indexed itds
|
||||
(citeproc-itd-setvar it 'citation-number
|
||||
(number-to-string (1+ it-index))))))))
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
(cl-defstruct (citeproc-style (:constructor citeproc-style--create))
|
||||
"A struct representing a parsed and localized CSL style.
|
||||
CATEGORY is the style's category as a string,
|
||||
INFO is the style's general info (currently simply the
|
||||
corresponding fragment of the parsed xml),
|
||||
OPTS, BIB-OPTS, CITE-OPTS and LOCALE-OPTS are alists of general
|
||||
@@ -49,7 +50,6 @@ BIB-SORT-ORDERS and CITE-SORT-ORDERS are the lists of sort orders
|
||||
the n-th key should be in ascending or desending order,
|
||||
CITE-LAYOUT-ATTRS contains the attributes of the citation layout
|
||||
as an alist,
|
||||
CITE-NOTE is non-nil iff the style's citation-format is \"note\",
|
||||
DATE-TEXT and DATE-NUMERIC are the style's date formats,
|
||||
LOCALE contains the locale to be used or nil if not set,
|
||||
MACROS is an alist with macro names as keys and corresponding
|
||||
@@ -57,8 +57,8 @@ MACROS is an alist with macro names as keys and corresponding
|
||||
TERMS is the style's parsed term-list,
|
||||
USES-YS-VAR is non-nil iff the style uses the YEAR-SUFFIX
|
||||
CSL-variable."
|
||||
info opts bib-opts bib-sort bib-sort-orders
|
||||
bib-layout cite-opts cite-note cite-sort cite-sort-orders
|
||||
category info opts bib-opts bib-sort bib-sort-orders
|
||||
bib-layout cite-opts cite-sort cite-sort-orders
|
||||
cite-layout cite-layout-attrs locale-opts macros terms
|
||||
uses-ys-var date-text date-numeric locale)
|
||||
|
||||
@@ -98,12 +98,13 @@ in-style locale information will be loaded (if available)."
|
||||
(--each (cddr parsed-style)
|
||||
(pcase (car it)
|
||||
('info
|
||||
(let ((info-lst (cddr it)))
|
||||
(setf (citeproc-style-info style) info-lst
|
||||
(citeproc-style-cite-note style)
|
||||
(not (not (member '(category
|
||||
((citation-format . "note")))
|
||||
info-lst))))))
|
||||
(let* ((info-lst (cddr it))
|
||||
(category-info (cl-find-if
|
||||
(lambda (x) (and (eq 'category (car x))
|
||||
(eq 'citation-format (caaadr x))))
|
||||
info-lst))
|
||||
(category (cdaadr category-info)))
|
||||
(setf (citeproc-style-category style) category)))
|
||||
('locale
|
||||
(let ((lang (alist-get 'lang (cadr it))))
|
||||
(when (and (citeproc-locale--compatible-p lang locale)
|
||||
@@ -310,7 +311,16 @@ position and before the (possibly empty) body."
|
||||
(cons str (cdr result)))
|
||||
result)))
|
||||
;; Handle `author' citation mode by stopping if needed
|
||||
(citeproc-lib-maybe-stop-rendering 'names context final)))))
|
||||
(citeproc-context-maybe-stop-rendering 'names context final)))))
|
||||
|
||||
(defun citeproc-style-cite-note (style)
|
||||
"Return whether csl STYLE is a note style."
|
||||
(string= (citeproc-style-category style) "note"))
|
||||
|
||||
(defun citeproc-style-cite-superscript-p (style)
|
||||
"Return whether csl STYLE has a superscript citaton layout."
|
||||
(string= (alist-get 'vertical-align (citeproc-style-cite-layout-attrs style))
|
||||
"sup"))
|
||||
|
||||
(defun citeproc-style-global-opts (style layout)
|
||||
"Return the global opts in STYLE for LAYOUT.
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'subr-x)
|
||||
(require 'compat)
|
||||
(require 'dash)
|
||||
|
||||
(require 'citeproc-proc)
|
||||
@@ -39,7 +41,8 @@ see the documentation of `citeproc-add-subbib-filters'."
|
||||
(let* ((csl-type (alist-get 'type vv))
|
||||
(type (or (alist-get 'blt-type vv) csl-type))
|
||||
(keyword (alist-get 'keyword vv))
|
||||
(keywords (and keyword (split-string keyword "[ ,;]" t))))
|
||||
(keywords (and keyword (mapcar #'string-clean-whitespace
|
||||
(split-string keyword "[,;]" t)))))
|
||||
(--every-p
|
||||
(pcase it
|
||||
(`(type . ,key) (string= type key))
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
;;; citeproc.el --- A CSL 1.0.2 Citation Processor -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2017-2023 András Simonyi
|
||||
;; Copyright (C) 2017-2024 András Simonyi
|
||||
|
||||
;; Author: András Simonyi <andras.simonyi@gmail.com>
|
||||
;; Maintainer: András Simonyi <andras.simonyi@gmail.com>
|
||||
;; URL: https://github.com/andras-simonyi/citeproc-el
|
||||
;; Keywords: bib
|
||||
;; Package-Requires: ((emacs "26") (dash "2.13.0") (s "1.12.0") (f "0.18.0") (queue "0.2") (string-inflection "1.0") (org "9") (parsebib "2.4"))
|
||||
;; Package-Requires: ((emacs "26") (dash "2.13.0") (s "1.12.0") (f "0.18.0") (queue "0.2") (string-inflection "1.0") (org "9") (parsebib "2.4")(compat "28.1"))
|
||||
;; Version: 0.9.3
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
@@ -87,10 +87,12 @@ CITATIONS is a list of `citeproc-citation' structures."
|
||||
(new-ids (--remove (gethash it itemdata) uniq-ids)))
|
||||
;; Add all new items in one pass
|
||||
(citeproc-proc-put-items-by-id proc new-ids)
|
||||
;; Add itemdata to the cite structs and add them to the cite queue.
|
||||
;; Internalize the cites dealing with locator-extra if present, add itemdata to
|
||||
;; the cite structs and add them to the cite queue.
|
||||
(dolist (citation citations)
|
||||
(setf (citeproc-citation-cites citation)
|
||||
(--map (cons (cons 'itd (gethash (alist-get 'id it) itemdata)) it)
|
||||
(--map (cons (cons 'itd (gethash (alist-get 'id it) itemdata))
|
||||
(citeproc-cite--internalize-locator it))
|
||||
(citeproc-citation-cites citation)))
|
||||
(queue-append (citeproc-proc-citations proc) citation))
|
||||
(setf (citeproc-proc-finalized proc) nil))))
|
||||
@@ -239,8 +241,12 @@ formatting parameters keyed to the parameter names as symbols:
|
||||
raw-bib)
|
||||
raw-bib))
|
||||
;; Calculate formatting params.
|
||||
(max-offset (if (alist-get 'second-field-align bib-opts)
|
||||
(citeproc-rt-max-offset itemdata)
|
||||
;; NOTE: This is the only place where we check whether there are
|
||||
;; bibliography items in the processor, even though the empty case
|
||||
;; could be handled way more efficiently.
|
||||
(max-offset (if (and (alist-get 'second-field-align bib-opts)
|
||||
(not (hash-table-empty-p itemdata)))
|
||||
(citeproc-proc-max-offset itemdata)
|
||||
0))
|
||||
(format-params (cons (cons 'max-offset max-offset)
|
||||
(citeproc-style-bib-opts-to-formatting-params bib-opts)))
|
||||
|
||||
Reference in New Issue
Block a user