I just made a new release v0.4.0 of Pandoc.jl
: https://github.com/kdheepak/Pandoc.jl
Pandoc is a swiss-army knife tool for converting one markup format (e.g. markdown, html, latex) to another (e.g. markdown, epub, rst) etc. You can read more about Pandoc here: https://pandoc.org/.
This Julia package provides 3 things:
- An interface to
pandoc_jll
v3.1: GitHub - JuliaBinaryWrappers/pandoc_jll.jl OR using your environmentpandoc
cli. - A
@kwdef
struct that let’s you construct the command line interface to Pandoc:
help?> Pandoc.Converter
This is a Converter options struct. It supports all of pandoc's command line arguments.
You can use it like so:
julia> run(Converter(; input = "# Header level 1"))
"<h1 id="header-level-1">Header level 1</h1>
"
julia> c = Pandoc.Converter(; input = "# Header level 1")
`pandoc`
julia> c.from = "markdown";
julia> c.to = "rst";
julia> c
`pandoc -f markdown -t rst`
julia> run(c)
"Header level 1
==============
"
mutable struct Converter
• input::Union{String, FilePathsBase.AbstractPath, Pandoc.Document, Vector{<:FilePathsBase.AbstractPath}}
• from::Union{Nothing, String}
• to::Union{Nothing, String}
• output::Union{Nothing, String}
• defaults::Union{Nothing, String}
• file_scope::Bool
• sandbox::Bool
• data_dir::Union{Nothing, String}
• template::Union{Nothing, String}
...
- Pandoc Types reimplemented in Julia for writing custom filters in Julia.
The serialization and deserialization of a Pandoc JSON is done using JSON3 and StructTypes.
You can use this package to process the JSON AST of a markup document, modify it, and use pandoc to convert it to any other markup.
Here’s any example of converting a markdown file to a markdown file but incrementing all the level headings by 1.
julia> using Pandoc
julia> doc = Pandoc.Document(raw"""
# header level 1
This is a paragraph.
## header level 2
This is another paragraph.
""");
julia> for block in doc.blocks
if block isa Pandoc.Header
block.level += 1
end
end
julia> run(Pandoc.Converter(input = doc, from="json", to="markdown")) |> println
## header level 1
This is a paragraph.
### header level 2
This is another paragraph.
Refer to the documentation for more information: https://kdheepak.com/Pandoc.jl/