It works wonderfully. I made some minor modifications to allow it to work more like a `citefield` filter in general, and to avoid an error due to invalid field names passed as args. I think we could call it ready unless anyone else has suggestions. For fields with names such as authors, editors and translators, it seemed enough to get the family name of the first name, but other could prefer it to behave differently, of course. ``` local function get_keys(t) local keys={} for key,_ in pairs(t) do table.insert(keys, key) end return keys end stringify = require 'pandoc.utils'.stringify 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 ) local the_arg = span.classes[1] local the_result = "" if ref and the_arg then if string.find(stringify(get_keys(ref)), the_arg) then -- replace the span with a specific citation field if the_arg == "author" or the_arg == "editor" or the_arg == "translator" then the_result = stringify(ref[the_arg][1]["family"]) else if the_arg == "title" then the_result = pandoc.Emph{stringify(ref[the_arg])} else the_result = stringify(ref[the_arg]) end end else -- return the span unchanged the_result = span end return the_result end end end } end ``` Um abraço, Bernardo From: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org on behalf of Bernardo C. D. A. Vasconcelos Date: Thursday, 9 March 2023 11:37 To: pandoc-discuss Subject: Re: Lua Filter for citeauthor and citetitle in HTML Albert, that is vexingly short, but the syntax is perfectly clear. Thank you! Since I toiled at this for a while, your filter will provide me with some interesting learning opportunities. I will play around with it and see how it behaves with the other Lua filters. Thanks again, B. On Thursday, March 9, 2023 at 9:44:30 AM UTC-3 Albert Krewinkel wrote: "Bernardo C. D. A. Vasconcelos" 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 -- You received this message because you are subscribed to a topic in the Google Groups "pandoc-discuss" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/pandoc-discuss/5gb64T4OU9Q/unsubscribe. To unsubscribe from this group and all its topics, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/555cddba-b706-48f6-acb8-07465e5487a2n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CY4PR08MB3495899DCBA5868E92EE0F0CF2B59%40CY4PR08MB3495.namprd08.prod.outlook.com.