pandoc.utils

blocks_to_inlines

function pandoc.utils.blocks_to_inlines(blocks: pandoc.List, sep?: pandoc.Inlines)
  -> pandoc.Inlines

Squash a list of blocks into a list of inlines.

Usage:

local blocks = {
  pandoc.Para{ pandoc.Str 'Paragraph1' },
  pandoc.Para{ pandoc.Emph 'Paragraph2' }
}
local inlines = pandoc.utils.blocks_to_inlines(blocks)
-- inlines = {
--   pandoc.Str 'Paragraph1',
--   pandoc.Space(), pandoc.Str'¶', pandoc.Space(),
--   pandoc.Emph{ pandoc.Str 'Paragraph2' }
-- }

citeproc

function pandoc.utils.citeproc(doc: pandoc.Pandoc)
  -> pandoc.Pandoc

Process the citations in the file, replacing them with rendered citations and adding a bibliography. See the manual section on citation rendering for details.

Usage:

-- Lua filter that behaves like `--citeproc`
function Pandoc (doc)
  return pandoc.utils.citeproc(doc)
end

equals

function pandoc.utils.equals(element1: any, element2: any)
  -> boolean

Test equality of AST elements. Elements in Lua are considered equal if and only if the objects obtained by unmarshaling are equal.

This function is deprecated. Use the normal Lua == equality operator instead.

from_simple_table

function pandoc.utils.from_simple_table(table: pandoc.SimpleTable)
  -> pandoc.Table

Creates a Table block element from a SimpleTable. This is useful for dealing with legacy code which was written for pandoc versions older than 2.10.

– Usage:

local simple = pandoc.SimpleTable(table)
-- modify, using pre pandoc 2.10 methods
simple.caption = pandoc.SmallCaps(simple.caption)
-- create normal table block again
table = pandoc.utils.from_simple_table(simple)

make_sections

function pandoc.utils.make_sections(number_sections: boolean, base_level: integer|nil, blocks: any)
  -> pandoc.Blocks

Converts list of Block elements into sections. Divs will be created beginning at each Header and containing following content until the next Header of comparable level. If number_sections is true, a number attribute will be added to each Header containing the section number. If base_level is non-null, Header levels will be reorganized so that there are no gaps, and so that the base level is the level specified.

Deprecated Use pandoc.structure.make_sections instead.

normalize_date

function pandoc.utils.normalize_date(date_string: string)
  -> string|nil

Parse a date and convert (if possible) to “YYYY-MM-DD” format. We limit years to the range 1601-9999 (ISO 8601 accepts greater than or equal to 1583, but MS Word only accepts dates starting 1601).

references

function pandoc.utils.references(doc: pandoc.Pandoc)
  -> table

Get references defined inline in the metadata and via an external bibliography. Only references that are actually cited in the document (either with a genuine citation or with nocite) are returned. URL variables are converted to links.

The structure used represent reference values corresponds to that used in CSL JSON; the return value can be use as references metadata, which is one of the values used by pandoc and citeproc when generating bibliographies.

Usage:

-- Include all cited references in document
function Pandoc (doc)
  doc.meta.references = pandoc.utils.references(doc)
  doc.meta.bibliography = nil
  return doc
end

run_json_filter

function pandoc.utils.run_json_filter(doc: pandoc.Pandoc, filter: string, args?: table)

Filter the given doc by passing it through the a JSON filter.

Usage:

-- Assumes `some_blocks` contains blocks for which a
-- separate literature section is required.
local sub_doc = pandoc.Pandoc(some_blocks, metadata)
sub_doc_with_bib = pandoc.utils.run_json_filter(
  sub_doc,
  'pandoc-citeproc'
)
some_blocks = sub_doc.blocks -- some blocks with bib

run_lua_filter

function pandoc.utils.run_lua_filter(doc: pandoc.Pandoc, filter: table)

Filter the given doc by passing it through a Lua filter.

sha1

function pandoc.utils.sha1(contents: string)
  -> string

Returns the SHA1 has of the contents.

Usage:

local fp = pandoc.utils.sha1("foobar")

stringify

function pandoc.utils.stringify(element: any)
  -> string

Converts the given element (Pandoc, Meta, Block, or Inline) into a string with all formatting removed.

Usage:

local inline = pandoc.Emph{pandoc.Str 'Moin'}
-- outputs "Moin"
print(pandoc.utils.stringify(inline))

to_roman_numeral

function pandoc.utils.to_roman_numeral(value: integer)
  -> string

Converts an integer < 4000 to uppercase roman numeral.

to_simple_table

function pandoc.utils.to_simple_table(table: pandoc.Table)
  -> pandoc.SimpleTable

Creates a SimpleTable out of a Table block.

Usage:

local simple = pandoc.utils.to_simple_table(table)
-- modify, using pre pandoc 2.10 methods
simple.caption = pandoc.SmallCaps(simple.caption)
-- create normal table block again
table = pandoc.utils.from_simple_table(simple)

type

function pandoc.utils.type(value: any)
  -> string

Pandoc-friendly version of Lua’s default type function, returning the type of a value. This function works with all types listed in section [Lua type reference][], except if noted otherwise.

The function works by checking the metafield __name. If the argument has a string-valued metafield __name, then it returns that string. Otherwise it behaves just like the normal type function.

Usage:

-- Prints one of 'string', 'boolean', 'Inlines', 'Blocks',
-- 'table', and 'nil', corresponding to the Haskell constructors
-- MetaString, MetaBool, MetaInlines, MetaBlocks, MetaMap,
-- and an unset value, respectively.
function Meta (meta)
  print('type of metavalue `author`:', pandoc.utils.type(meta.author))
end