Can I use pandoc in a lua filter to render parts of the AST to the current target format? #10054
Unanswered
retorquere
asked this question in
Q&A
Replies: 5 comments 4 replies
-
Maybe pandoc.write ?
Gesendet von Outlook für Android<https://aka.ms/AAb9ysg>
…________________________________
From: Emiliano Heyns ***@***.***>
Sent: Sunday, August 4, 2024 4:03:24 PM
To: jgm/pandoc ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [jgm/pandoc] Can I use pandoc in a lua filter to render parts of the AST to the current target format? (Discussion #10054)
I have a lua filter that converts markdown to docx/odt Zotero live citations. I do this by replacing Cite elements with RawInline docx/odt in the filter. Parts of the citation, such as citationSuffix, may have inline markup (Quoted, Underline etc) which I'd have to convert to RawInline myself. Is there a way to use the pandoc itself in the lua filter to render the citationSuffix to the raw XML for the target format? Perhaps by (ab)using pandoc.utils.citeproc?
—
Reply to this email directly, view it on GitHub<#10054>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABDTWJQHQIHOEQRHRHWLN2TZPYYCZAVCNFSM6AAAAABL63YOISVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZXGAYTCNRSGQ>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
You can let Pandoc handle the prefix and the suffix itself by returning a List made up of the Inlines of the prefix and suffix and of the citation ID formatted by you. Here is a proof of concept:
function Cite(cite)
local res = pandoc.List()
for _, citation in ipairs(cite.citations) do
if citation.prefix then
res:extend(citation.prefix)
res:insert(pandoc.Space())
end
res:insert(pandoc.RawInline('opendocument', '<stg>' .. citation.id .. '</stg>'))
if citation.suffix then
res:insert(pandoc.Space())
res:extend(citation.suffix)
end
end
return res
end
Of course, <stg> should be replaced by the correct formatting. The trailing space in the prefix and the leading space in the suffix are removed by Pandoc when parsing: the filter adds them, but it should not do this unconditionally as I did here (e.g. not when the suffix begins with a comma).
As the citation suffix is not interpreted by citeproc, the locator cannot be wrapped in braces or they will be printed as is.
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Could you please provide an example? I am not sure that I understand what you wish/have to do.
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Thank you, I realize that my solution will not work since the whole citation, including the prefix and the suffix, will have to be in the JSON object included in <w:instrText>. As you suggest, you will probably have to pass the prefix and suffix Inlines to a filter that will convert every element to a string containing the desired markup, using the walk method of the Inlines type. I don't think that using pandoc.write would be of great help here, for you would have to modify the output heavily (e.g. converting "strong" to "b", "<" to "<", etc.).
|
Beta Was this translation helpful? Give feedback.
2 replies
-
It seems to be more compact than what I envisioned :-) You need to remove the <p> tag as well though.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a lua filter that converts markdown to docx/odt Zotero live citations. I do this by replacing Cite elements with RawInline docx/odt in the filter. Parts of the citation, such as citationSuffix, may have inline markup (Quoted, Underline etc) which I'd have to convert to RawInline myself. Is there a way to use the pandoc itself in the lua filter to render the citationSuffix to the raw XML for the target format? Perhaps by (ab)using pandoc.utils.citeproc?
Beta Was this translation helpful? Give feedback.
All reactions