pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
603 stars 165 forks source link

Using yaml-metadata to set the dotPath doesn't seem to work? #99

Closed jerri closed 4 years ago

jerri commented 4 years ago

I am using pandoc 2.10 together with the current version of lua-filters/diagram-generator. I try to create diagrams using graphviz. But for one page I need the neato-binary from graphviz instead of dot. According to the documentation I should be able to set metadata dotPath to affect this. This works cool from the command line via --metadata dotPath=/usr/bin/neato. But if I try to add the information inside the file as follows

---
dotPath: /usr/bin/neato
---
# Test a graphviz image.

~~~graphviz
graph test {
    A -- B;
    C -- B;
    D -- B;
    B -- E;
    C -- E;
}


I just get an error message: `PandocLuaError "Error during function call: expected string, got 'table: 0x5e11780' (table)"`. It seems that pandoc returns a table with the string inside a `text` key. I am not sure if I am doing something wrong, or if maybe in pandoc the structure of metadata was changed somewhere to 2.10.  I tried to work around the problem, but I am either incompatible to the structure coming from the yaml-meta or coming from the commandline metadata parameter. Can anybody help?
jerri commented 4 years ago

It seems that pandoc.utils.stringify has to be used (according to other examples in this repository). So maybe diagram-generator.lua has to be updated to be compatible with newer versions of pandoc?

tarleb commented 4 years ago

Thanks for the report. Your analysis is on point, everything after the equal-sign in line 85 should be wrapped into a call to pandoc.utils.stringify. I hope to fix that soon.

jerri commented 4 years ago

Thanks for the bugfix. I tried to use this with my usecase, but now I get an error message:

Error running filter /home/gerhard/external/git/lua-filters/diagram-generator/diagram-
generator.lua:
PandocLuaError "Error during function call: Expected an AST element, but could not parse value as such."
stack traceback:
        [C]: in function 'pandoc.utils.stringify'
        .../git/lua-filters/diagram-generator/diagram-generator.lua:88: in function 'Meta'

I tried my own implementation of your approach which seems to work:

dotPath = (meta.dotPath and pandoc.utils.stringify(meta.dotPath)) or dotPath

Or is my setup somehow wrong?

tarleb commented 4 years ago

The first fix had a bug, which in turn was fixed this morning. Did you try the current version?

jerri commented 4 years ago

Yes, I tested with the latest version. Just retried and nothing new was pulled by git. So the problem happened with the latest version of the code.

jerri commented 4 years ago

I rechecked the approach and found the problem. It coughs up at a different location now. stringify is upset about meta.python_path, meta.pythonPath or python_path, which are all nil in my case. The old version of diagram_generator.lua that I patched as mentioned above doesn't have this problem.