Closed perrette closed 3 years ago
I don’t quite follow your use case, could you explain it in more details step by step? Eg the crucial part is what you want to do with the template.
convert_text can convert between any formats in addition to the ast. So your title sentence is doable. But your use case description is more complicated than that.
Ok. I see i keep underestimating convert_text
. When I tried to use it I had run into errors. I'll give it another try.
My use case is, convert [caption text](path/to/image.png){ title="image title" source="image source" }
into something like
<h2> image title </h2>
<p> image caption <span class=...>image source</span></p>
</div>
with a few more elements and keywords. The template is rendered via jinja2
, as
jinja2.Template("""<div>
<h2> {{title}} </h2>
<p> {{caption}} <span class=...> {{source}} </span> </p>
</div>""").render(title=title, caption=caption, source=source)
that's why i need to convert caption
to html directly. I am aware that I could build such a template with native panflute classes but I'd prefer to stick to jinja2 for readability. Caption and source potentially have links and bibtex references.
The pandoc call involves three filters:
convert_text
on raw "source" field, since caption is ast and source is markdown).I hope that is a clearer explanation. There are probably other ways of achieving this, but that seems to work for me. I'm only stuck in extracting figure caption in HTML format. I understand now that should try again with convert_text
.
I could solve the issue by converting my image element to Para:
pf.convert_text(pf.Para(*elem.content), 'panflute', 'html')
Thanks for your hint and the great project.
What is the best way to write html from parsed
panflute.convert_text
output?Use case: conversion from markdown to html, with a custom HTML template for images. I need to inject the caption into the template and return a pf.RawInline instance of the styled image. The caption was previously parsed and other filters applied (links, citeproc ...). Now if only I could convert it back to HTML, the problem would be solved.
I started to use the
walk
method, but it is not a straightforward task, and it duplicates the work of pandoc. I was just wondering, how can I make use of the underlying pandoc / panflute machinery to convert to HTML and avoid double work?Alternatively, I guess I could try to parse the tempate itself, using PLACEHOLDERS, and then replace the placeholder...but again it seems too complicated. I'm sure I'm missing a simple solution.
Thanks much for any suggestion.