git.iko.soy/typeable/pandoc
on 2.0.1 help sign in
typeable/pandoc/data/pandoc.lua
846 lines 25 kB history raw
1--[[
2pandoc.lua
4Copyright © 2017 Albert Krewinkel
6Permission to use, copy, modify, and/or distribute this software for any purpose
7with or without fee is hereby granted, provided that the above copyright notice
8and this permission notice appear in all copies.
10THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
12FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
16THIS SOFTWARE.
17]]
19---
20-- Lua functions for pandoc scripts.
21--
22-- @author Albert Krewinkel
23-- @copyright © 2017 Albert Krewinkel
24-- @license MIT
25local M = {
26 _VERSION = "0.3.0"
29------------------------------------------------------------------------
30-- The base class for pandoc's AST elements.
31-- @type Element
32-- @local
33local Element = {}
35--- Create a new element subtype
36-- @local
37function Element:make_subtype(o)
38 o = o or {}
39 setmetatable(o, self)
40 self.__index = self
41 return o
42end
44--- Create a new element given its tag and arguments
45-- @local
46function Element:new(tag, ...)
47 local element = { t = tag }
48 local content = {...}
49 -- special case for unary constructors
50 if #content == 1 then
51 element.c = content[1]
52 -- Don't set 'c' field if no further arguments were given. This is important
53 -- for nullary constructors like `Space` and `HorizontalRule`.
54 elseif #content > 0 then
55 element.c = content
56 end
57 setmetatable(element, self)
58 self.__index = self
59 return element
60end
62--- Create a new constructor
63-- @local
64-- @param tag Tag used to identify the constructor
65-- @param fn Function to be called when constructing a new element
66-- @param accessors names to use as accessors for numerical fields
67-- @return function that constructs a new element
68function Element:create_constructor(tag, fn, accessors)
69 local constr = self:make_subtype({tag = tag, getters = {}, setters = {}})
71 -- Add accessors to the metatable
72 if type(accessors) == "string" then
73 constr.getters[accessors] = function(elem)
74 return elem.c
75 end
76 constr.setters[accessors] = function(elem, v)
77 elem.c = v
78 end
79 else
80 for i = 1, #(accessors or {}) do
81 if type(accessors[i]) == "string" then
82 constr.getters[accessors[i]] = function(elem)
83 return elem.c[i]
84 end
85 constr.setters[accessors[i]] = function(elem, v)
86 elem.c[i] = v
87 end
88 else -- only two levels of nesting are supported
89 for k, v in ipairs(accessors[i]) do
90 constr.getters[v] = function(elem)
91 return elem.c[i][k]
92 end
93 constr.setters[v] = function(elem, v)
94 elem.c[i][k] = v
95 end
96 end
97 end
98 end
99 end
101 function constr:new(...)
102 local obj = fn(...)
103 setmetatable(obj, self)
104 self.__index = function(t, k)
105 if getmetatable(t).getters[k] then
106 return getmetatable(t).getters[k](t)
107 elseif k == "t" then
108 return getmetatable(t)["tag"]
109 else
110 return getmetatable(t)[k]
111 end
112 end
113 self.__newindex = function(t, k, v)
114 if getmetatable(t).setters[k] then
115 getmetatable(t).setters[k](t, v)
116 else
117 rawset(t, k, v)
118 end
119 end
120 return obj
121 end
122 self.constructor = self.constructor or {}
123 self.constructor[tag] = constr
124 return constr
125end
127--- Calls the constructor, creating a new element.
128-- @local
129function Element.__call(t, ...)
130 return t:new(...)
131end
133------------------------------------------------------------------------
134--- Pandoc Document
135-- @section document
137--- A complete pandoc document
138-- @function Pandoc
139-- @tparam {Block,...} blocks document content
140-- @tparam[opt] Meta meta document meta data
141function M.Pandoc(blocks, meta)
142 meta = meta or {}
143 return {
144 ["blocks"] = blocks,
145 ["meta"] = meta,
146 ["pandoc-api-version"] = {1,17,0,5},
147 }
148end
150-- DEPRECATED synonym:
151M.Doc = M.Pandoc
153------------------------------------------------------------------------
154-- MetaValue
155-- @section MetaValue
156M.MetaValue = Element:make_subtype{}
157M.MetaValue.__call = function(t, ...)
158 return t:new(...)
159end
160--- Meta blocks
161-- @function MetaBlocks
162-- @tparam {Block,...} blocks blocks
164--- Meta inlines
165-- @function MetaInlines
166-- @tparam {Inline,...} inlines inlines
168--- Meta list
169-- @function MetaList
170-- @tparam {MetaValue,...} meta_values list of meta values
172--- Meta map
173-- @function MetaMap
174-- @tparam table key_value_map a string-indexed map of meta values
175M.meta_value_types = {
176 "MetaBlocks",
177 "MetaInlines",
178 "MetaList",
179 "MetaMap",
181for i = 1, #M.meta_value_types do
182 M[M.meta_value_types[i]] = M.MetaValue:create_constructor(
183 M.meta_value_types[i],
184 function(content)
185 return content
186 end
187 )
188end
190--- Creates string to be used in meta data.
191-- Does nothing, lua strings are meta strings.
192-- @function MetaString
193-- @tparam string str string value
194function M.MetaString(str)
195 return str
196end
198--- Creates boolean to be used in meta data.
199-- Does nothing, lua booleans are meta booleans.
200-- @function MetaBool
201-- @tparam boolean bool boolean value
202function M.MetaBool(bool)
203 return bool
204end
206------------------------------------------------------------------------
207-- Blocks
208-- @section Block
210--- Block elements
211M.Block = Element:make_subtype{}
212M.Block.__call = function (t, ...)
213 return t:new(...)
214end
216--- Creates a block quote element
217-- @function BlockQuote
218-- @tparam {Block,...} content block content
219-- @treturn Block block quote element
220M.BlockQuote = M.Block:create_constructor(
221 "BlockQuote",
222 function(content) return {c = content} end,
223 "content"
226--- Creates a bullet (i.e. unordered) list.
227-- @function BulletList
228-- @tparam {{Block,...},...} content list of items
229-- @treturn Block block quote element
230M.BulletList = M.Block:create_constructor(
231 "BulletList",
232 function(content) return {c = content} end,
233 "content"
236--- Creates a code block element
237-- @function CodeBlock
238-- @tparam string text code string
239-- @tparam[opt] Attr attr element attributes
240-- @treturn Block code block element
241M.CodeBlock = M.Block:create_constructor(
242 "CodeBlock",
243 function(text, attr) return {c = {attr or M.Attr(), text}} end,
244 {{"identifier", "classes", "attributes"}, "text"}
247--- Creates a definition list, containing terms and their explanation.
248-- @function DefinitionList
249-- @tparam {{{Inline,...},{Block,...}},...} content list of items
250-- @treturn Block block quote element
251M.DefinitionList = M.Block:create_constructor(
252 "DefinitionList",
253 function(content) return {c = content} end,
254 "content"
257--- Creates a div element
258-- @function Div
259-- @tparam {Block,...} content block content
260-- @tparam[opt] Attr attr element attributes
261-- @treturn Block code block element
262M.Div = M.Block:create_constructor(
263 "Div",
264 function(content, attr)
265 return {c = {attr or M.Attr(), content}}
266 end,
267 {{"identifier", "classes", "attributes"}, "content"}
270--- Creates a block quote element.
271-- @function Header
272-- @tparam int level header level
273-- @tparam {Inline,...} content inline content
274-- @tparam[opt] Attr attr element attributes
275-- @treturn Block header element
276M.Header = M.Block:create_constructor(
277 "Header",
278 function(level, content, attr)
279 return {c = {level, attr or M.Attr(), content}}
280 end,
281 {"level", {"identifier", "classes", "attributes"}, "content"}
284--- Creates a horizontal rule.
285-- @function HorizontalRule
286-- @treturn Block horizontal rule
287M.HorizontalRule = M.Block:create_constructor(
288 "HorizontalRule",
289 function() return {} end
292--- Creates a line block element.
293-- @function LineBlock
294-- @tparam {{Inline,...},...} content inline content
295-- @treturn Block block quote element
296M.LineBlock = M.Block:create_constructor(
297 "LineBlock",
298 function(content) return {c = content} end,
299 "content"
302--- Creates a null element.
303-- @function Null
304-- @treturn Block null element
305M.Null = M.Block:create_constructor(
306 "Null",
307 function() return {} end
310--- Creates an ordered list.
311-- @function OrderedList
312-- @tparam {{Block,...},...} items list items
313-- @param[opt] listAttributes list parameters
314-- @treturn Block
315M.OrderedList = M.Block:create_constructor(
316 "OrderedList",
317 function(items, listAttributes)
318 listAttributes = listAttributes or {1, M.DefaultStyle, M.DefaultDelim}
319 return {c = {listAttributes, items}}
320 end,
321 {{"start", "style", "delimiter"}, "content"}
324--- Creates a para element.
325-- @function Para
326-- @tparam {Inline,...} content inline content
327-- @treturn Block block quote element
328M.Para = M.Block:create_constructor(
329 "Para",
330 function(content) return {c = content} end,
331 "content"
334--- Creates a plain element.
335-- @function Plain
336-- @tparam {Inline,...} content inline content
337-- @treturn Block block quote element
338M.Plain = M.Block:create_constructor(
339 "Plain",
340 function(content) return {c = content} end,
341 "content"
344--- Creates a raw content block of the specified format.
345-- @function RawBlock
346-- @tparam string format format of content
347-- @tparam string text string content
348-- @treturn Block block quote element
349M.RawBlock = M.Block:create_constructor(
350 "RawBlock",
351 function(format, text) return {c = {format, text}} end,
352 {"format", "text"}
355--- Creates a table element.
356-- @function Table
357-- @tparam {Inline,...} caption table caption
358-- @tparam {AlignDefault|AlignLeft|AlignRight|AlignCenter,...} aligns alignments
359-- @tparam {int,...} widths column widths
360-- @tparam {Block,...} headers header row
361-- @tparam {{Block,...}} rows table rows
362-- @treturn Block block quote element
363M.Table = M.Block:create_constructor(
364 "Table",
365 function(caption, aligns, widths, headers, rows)
366 return {c = {caption, aligns, widths, headers, rows}}
367 end,
368 {"caption", "aligns", "widths", "headers", "rows"}
372------------------------------------------------------------------------
373-- Inline
374-- @section Inline
376--- Inline element class
377M.Inline = Element:make_subtype{}
378M.Inline.__call = function (t, ...)
379 return t:new(...)
380end
382--- Creates a Cite inline element
383-- @function Cite
384-- @tparam {Inline,...} content List of inlines
385-- @tparam {Citation,...} citations List of citations
386-- @treturn Inline citations element
387M.Cite = M.Inline:create_constructor(
388 "Cite",
389 function(content, citations) return {c = {citations, content}} end,
390 {"citations", "content"}
393--- Creates a Code inline element
394-- @function Code
395-- @tparam string text brief image description
396-- @tparam[opt] Attr attr additional attributes
397-- @treturn Inline code element
398M.Code = M.Inline:create_constructor(
399 "Code",
400 function(text, attr) return {c = {attr or M.Attr(), text}} end,
401 {{"identifier", "classes", "attributes"}, "text"}
404--- Creates an inline element representing emphasised text.
405-- @function Emph
406-- @tparam {Inline,..} content inline content
407-- @treturn Inline emphasis element
408M.Emph = M.Inline:create_constructor(
409 "Emph",
410 function(content) return {c = content} end,
411 "content"
414--- Creates a Image inline element
415-- @function Image
416-- @tparam {Inline,..} caption text used to describe the image
417-- @tparam string src path to the image file
418-- @tparam[opt] string title brief image description
419-- @tparam[opt] Attr attr additional attributes
420-- @treturn Inline image element
421M.Image = M.Inline:create_constructor(
422 "Image",
423 function(caption, src, title, attr)
424 title = title or ""
425 attr = attr or M.Attr()
426 return {c = {attr, caption, {src, title}}}
427 end,
428 {{"identifier", "classes", "attributes"}, "caption", {"src", "title"}}
431--- Create a LineBreak inline element
432-- @function LineBreak
433-- @treturn Inline linebreak element
434M.LineBreak = M.Inline:create_constructor(
435 "LineBreak",
436 function() return {} end
439--- Creates a link inline element, usually a hyperlink.
440-- @function Link
441-- @tparam {Inline,..} content text for this link
442-- @tparam string target the link target
443-- @tparam[opt] string title brief link description
444-- @tparam[opt] Attr attr additional attributes
445-- @treturn Inline image element
446M.Link = M.Inline:create_constructor(
447 "Link",
448 function(content, target, title, attr)
449 title = title or ""
450 attr = attr or M.Attr()
451 return {c = {attr, content, {target, title}}}
452 end,
453 {{"identifier", "classes", "attributes"}, "content", {"target", "title"}}
456--- Creates a Math element, either inline or displayed.
457-- @function Math
458-- @tparam "InlineMath"|"DisplayMath" mathtype rendering specifier
459-- @tparam string text Math content
460-- @treturn Inline Math element
461M.Math = M.Inline:create_constructor(
462 "Math",
463 function(mathtype, text)
464 return {c = {mathtype, text}}
465 end,
466 {"mathtype", "text"}
468--- Creates a DisplayMath element (DEPRECATED).
469-- @function DisplayMath
470-- @tparam string text Math content
471-- @treturn Inline Math element
472M.DisplayMath = M.Inline:create_constructor(
473 "DisplayMath",
474 function(text) return M.Math("DisplayMath", text) end,
475 {"mathtype", "text"}
477--- Creates an InlineMath inline element (DEPRECATED).
478-- @function InlineMath
479-- @tparam string text Math content
480-- @treturn Inline Math element
481M.InlineMath = M.Inline:create_constructor(
482 "InlineMath",
483 function(text) return M.Math("InlineMath", text) end,
484 {"mathtype", "text"}
487--- Creates a Note inline element
488-- @function Note
489-- @tparam {Block,...} content footnote block content
490M.Note = M.Inline:create_constructor(
491 "Note",
492 function(content) return {c = content} end,
493 "content"
496--- Creates a Quoted inline element given the quote type and quoted content.
497-- @function Quoted
498-- @tparam "DoubleQuote"|"SingleQuote" quotetype type of quotes to be used
499-- @tparam {Inline,..} content inline content
500-- @treturn Inline quoted element
501M.Quoted = M.Inline:create_constructor(
502 "Quoted",
503 function(quotetype, content) return {c = {quotetype, content}} end,
504 {"quotetype", "content"}
506--- Creates a single-quoted inline element (DEPRECATED).
507-- @function SingleQuoted
508-- @tparam {Inline,..} content inline content
509-- @treturn Inline quoted element
510-- @see Quoted
511M.SingleQuoted = M.Inline:create_constructor(
512 "SingleQuoted",
513 function(content) return M.Quoted(M.SingleQuote, content) end,
514 {"quotetype", "content"}
516--- Creates a single-quoted inline element (DEPRECATED).
517-- @function DoubleQuoted
518-- @tparam {Inline,..} content inline content
519-- @treturn Inline quoted element
520-- @see Quoted
521M.DoubleQuoted = M.Inline:create_constructor(
522 "DoubleQuoted",
523 function(content) return M.Quoted("DoubleQuote", content) end,
524 {"quotetype", "content"}
527--- Creates a RawInline inline element
528-- @function RawInline
529-- @tparam string format format of the contents
530-- @tparam string text string content
531-- @treturn Inline raw inline element
532M.RawInline = M.Inline:create_constructor(
533 "RawInline",
534 function(format, text) return {c = {format, text}} end,
535 {"format", "text"}
538--- Creates text rendered in small caps
539-- @function SmallCaps
540-- @tparam {Inline,..} content inline content
541-- @treturn Inline smallcaps element
542M.SmallCaps = M.Inline:create_constructor(
543 "SmallCaps",
544 function(content) return {c = content} end,
545 "content"
548--- Creates a SoftBreak inline element.
549-- @function SoftBreak
550-- @treturn Inline softbreak element
551M.SoftBreak = M.Inline:create_constructor(
552 "SoftBreak",
553 function() return {} end
556--- Create a Space inline element
557-- @function Space
558-- @treturn Inline space element
559M.Space = M.Inline:create_constructor(
560 "Space",
561 function() return {} end
564--- Creates a Span inline element
565-- @function Span
566-- @tparam {Inline,..} content inline content
567-- @tparam[opt] Attr attr additional attributes
568-- @treturn Inline span element
569M.Span = M.Inline:create_constructor(
570 "Span",
571 function(content, attr) return {c = {attr or M.Attr(), content}} end,
572 {{"identifier", "classes", "attributes"}, "content"}
575--- Creates a Str inline element
576-- @function Str
577-- @tparam string text content
578-- @treturn Inline string element
579M.Str = M.Inline:create_constructor(
580 "Str",
581 function(text) return {c = text} end,
582 "text"
585--- Creates text which is striked out.
586-- @function Strikeout
587-- @tparam {Inline,..} content inline content
588-- @treturn Inline strikeout element
589M.Strikeout = M.Inline:create_constructor(
590 "Strikeout",
591 function(content) return {c = content} end,
592 "content"
595--- Creates a Strong element, whose text is usually displayed in a bold font.
596-- @function Strong
597-- @tparam {Inline,..} content inline content
598-- @treturn Inline strong element
599M.Strong = M.Inline:create_constructor(
600 "Strong",
601 function(content) return {c = content} end,
602 "content"
605--- Creates a Subscript inline element
606-- @function Subscript
607-- @tparam {Inline,..} content inline content
608-- @treturn Inline subscript element
609M.Subscript = M.Inline:create_constructor(
610 "Subscript",
611 function(content) return {c = content} end,
612 "content"
615--- Creates a Superscript inline element
616-- @function Superscript
617-- @tparam {Inline,..} content inline content
618-- @treturn Inline strong element
619M.Superscript = M.Inline:create_constructor(
620 "Superscript",
621 function(content) return {c = content} end,
622 "content"
626------------------------------------------------------------------------
627-- Helpers
628-- @section helpers
630-- Attr
631M.Attr = {}
632M.Attr._field_names = {identifier = 1, classes = 2, attributes = 3}
633--- Create a new set of attributes (Attr).
634-- @function Attr
635-- @tparam[opt] string identifier element identifier
636-- @tparam[opt] {string,...} classes element classes
637-- @tparam[opt] table attributes table containing string keys and values
638-- @return element attributes
639M.Attr.__call = function(t, identifier, classes, attributes)
640 identifier = identifier or ''
641 classes = classes or {}
642 attributes = attributes or {}
643 local attr = {identifier, classes, attributes}
644 setmetatable(attr, t)
645 return attr
646end
647M.Attr.__index = function(t, k)
648 return rawget(t, k) or
649 rawget(t, M.Attr._field_names[k]) or
650 rawget(getmetatable(t), k)
651end
652M.Attr.__newindex = function(t, k, v)
653 if M.Attr._field_names[k] then
654 rawset(t, M.Attr._field_names[k], v)
655 else
656 rawset(t, k, v)
657 end
658end
659setmetatable(M.Attr, M.Attr)
662--- Creates a single citation.
663-- @function Citation
664-- @tparam string id citation identifier (like a bibtex key)
665-- @tparam AuthorInText|SuppressAuthor|NormalCitation mode citation mode
666-- @tparam[opt] {Inline,...} prefix citation prefix
667-- @tparam[opt] {Inline,...} suffix citation suffix
668-- @tparam[opt] int note_num note number
669-- @tparam[opt] int hash hash number
670M.Citation = function(id, mode, prefix, suffix, note_num, hash)
671 prefix = prefix or {}
672 suffix = suffix or {}
673 note_num = note_num or 0
674 hash = hash or 0
675 return {
676 citationId = id,
677 citationPrefix = prefix,
678 citationSuffix = suffix,
679 citationMode = mode,
680 citationNoteNum = note_num,
681 citationHash = hash,
682 }
683end
686------------------------------------------------------------------------
687-- Constants
688-- @section constants
690--- Author name is mentioned in the text.
691-- @see Citation
692-- @see Cite
693M.AuthorInText = "AuthorInText"
695--- Author name is suppressed.
696-- @see Citation
697-- @see Cite
698M.SuppressAuthor = "SuppressAuthor"
700--- Default citation style is used.
701-- @see Citation
702-- @see Cite
703M.NormalCitation = "NormalCitation"
705--- Table cells aligned left.
706-- @see Table
707M.AlignLeft = "AlignLeft"
709--- Table cells right-aligned.
710-- @see Table
711M.AlignRight = "AlignRight"
713--- Table cell content is centered.
714-- @see Table
715M.AlignCenter = "AlignCenter"
717--- Table cells are alignment is unaltered.
718-- @see Table
719M.AlignDefault = "AlignDefault"
721--- Default list number delimiters are used.
722-- @see OrderedList
723M.DefaultDelim = "DefaultDelim"
725--- List numbers are delimited by a period.
726-- @see OrderedList
727M.Period = "Period"
729--- List numbers are delimited by a single parenthesis.
730-- @see OrderedList
731M.OneParen = "OneParen"
733--- List numbers are delimited by a double parentheses.
734-- @see OrderedList
735M.TwoParens = "TwoParens"
737--- List are numbered in the default style
738-- @see OrderedList
739M.DefaultStyle = "DefaultStyle"
741--- List items are numbered as examples.
742-- @see OrderedList
743M.Example = "Example"
745--- List are numbered using decimal integers.
746-- @see OrderedList
747M.Decimal = "Decimal"
749--- List are numbered using lower-case roman numerals.
750-- @see OrderedList
751M.LowerRoman = "LowerRoman"
753--- List are numbered using upper-case roman numerals
754-- @see OrderedList
755M.UpperRoman = "UpperRoman"
757--- List are numbered using lower-case alphabetic characters.
758-- @see OrderedList
759M.LowerAlpha = "LowerAlpha"
761--- List are numbered using upper-case alphabetic characters.
762-- @see OrderedList
763M.UpperAlpha = "UpperAlpha"
766------------------------------------------------------------------------
767-- Helper Functions
768-- @section helpers
770--- Parse the given string into a Pandoc document.
771-- The method used to interpret input is specified by *format*. Acceptable
772-- values for this parameter are equal to those that can be given to the
773-- `--from` command line option.
774-- @tparam string markup the markup to be parsed
775-- @tparam[opt] string format format specification, defaults to "markdown".
776-- @treturn Pandoc pandoc document
777-- @usage
778-- local org_markup = "/emphasis/" -- Input to be read
779-- local document = pandoc.read(org_markup, "org")
780-- -- Get the first block of the document
781-- local block = document.blocks[1]
782-- -- The inline element in that block is an `Emph`
783-- assert(block.content[1].t == "Emph")
784function M.read(markup, format)
785 format = format or "markdown"
786 local pd = pandoc._read(format, markup)
787 if type(pd) == "string" then
788 error(pd)
789 else
790 return pd
791 end
792end
794--- Runs command with arguments, passing it some input, and returns the output.
795-- @treturn string Output of command.
796-- @raise A table containing the keys `command`, `error_code`, and `output` is
797-- thrown if the command exits with a non-zero error code.
798-- @usage
799-- local ec, output = pandoc.pipe("sed", {"-e","s/a/b/"}, "abc")
800function M.pipe (command, args, input)
801 local ec, output = pandoc._pipe(command, args, input)
802 if ec ~= 0 then
803 err = setmetatable(
804 { command = command, error_code = ec, output = output},
805 { __tostring = function(e)
806 return "Error running " .. e.command
807 .. " (error code " .. e.error_code .. "): "
808 .. e.output
809 end
810 }
811 )
812 error(err)
813 end
814 return output
815end
817--- Use functions defined in the global namespace to create a pandoc filter.
818-- All globally defined functions which have names of pandoc elements are
819-- collected into a new table.
820-- @return A list of filter functions
821-- @usage
822-- -- within a file defining a pandoc filter:
823-- function Str(text)
824-- return pandoc.Str(utf8.upper(text))
825-- end
826--
827-- return {pandoc.global_filter()}
828-- -- the above is equivallent to
829-- -- return {{Str = Str}}
830function M.global_filter()
831 local res = {}
832 function is_filter_function(k)
833 return M.Inline.constructor[k] or
834 M.Block.constructor[k] or
835 k == "Meta" or k == "Doc" or k == "Pandoc" or
836 k == "Block" or k == "Inline"
837 end
838 for k, v in pairs(_G) do
839 if is_filter_function(k) then
840 res[k] = v
841 end
842 end
843 return res
844end
846return M