pandoc-ext / diagram Goto Github PK
View Code? Open in Web Editor NEWGenerate diagrams from embedded code; supports Mermaid, Dot/GraphViz, PlantUML, Asymptote, and TikZ.
License: MIT License
Generate diagrams from embedded code; supports Mermaid, Dot/GraphViz, PlantUML, Asymptote, and TikZ.
License: MIT License
If PLANTUML_BIN
not set, support for rendering plantuml with online server.
https://www.plantuml.com/plantuml/uml/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000
Hi,
I'd be interested in using diagram
but it's a little tricky right now.
My workflow is markdown to html (just pandoc and a makefile, not quarto), so diagram
doesn't really work unless one or both of embed-resources
and extract-media
options are active.
But those aren't good options for me - there's plenty of other things that I link to in a given document, but nothing else that I'd want embedded or extracted.
Rather, what I'd like is to be able to configure diagram
to output its images to some path and then link to that. (I got halfway there by setting the cache directory, but then tripped up on the hashes being different.)
If this is out of scope for the project because it's not a use case that makes sense for other output formats, fair enough.
Hi. I can run the diagram.lua filter on input-tikz.md
from your test
directory. Now I want to apply it to produce html from a latex document. I am adding --from latex
, but the output contains Unknown environment 'tikzpicture'
.
pandoc --from latex --to slidy \
--variable "slidy-url:...my-local-installation.../Slidy2" \
--standalone \
--mathjax="...my-local-installation.../MathJax-3.2.2/es5/tex-mml-chtml.js" \
--slide-level=2 \
--lua-filter=...my-local-installation.../diagram/diagram.lua
with
$ pandoc --version
pandoc 3.1
Features: -server +lua
Scripting engine: Lua 5.4
Including simple images instead of figure where there is no caption is very useful.
But when if I provide neither caption nor alt, there is an error message :
pandoc -t latex --lua-filter ~/dev/pandoc/diagram.lua -o test.pdf test.md
Error running filter diagram.lua:
Inline, list of Inlines, or string expected, got nil
while retrieving function argument caption
while retrieving arguments for function Image
stack traceback:
diagram.lua:481: in function <diagram.lua:413>
[C]: in ?
[C]: in method 'walk'
diagram.lua:497: in function 'Pandoc'
stack traceback:
diagram.lua:497: in function 'Pandoc'
Sample file:
Sample graph :
```{.dot}
digraph {
A -> B;
B -> C;
C -> A;
}
```
If I use {.dot alt="foo"}
or {.dot caption="bar"}
, everything is fine.
It seems to me that additional packages for tikz are not taken into account.
sample.md
contains :
{.tikz caption="This is an image, created by **TikZ i.e. LaTeX**." additionalPackages="\usepackage{adjustbox}"}
but in diagram.lua
:
local pkgs = opt['additional-packages'] or ''
variable pkgs
remains empty (opt['additional-packages']
is nil
). The package is not added, and compilation fails
(missing \trimbox
).
If I add \usepackage{adjustbox}
directly in local tikz_template
variable, everything works fine.
I don't understand lua enough to make a PR... :)
This commit 97c6362 works like a charm for my use case (generation of PDF) : TikZ, mermaid, plantUML, asymptote.
But with the last commit : 8168143 plantUML does not work anymore :
java.lang.ClassNotFoundException: org.apache.batik.apps.rasterizer.SVGConverter
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at net.sourceforge.plantuml.pdf.PdfConverter.convert(PdfConverter.java:61)
at net.sourceforge.plantuml.UmlDiagram.exportDiagramInternalPdf(UmlDiagram.java:289)
at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:138)
at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:198)
at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:165)
at net.sourceforge.plantuml.Pipe.generateDiagram(Pipe.java:103)
at net.sourceforge.plantuml.Pipe.managePipe(Pipe.java:94)
at net.sourceforge.plantuml.Run.managePipe(Run.java:361)
at net.sourceforge.plantuml.Run.main(Run.java:187)
Exception in thread "main" java.lang.UnsupportedOperationException
at net.sourceforge.plantuml.pdf.PdfConverter.convert(PdfConverter.java:80)
at net.sourceforge.plantuml.UmlDiagram.exportDiagramInternalPdf(UmlDiagram.java:289)
at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:138)
at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:198)
at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:165)
at net.sourceforge.plantuml.Pipe.generateDiagram(Pipe.java:103)
at net.sourceforge.plantuml.Pipe.managePipe(Pipe.java:94)
at net.sourceforge.plantuml.Run.managePipe(Run.java:361)
at net.sourceforge.plantuml.Run.main(Run.java:187)
Lua warning: /home/signac/dev/pandoc/diagram.lua: Error running plantuml (error code 1): <no output>
The sample file used contains :
Example usage:
```{.plantuml caption="This is an image, created by **PlantUML**." width=50%}
@startuml
Alice -> Bob: Authentication Request Bob --> Alice: Authentication Response
Alice -> Bob: Another authentication Request Alice <-- Bob: another Response
@enduml
```
I found this information in the readme
While it is possible to use this filter with Quarto, it is not encouraged. Quarto comes its own system for diagram generation, and that should be used instead.
I looked at the documentation, Quarto comes with native support of Mermaid and Graphviz. This affirmation is then true for those types of diagrams. But I did not see a way to extend the native support with other format like plantuml.
This extension could be a good fit to integrate plantuml support to Quarto ?
Sorry to ping you @cderv, may be you can help to answer my question ?
Thanks a lot for you help!
I tested diagram.lua with the following qmd
file:
---
filters:
- diagram.lua
diagram:
cache: true
cache-dir: .cache/plantuml
---
# Welcome for fun
```{.plantuml}
'| label: fig-auth
@startuml
Alice -> Bob: Authentication Request Bob super --> Alice: Authentication Response
Alice -> Bob: Another authentication Request Alice <-- Bob: another Response
@enduml
```
When I use the following command: quarto render docs/index.qmd --to docx
, I get the following error:
pandoc
to: docx
output-file: index.docx
default-image-extension: png
metadata
diagram:
cache: true
cache-dir: .cache/plantuml
Error running filter /opt/quarto/share/filters/main.lua:
diagram.lua:11: attempt to call a nil value (global 'warn')
stack traceback:
/opt/quarto/share/filters/main.lua:4073: in local 'callback'
[string "..."]:1789: in function <[string "..."]:1787>
(...tail calls...)
/opt/quarto/share/filters/main.lua:368: in function 'make_wrapped_user_filters'
/opt/quarto/share/filters/main.lua:15395: in main chunk
A workaround is to comment the following line
It happens with other output format too.
Quarto version used and pandoc version embedded by quarto.
Tests was performed on WSL.
> quarto check
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.1.1: OK
Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 1.3.340
Path: /opt/quarto/bin
[✓] Checking basic markdown render....OK
Thanks for your help.
Hi, quarto 1.4 changed the AST handling for figures in 1.4, so the actual pandoc.Figure
code doesn’t work anymore for this release.
Should we add a whole "if (quarto.version > 1.4)" code path for this?
I’m still figuring out how to wrap the pandoc.Figure
correctly now.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.