Skip to content

Instantly share code, notes, and snippets.

@cderv
Last active April 19, 2023 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cderv/078720a8f2f5fcf0f806e058f6efd929 to your computer and use it in GitHub Desktop.
Save cderv/078720a8f2f5fcf0f806e058f6efd929 to your computer and use it in GitHub Desktop.
pretty output for `pandoc lua`

We don't get pretty output by default with pandoc lua like we do with --to native

 pandoc -f markdown -t native
![My Image](local/img/jpg)
^Z
[ Figure
    ( "" , [] , [] )
    (Caption
       Nothing [ Plain [ Str "My" , Space , Str "Image" ] ])
    [ Plain
        [ Image
            ( "" , [] , [] )
            [ Str "My" , Space , Str "Image" ]
            ( "local/img/jpg" , "" )
        ]
    ]
]
 pandoc lua -i
Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio
Embedded in pandoc 3.1.2
> pandoc.Figure( pandoc.Image( {}, 'local/img.jpg'),  { 'My image' })
Figure ("",[],[]) (Caption Nothing [Plain [Str "My",Space,Str "image"]]) [Plain [Image ("",[],[]) [] ("local/img.jpg","")]] 

We can use the pretty.lua filter to get pretty output

pandoc lua -l pretty -i
local debug = require 'debug'
debug.getmetatable(pandoc.Space()).__tostring = function (inln)
return pandoc.write(pandoc.Pandoc(inln), 'native')
end
debug.getmetatable(pandoc.Plain{}).__tostring = function (blk)
return pandoc.write(pandoc.Pandoc(blk), 'native')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment