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
20-- Lua functions for pandoc scripts.
22-- @author Albert Krewinkel
23-- @copyright © 2017 Albert Krewinkel
32setmetatable(M.Attributes, M.Attributes)
34M.Attributes.__index = function(t, k)
37 elseif k == "class" then
38 return table.concat(t[2], ' ')
44--- Create a new set of attributes (Attr).
45-- @function Attributes
46M.Attributes.__call = function(t, key_values, id, classes)
48 for i = 1, #key_values do
49 kv[key_values[i][1]] = key_values[i][2]
52 classes = classes or {}
53 local attr = {id, classes, key_values, kv = kv}
57M.Attributes.empty = M.Attributes('', {}, {})
60--- Creates a single citation.
62-- @tparam string id citation identifier (like a bibtex key)
63-- @tparam AuthorInText|SuppressAuthor|NormalCitation mode citation mode
64-- @tparam[opt] {Inline,...} prefix citation prefix
65-- @tparam[opt] {Inline,...} suffix citation suffix
66-- @tparam[opt] int note_num note number
67-- @tparam[opt] int note_num hash number
68M.Citation = function(id, mode, prefix, suffix, note_num, hash)
71 note_num = note_num or 0
75 citationPrefix = prefix,
76 citationSuffix = suffix,
78 citationNoteNum = note_num,
83------------------------------------------------------------------------
84-- The base class for pandoc's AST elements.
89--- Create a new element subtype
91function Element:make_subtype(o)
98--- Create a new element given its tag and arguments
100function Element:new(tag, ...)
101 local element = { t = tag }
102 local content = {...}
103 -- special case for unary constructors
104 if #content == 1 then
105 element.c = content[1]
106 -- Don't set 'c' field if no further arguments were given. This is important
107 -- for nullary constructors like `Space` and `HorizontalRule`.
108 elseif #content > 0 then
111 setmetatable(element, self)
116--- Create a new constructor
118-- @param tag Tag used to identify the constructor
119-- @param fn Function to be called when constructing a new element
120-- @return function that constructs a new element
121function Element:create_constructor(tag, fn)
122 local constr = self:make_subtype({tag = tag})
123 function constr:new(...)
125 setmetatable(obj, self)
126 self.__index = function(t, k)
130 return getmetatable(t)["tag"]
132 return getmetatable(t)[k]
137 self.constructor = self.constructor or {}
138 self.constructor[tag] = constr
142--- Calls the constructor, creating a new element.
144function Element.__call(t, ...)
148------------------------------------------------------------------------
152--- A complete pandoc document
154-- @tparam {Block,...} blocks document content
155-- @tparam[opt] Meta meta document meta data
156function M.Doc(blocks, meta)
161 ["pandoc-api-version"] = {1,17,0,5},
166------------------------------------------------------------------------
169M.MetaValue = Element:make_subtype{}
170M.MetaValue.__call = function(t, ...)
174-- @function MetaBlocks
175-- @tparam {Block,...} blocks blocks
178-- @function MetaInlines
179-- @tparam {Inline,...} inlines inlines
183-- @tparam {MetaValue,...} meta_values list of meta values
187-- @tparam boolean bool boolean value
191-- @tparam table a string-index map of meta values
194-- @function MetaString
195-- @tparam string str string value
196M.meta_value_types = {
204for i = 1, #M.meta_value_types do
205 M[M.meta_value_types[i]] = M.MetaValue:create_constructor(
206 M.meta_value_types[i],
213------------------------------------------------------------------------
217M.Block = Element:make_subtype{}
218M.Block.__call = function (t, ...)
222--- Creates a block quote element
223-- @function BlockQuote
224-- @tparam {Block,...} content block content
225-- @treturn Block block quote element
226M.BlockQuote = M.Block:create_constructor(
228 function(content) return {c = content} end
231--- Creates a bullet (i.e. unordered) list.
232-- @function BulletList
233-- @tparam {{Block,...},...} content list of items
234-- @treturn Block block quote element
235M.BulletList = M.Block:create_constructor(
237 function(content) return {c = content} end
240--- Creates a code block element
241-- @function CodeBlock
242-- @tparam string code code string
243-- @tparam[opt] Attributes attributes element attributes
244-- @treturn Block code block element
245M.CodeBlock = M.Block:create_constructor(
247 function(code, attributes) return {c = {attributes, code}} end
250--- Creates a definition list, containing terms and their explanation.
251-- @function DefinitionList
252-- @tparam {{{Inline,...},{Block,...}},...} content list of items
253-- @treturn Block block quote element
254M.DefinitionList = M.Block:create_constructor(
256 function(content) return {c = content} end
259--- Creates a div element
261-- @tparam {Block,...} content block content
262-- @tparam[opt] Attributes attributes element attributes
263-- @treturn Block code block element
264M.Div = M.Block:create_constructor(
266 function(content, attributes) return {c = {attributes, content}} end
269--- Creates a block quote element.
271-- @tparam int level header level
272-- @tparam Attributes attributes element attributes
273-- @tparam {Inline,...} content inline content
274-- @treturn Block header element
275M.Header = M.Block:create_constructor(
277 function(level, attributes, content)
278 return {c = {level, attributes, content}}
282--- Creates a horizontal rule.
283-- @function HorizontalRule
284-- @treturn Block horizontal rule
285M.HorizontalRule = M.Block:create_constructor(
287 function() return {} end
290--- Creates a line block element.
291-- @function LineBlock
292-- @tparam {{Inline,...},...} content inline content
293-- @treturn Block block quote element
294M.LineBlock = M.Block:create_constructor(
296 function(content) return {c = content} end
299--- Creates a null element.
301-- @treturn Block null element
302M.Null = M.Block:create_constructor(
304 function() return {} end
307--- Creates an ordered list.
308-- @function OrderedList
309-- @tparam {{Block,...},...} items list items
310-- @param[opt] listAttributes list parameters
312M.OrderedList = M.Block:create_constructor(
314 function(items, listAttributes)
315 return {c = {listAttributes,items}}
319--- Creates a para element.
321-- @tparam {Inline,...} content inline content
322-- @treturn Block block quote element
323M.Para = M.Block:create_constructor(
325 function(content) return {c = content} end
328--- Creates a plain element.
330-- @tparam {Inline,...} content inline content
331-- @treturn Block block quote element
332M.Plain = M.Block:create_constructor(
334 function(content) return {c = content} end
337--- Creates a raw content block of the specified format.
339-- @tparam string format format of content
340-- @tparam string content string content
341-- @treturn Block block quote element
342M.RawBlock = M.Block:create_constructor(
344 function(format, content) return {c = {format, content}} end
347--- Creates a table element.
349-- @tparam {Inline,...} caption table caption
350-- @tparam {AlignDefault|AlignLeft|AlignRight|AlignCenter,...} aligns alignments
351-- @tparam {int,...} widths column widths
352-- @tparam {Block,...} headers header row
353-- @tparam {{Block,...}} rows table rows
354-- @treturn Block block quote element
355M.Table = M.Block:create_constructor(
357 function(caption, aligns, widths, headers, rows)
358 return {c = {caption, aligns, widths, headers, rows}}
363------------------------------------------------------------------------
367--- Inline element class
368M.Inline = Element:make_subtype{}
369M.Inline.__call = function (t, ...)
373--- Creates a Cite inline element
375-- @tparam {Inline,...} content List of inlines
376-- @tparam {Citation,...} citations List of citations
377-- @treturn Inline citations element
378M.Cite = M.Inline:create_constructor(
380 function(content, citations) return {c = {citations, content}} end
383--- Creates a Code inline element
385-- @tparam string code brief image description
386-- @tparam[opt] Attributes attributes additional attributes
387-- @treturn Inline code element
388M.Code = M.Inline:create_constructor(
390 function(code, attributes) return {c = {attributes, code}} end
393--- Creates an inline element representing emphasised text.
395-- @tparam {Inline,..} content inline content
396-- @treturn Inline emphasis element
397M.Emph = M.Inline:create_constructor(
399 function(content) return {c = content} end
402--- Creates a Image inline element
404-- @tparam {Inline,..} caption text used to describe the image
405-- @tparam string src path to the image file
406-- @tparam[opt] string title brief image description
407-- @tparam[opt] Attributes attributes additional attributes
408-- @treturn Inline image element
409M.Image = M.Inline:create_constructor(
411 function(caption, src, title, attributes)
413 attributes = attributes or Attribute.empty
414 return {c = {attributes, caption, {src, title}}}
418--- Create a LineBreak inline element
419-- @function LineBreak
420-- @treturn Inline linebreak element
421M.LineBreak = M.Inline:create_constructor(
423 function() return {} end
426--- Creates a link inline element, usually a hyperlink.
428-- @tparam {Inline,..} content text for this link
429-- @tparam string target the link target
430-- @tparam[opt] string title brief link description
431-- @tparam[opt] Attributes attributes additional attributes
432-- @treturn Inline image element
433M.Link = M.Inline:create_constructor(
435 function(content, target, title, attributes)
437 attributes = attributes or Attribute.empty
438 return {c = {attributes, content, {target, title}}}
442--- Creates a Math inline element
444-- @tparam InlineMath|DisplayMath mathtype Display specifier
445-- @tparam string text Math content
446-- @treturn Inline Math element
447M.Math = M.Inline:create_constructor(
449 function(mathtype, text)
450 return {c = {mathtype, text}}
454--- Creates a Note inline element
456-- @tparam {Block,...} content footnote block content
457M.Note = M.Inline:create_constructor(
459 function(contents) return {c = contents} end
462--- Creates a Quoted inline element
464-- @tparam DoubleQuote|SingleQuote quotetype type of quotes to be used
465-- @tparam {Inline,..} content inline content
466-- @treturn Inline quoted element
467M.Quoted = M.Inline:create_constructor(
469 function(quotetype, content) return {c = {quotetype, content}} end
471--- Creates a RawInline inline element
472-- @function RawInline
473-- @tparam string format format of the contents
474-- @tparam string text string content
475-- @treturn Inline raw inline element
476M.RawInline = M.Inline:create_constructor(
478 function(format, text) return {c = {format, text}} end
481--- Creates text rendered in small caps
482-- @function SmallCaps
483-- @tparam {Inline,..} content inline content
484-- @treturn Inline smallcaps element
485M.SmallCaps = M.Inline:create_constructor(
487 function(content) return {c = content} end
490--- Creates a SoftBreak inline element.
491-- @function SoftBreak
492-- @treturn Inline softbreak element
493M.SoftBreak = M.Inline:create_constructor(
495 function() return {} end
498--- Create a Space inline element
500-- @treturn Inline space element
501M.Space = M.Inline:create_constructor(
503 function() return {} end
506--- Creates a Span inline element
508-- @tparam {Inline,..} content inline content
509-- @tparam[opt] Attributes attributes additional attributes
510-- @treturn Inline span element
511M.Span = M.Inline:create_constructor(
513 function(content, attributes) return {c = {attributes, content}} end
516--- Creates a Str inline element
518-- @tparam string text content
519-- @treturn Inline string element
520M.Str = M.Inline:create_constructor(
522 function(text) return {c = text} end
525--- Creates text which is striked out.
526-- @function Strikeout
527-- @tparam {Inline,..} content inline content
528-- @treturn Inline strikeout element
529M.Strikeout = M.Inline:create_constructor(
531 function(content) return {c = content} end
534--- Creates a Strong element, whose text is usually displayed in a bold font.
536-- @tparam {Inline,..} content inline content
537-- @treturn Inline strong element
538M.Strong = M.Inline:create_constructor(
540 function(content) return {c = content} end
543--- Creates a Subscript inline element
544-- @function Subscript
545-- @tparam {Inline,..} content inline content
546-- @treturn Inline subscript element
547M.Subscript = M.Inline:create_constructor(
549 function(content) return {c = content} end
552--- Creates a Superscript inline element
553-- @function Superscript
554-- @tparam {Inline,..} content inline content
555-- @treturn Inline strong element
556M.Superscript = M.Inline:create_constructor(
558 function(content) return {c = content} end
562------------------------------------------------------------------------
566--- Math content is to be displayed on a separate line.
569M.DisplayMath.t = "DisplayMath"
570--- Math content is to be displayed inline within the paragraph
573M.InlineMath.t = "InlineMath"
575--- Double quoted content.
578M.DoubleQuote.t = "DoubleQuote"
580--- Single quoted content.
583M.SingleQuote.t = "SingleQuote"
585--- Author name is mentioned in the text.
589M.AuthorInText.t = "AuthorInText"
591--- Author name is suppressed.
595M.SuppressAuthor.t = "SuppressAuthor"
597--- Default citation style is used.
601M.NormalCitation.t = "NormalCitation"
603--- Table cells aligned left.
606M.AlignLeft.t = "AlignLeft"
608--- Table cells right-aligned.
611M.AlignRight.t = "AlignRight"
613--- Table cell content is centered.
616M.AlignCenter.t = "AlignCenter"
618--- Table cells are alignment is unaltered.
621M.AlignDefault.t = "AlignDefault"
623--- Default list number delimiters are used.
626M.DefaultDelim.t = "DefaultDelim"
628--- List numbers are delimited by a period.
633--- List numbers are delimited by a single parenthesis.
636M.OneParen.t = "OneParen"
638--- List numbers are delimited by a double parentheses.
641M.TwoParens.t = "TwoParens"
643--- List are numbered in the default style
646M.DefaultStyle.t = "DefaultStyle"
648--- List items are numbered as examples.
651M.Example.t = "Example"
653--- List are numbered using decimal integers.
656M.Decimal.t = "Decimal"
658--- List are numbered using lower-case roman numerals.
661M.LowerRoman.t = "LowerRoman"
663--- List are numbered using upper-case roman numerals
666M.UpperRoman.t = "UpperRoman"
668--- List are numbered using lower-case alphabetic characters.
671M.LowerAlpha.t = "LowerAlpha"
673--- List are numbered using upper-case alphabetic characters.
676M.UpperAlpha.t = "UpperAlpha"
679------------------------------------------------------------------------
683--- Use functions defined in the global namespace to create a pandoc filter.
684-- All globally defined functions which have names of pandoc elements are
685-- collected into a new table.
686-- @return A list of filter functions
688-- -- within a file defining a pandoc filter:
690-- return pandoc.Str(utf8.upper(text))
693-- return {pandoc.global_filter()}
694-- -- the above is equivallent to
695-- -- return {{Str = Str}}
696function M.global_filter()
698 for k, v in pairs(_G) do
699 if M.Inline.constructor[k] or M.Block.constructor[k] or M.Block.constructors[k] or k == "Doc" then
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list