sergiocorreia / panflute

An Pythonic alternative to John MacFarlane's pandocfilters, with extra helper functions
http://scorreia.com/software/panflute/
BSD 3-Clause "New" or "Revised" License
500 stars 59 forks source link

Creating a Panflute filter that interacts with other filters #210

Closed rschram closed 2 years ago

rschram commented 2 years ago

Hello everyone,

I have created a Panflute filter that replaces a fenced div with a table containing the contents of the div and a caption containing attributes of the div, like a specially formatted caption based on the identifier. Now I'd like to incorporate this into a workflow. I'm not clear on how I would go about, for instance,

I have toyed with creating a chain of bash commands that convert the original document into an intermediary format. If JSON is the intermediary format then I cannot accomplish either of the above. If Markdown is, then I can create table crossrefs but the intermediary .md output escapes the @ in the citeproc id. I was hoping for something that would be more straightforward. Is there a "batteries included" panflute way to create a filter that interacts nicely with other filters?

Best wishes, Ryan

PS: An example of the input text my filter will process is: -

---
title: My paper
bibliography: mybib.json
other-pandoc-options: | 
    ....
...

Manuscript text discussing results, as presented in (@tbl:id} below.

::: {.tbl #id caption="A tabularized version of @primary_source_1"

Lorem ipsum. [Et cetera]{type="code1"}.

More [text]{type="code2"} here.  

:::

Further discussion follows here, perhaps also citing [@primary_source_1] See also @secondary_source. 

PPS: Thanks to Sergio and others who commented on my previous issue. My filter to turn similar coded transcripts into a Graphviz diagram works well.

rschram commented 2 years ago

I am closing this issue because I have learned how to use convert_text to run pandoc in my filter on attribute text, which generates a tree of panflute objects that can be passed a table Caption element (task #1) and also learned how to modify the identifier attribute of a Table element so that a subsequent run of pandoc-crossref over the AST generates all the right crossrefs.