public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Lua Filter for \citeauthor and \citetitle in HTML
Date: Thu, 09 Mar 2023 13:37:27 +0100	[thread overview]
Message-ID: <87pm9i6qmx.fsf@zeitkraut.de> (raw)
In-Reply-To: <4641cd0b-adb7-408f-b025-f56a0b293be5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>


"Bernardo C. D. A. Vasconcelos" <bernardovasconcelos-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> A filter that seems close enough is the bibexport filter at https://
> raw.githubusercontent.com/pandoc/lua-filters/master/bibexport/
> bibexport.lua which I reproduce below:

Newer pandoc versions allow to shorten this to

```
function Pandoc (doc)
  doc.meta.references = pandoc.utils.references(doc)
  doc.meta.bibliography = nil
  return doc
end
```

Here's a "quick n' dirty" filter that should make your `[@key]{.title}`
syntax work:

```
function Pandoc (doc)
  doc.meta.references = pandoc.utils.references(doc)
  doc.meta.bibliography = nil
  return doc:walk{
    Span = function (span)
      -- check that the span contains only a single cite object
      local cite = span.content[1]
      local citations = cite and cite.citations or nil
      if #span.content == 1 and cite.t == 'Cite' and #citations == 1 then
        local cite_id = citations[1].id
        local ref = doc.meta.references:find_if(
          function (r) return cite_id == r.id end
        )
        if ref and span.classes[1] then
          -- replace the span with a specific citation field
          return ref[span.classes[1]]
        end
      end
    end
  }
end
```

It's a bit condensed and not well documented, so let me know if you have
questions.


-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


  parent reply	other threads:[~2023-03-09 12:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-28 22:07 Bernardo C. D. A. Vasconcelos
     [not found] ` <51e71797-b029-4438-be64-6a8a15dd500an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-28 22:35   ` Bastien DUMONT
2023-01-30 16:49     ` Bernardo C. D. A. Vasconcelos
     [not found]       ` <4865a325-42c0-4245-b992-b4fbdeab576en-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-30 17:21         ` Bastien DUMONT
2023-01-30 17:41           ` John MacFarlane
     [not found]             ` <9786B5A5-9022-4E5B-85DE-39D4A2CAFD8F-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2023-03-08 14:00               ` Bernardo C. D. A. Vasconcelos
     [not found]                 ` <4641cd0b-adb7-408f-b025-f56a0b293be5n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-03-09 12:37                   ` Albert Krewinkel [this message]
     [not found]                     ` <87pm9i6qmx.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2023-03-09 14:37                       ` Bernardo C. D. A. Vasconcelos
     [not found]                         ` <555cddba-b706-48f6-acb8-07465e5487a2n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-03-09 18:56                           ` Bernardo C. D. A. Vasconcelos

Reply instructions:

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pm9i6qmx.fsf@zeitkraut.de \
    --to=albert+pandoc-9eawchwdxg8hfhg+jk9f0w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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.
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 NNTP newsgroup(s).