[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: modify citation links in a derived HTML backend

From: Matt Price
Subject: Re: modify citation links in a derived HTML backend
Date: Sat, 3 Jul 2021 17:32:50 -0400

Thanks Jens!

I've added some comments in the issue you linked to, but in the meantime I've also come up with what seems to be at least a semi-viable hack for adding native CSL citation support to org-re-reveal. It involves creating two new variables and then let-setting `citeproc-fmt--formatters-alist` in `org-re-reveal-export-to-html`. Something similar could presumably be done in other derived backends.

I find it quite hackish and I don't know whether perhaps some more general solution could be found, but in any case here is the code, which I have inserted into org-re-reveal.el locally:

Something to note here is that `oc-csl.el` hard-codes the output format options in org-cite-csl--output-formats. I wonder if it would be worth having an extensible variable "org-cite-csl--output-format-alist" that backends could modify if they have special needs. For instance, I am thinking about website exporters like Hugo where authors might want to have separate bibliography pages rather than endnotes, or add "title" attributes to citations, or possibly even modal tooltips with formatted text.  It probably doesn't make sense to build all of that in to citeproc.el, but assing some additional information seems worthwhile.
(defvar org-re-reveal-citeproc-fmt-alist
  `((unformatted . citeproc-fmt--xml-escape)
    (cited-item-no . ,(lambda (x y) (concat "<a href="">    x "</a>")))
    (bib-item-no . ,(lambda (x y) (concat "<a name=\"citeproc_bib_item_" y "\"></a>"
    (font-style-italic . ,(lambda (x) (concat "<i>" x "</i>")))
    (font-style-oblique . ,(lambda (x)
    (concat "<span style=\"font-style:oblique;\"" x "</span>")))
    (font-variant-small-caps . ,(lambda (x)
  "<span style=\"font-variant:small-caps;\">" x "</span>")))
    (font-weight-bold . ,(lambda (x) (concat "<b>" x "</b>")))
    (text-decoration-underline .
                               ,(lambda (x)
                          "<span style=\"text-decoration:underline;\">" x "</span>")))
    (rendered-var-url . ,(lambda (x) (concat "<a href="" x "\">" x "</a>")))
    (rendered-var-doi . ,(lambda (x) (concat "<a href="" x "\">" x "</a>")))
    ;;(rendered-var-title . ,(lambda (x) (concat "<a href="" x "\">" x "</a>")))
    (vertical-align-sub . ,(lambda (x) (concat "<sub>" x "</sub>")))
    (vertical-align-sup . ,(lambda (x) (concat "<sup>" x "</sup>")))
    (vertical-align-baseline . ,(lambda (x) (concat "<span style=\"baseline\">" x "</span>")))
    (display-left-margin . ,(lambda (x) (concat "\n    <div class=\"csl-left-margin\">"
x "</div>")))
    (display-right-inline . ,(lambda (x) (concat "<div class=\"csl-right-inline\">"
x "</div>\n  ")))
    (display-block . ,(lambda (x) (concat "\n\n    <div class=\"csl-block\">"
 x "</div>\n")))
    (display-indent . ,(lambda (x) (concat "<div class=\"csl-indent\">" x "</div>\n  ")))))

(defvar org-re-reveal-formatters-alist
  `((html . ,(citeproc-formatter-create
           :rt (citeproc-formatter-fun-create org-re-reveal-citeproc-fmt-alist)
           :bib #'citeproc-fmt--html-bib-formatter))))

(defun org-re-reveal-export-to-html
    (&optional async subtreep visible-only body-only ext-plist backend)
  "Export current buffer to a reveal.js HTML file.
to `org-export-to-file'.
Optional BACKEND must be `re-reveal' or a backend derived from it."
  (let* ((backend (or backend 're-reveal))
         (extension (concat "." org-html-extension))
         (client-ext (concat org-re-reveal-multiplex-client-ext extension))
         (file (org-export-output-file-name extension subtreep))
         (clientfile (org-export-output-file-name client-ext subtreep))
         (org-html-container-element "div")
         (citeproc-fmt--formatters-alist org-re-reveal-formatters-alist))

    (setq org-re-reveal-client-multiplex nil)
    (org-export-to-file backend file
      async subtreep visible-only body-only ext-plist)

    ;; Export the client HTML file if org-re-reveal-client-multiplex is set true
    ;; by previous call to org-export-to-file
    (if org-re-reveal-client-multiplex
        (org-export-to-file backend clientfile
          async subtreep visible-only body-only ext-plist))

On Sat, Jul 3, 2021 at 3:53 AM Jens Lechtenboerger <lechten@wi.uni-muenster.de> wrote:
On 2021-07-02, Matt Price wrote:

> Hi,
> (cc:ing Jens L. in case this is relevant for his dev work on org-re-reveal).

Hi Matt,

just a quick reply: Yes, that is certainly relevant for me, but I do
not have the time to investigate this at the moment.  Note that I
use references with org-ref and org-re-reveal-ref (for which Bruce
opened an issue for org-cite support [1]).  Currently, I configure
org-ref-ref-html (although its doc string suggests otherwise).

Best wishes

[1] https://gitlab.com/oer/org-re-reveal-ref/-/issues/2

reply via email to

[Prev in Thread] Current Thread [Next in Thread]