Custom pandoc writer in lua: attempt to call nil value

Viewed 73

I'm trying to set up a simple custom writer going from pandoc's markdown to latex. Here's what I have so far:

test.md

# A section

## A subsection


Heres a paragraph.


Heres another

custom_writer.lua


function Header(lev, s, attr)
    level_sequences = {
        "section",
        "subsection",
        "subsubsection",
        "subsubsubsection"
    }
    return string.format("\\%s{%s}", level_sequences[lev], s)
end

function Para(s)
    return s.."\\parskip"
end

function Str(s)
    return s
end

function Space()
    return " "
end

Question

As far as I understand from the docs

A writer using the classic style defines rendering functions for each element of the pandoc AST

I checked the resulting JSON from my markdown file and the only the following elements occur:

  • Header
  • Para
  • Str
  • Space

It seems to my that I've covered all the necessary elements in the AST, so I'm not sure why pandoc complains with Error running lua: attempt to call a nil value when I do the following:

pandoc test.md -t custom_writer.lua

Does anyone know what I'm missing in custom_writer.lua?

1 Answers

I was missing a few things which are not documented:

function Header(lev, s, attr)
    level_sequences = {
        "section",
        "subsection",
        "subsubsection",
        "subsubsubsection"
    }
    return string.format("\\%s{%s}", level_sequences[lev], s)
end

function Blocksep()
    return "\\parskip"
end

function Para(s)
    return s.."\\parskip"
end

function Str(s)
    return s
end

function Space()
    return " "
end

function Doc(body, metadata, variables) 
    return body
end
Related