Replies: 4 comments 8 replies
-
Well done! Excellent start! |
Beta Was this translation helpful? Give feedback.
-
Stuck in Conversion of Headings to Chapter NodesI knew this was going to be a problem, because in the pandoc AST a Heading element is a standalone block (with its level stored) whereas in PML it maps to a The solution I came up with it this: currChLev = 0
openChNodes = 0
-- lev is an integer, the header level.
function Header(lev, s, attr)
local closeNodes = ""
if currChLev > lev then
for i=0,currChLev-lev do
closeNodes = closeNodes .. "]"
openChNodes = openChNodes -1
end
elseif currChLev < lev then
for i=0,lev-currChLev do
openChNodes = openChNodes +1
end
else
closeNodes = closeNodes .. "]"
end
currChLev = lev
return closeNodes .. "[ch " .. s
end which works correctly ( I originally hoped that I could do this via PML's
If So, for the above solution to work we'd need a way to ensure that either the writer or the template can take care of closing any pending open Chapter nodes at the end of the document. I couldn't find any references on how to expose a custom writer/filter variable to the pandoc template, nor any way of explicitly emitting some text after the document has been processed. Any ideas on this? The only alternative method that comes to my mind would be to make the Pandoc does expose some functions to walk or manipulate AST nodes:
Maybe this might help:
The The I'm quite lost at this point ... I was betting on using the template to handle closing the open Chapter tags, and now that I came to discover it doesn't work, I have no clue where to go from here. |
Beta Was this translation helpful? Give feedback.
-
Hi Tristano (@tajmone), I'm only starting to get my head around the Lua language so, I'm afraid that I'm not going to be much help right now. I did notice your 2bbcode from about 4 years ago. So, it is good that you have that experience from the past. I will add my 2c whenever I have some ideas. Kind Regards, |
Beta Was this translation helpful? Give feedback.
-
PML Writer UpdatesJust a quick update on the Lua filter progress... Implementing escape rules turned out to be easier than I though, luckily the pandoc AST process one token (word, symbol, etc.) at the time, which turns out to allow fine-grain control on when and how to enforce escaping rules. Also, since we're writing to PML is quite easy to just stick to the mandatory escaping rules for text; as for attributes, the general approach is to always quote them, and the escaping function has an optional boolean parameter to enforce the extra escaping of I've been testing all the inline elements, but still need to cover some block elements, just to check that the There's still a lot of work to be done, merely because pandoc covers lot's of style and formatting elements which are not natively supported by PML, which need to be either passed as raw html or manipulated in various ways. HTML/SGML entities are probably going to require considerable work in order to be converted to Unicode code-point escape, especially named entities (I'm not sure if pandoc emits them, or whether it converts them to decimal or hex values, need to test that). If named entities are passed, it might require creating a dictionary/hash table to convert them to Unicode escapes. Other elements requiring HTML hacks are probably images with internet URLs, since PML only supports filepath URIs for images. Then there are those elements which require translation to nodes + html attributes (e.g. ordered lists and their various numeral types like romans, alphanumeric, etc.), and so on. But so far, so good! the writer is already usable, although not fully complete, and the pros of using it for bulk documents-conversion already overweight the cons of having to manually fix the few elements which are not handled well. |
Beta Was this translation helpful? Give feedback.
-
Since the pandoc PML custom writer is quite different from the PML reader filter, I've decided to create a dedicated Discussion for it, separate from the general discussion on pandoc filter at #26.
So, I've finally managed to set-up a dedicated repository folder for our custom PML writer:
pandoc/filters-lua/pml-writer/
HTML Writer as Boilerplate
Currently
pml-writer.lua
is just a copy ofsample.lua
, the sample HTML writer that ships with pandoc, anddefault.pml.lua
is just a copy of the default pandoc HTML template.But since PML and HTML share a common document structure, this is a good starting point. In many cases, it should be sufficient to simply replace the HTML tags in output string with PML notes, so we could start working on these.
Other AST nodes will require ad hoc adaptation to PML needs, and we'll address them according to each node's priority.
What's important, is that now we finally have a proper scaffolding for the project, with a fully functional build script and sample test docs to work with.
Next Steps
The next steps will be to covert the
default.pml.lua
template to a real PML template, trying to map as many attributes as possible; and then start to editpml-writer.lua
to gradually implement proper PML nodes and attributes.It's definitely going to be a rather long journey, but every project needs to start from somewhere.
Support and Collaboration
This thread should serve for further discussion on the implementation details, to prevent polluting Issues — we can always create a concise Issue once we have a clear task to add to our TODOs list.
Please, share any thoughts, doubts and tips — I have no specific knowledge on how to create a pandoc Lua writer, beside a quick brush with Lua filters in the past. Any contributions to the repository are most welcome.
Beta Was this translation helpful? Give feedback.
All reactions