git.iko.soy/typeable/pandoc
on 944ed5e help sign in
typeable/pandoc/data/pandoc.lua
933 lines 27 kB history raw
1--[[
2pandoc.lua
4Copyright © 2017–2018 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–2018 Albert Krewinkel
24-- @license MIT
26local List = require 'pandoc.List'
28M = {}
30------------------------------------------------------------------------
31-- Accessor objects
32--
33-- Create metatables which allow to access numerical indices via accessor
34-- methods.
35-- @section
36-- @local
38--- Create a new indexing function.
39-- @param template function template
40-- @param indices list of indices, starting with the most deeply nested
41-- @return newly created function
42-- @local
43function make_indexing_function(template, indices)
44 local loadstring = loadstring or load
45 local bracketed = {}
46 for i = 1, #indices do
47 bracketed[i] = string.format('[%d]', indices[#indices - i + 1])
48 end
49 local fnstr = string.format('return ' .. template, table.concat(bracketed))
50 return assert(loadstring(fnstr))()
51end
53--- Create accessor functions using a function template.
54-- @param fn_template function template in which '%s' is replacd with indices
55-- @param accessors list of accessors
56-- @return mapping from accessor names to accessor functions
57-- @local
58local function create_accessor_functions (fn_template, accessors)
59 local res = {}
60 function add_accessors(acc, ...)
61 if type(acc) == "string" then
62 res[acc] = make_indexing_function(fn_template, {...})
63 else
64 for i = 1, #(acc or {}) do
65 add_accessors(acc[i], i, ...)
66 end
67 end
68 end
69 add_accessors(accessors)
70 return res
71end
73--- Create a new table which allows to access numerical indices via accessor
74-- functions.
75-- @local
76local function create_accessor_behavior (tag, accessors)
77 local behavior = {tag = tag}
78 behavior.getters = create_accessor_functions(
79 'function (x) return x.c%s end',
80 accessors
81 )
82 behavior.setters = create_accessor_functions(
83 'function (x, v) x.c%s = v end',
84 accessors
85 )
86 behavior.__index = function(t, k)
87 if getmetatable(t).getters[k] then
88 return getmetatable(t).getters[k](t)
89 elseif k == "t" then
90 return getmetatable(t)["tag"]
91 else
92 return getmetatable(t)[k]
93 end
94 end
95 behavior.__newindex = function(t, k, v)
96 if getmetatable(t).setters[k] then
97 getmetatable(t).setters[k](t, v)
98 else
99 rawset(t, k, v)
100 end
101 end
102 return behavior
103end
106------------------------------------------------------------------------
107-- The base class for types
108-- @type Type
109-- @local
110local Type = {}
111Type.name = 'Type'
112Type.__index = Type
113Type.behavior = {
114 __type = Type,
115 new = function (obj)
116 obj = obj or {}
117 setmetatable(obj, self)
118 return obj
119 end
121Type.behavior.__index = Type.behavior
123--- Set a new behavior for the type, inheriting that of the parent type if none
124--- is specified explicitely
125-- @param behavior the behavior object for this type.
126-- @local
127function Type:set_behavior (behavior)
128 behavior = behavior or {}
129 behavior.__index = rawget(behavior, '__index') or behavior
130 behavior.__type = self
131 if not getmetatable(behavior) and getmetatable(self) then
132 setmetatable(behavior, getmetatable(self).behavior)
133 end
134 self.behavior = behavior
135end
137--- Create a new subtype, using the given table as base.
138-- @param name name of the new type
139-- @param[opt] behavior behavioral object for the new type.
140-- @return a new type
141-- @local
142function Type:make_subtype(name, behavior)
143 local newtype = setmetatable({}, self)
144 newtype.name = name
145 newtype.__index = newtype
146 newtype:set_behavior(behavior)
147 return newtype
148end
151------------------------------------------------------------------------
152-- The base class for pandoc's AST elements.
153-- @type AstElement
154-- @local
155local AstElement = Type:make_subtype 'AstElement'
156AstElement.__call = function(t, ...)
157 local success, ret = pcall(t.new, t, ...)
158 if success then
159 return setmetatable(ret, t.behavior)
160 else
161 error(string.format('Constructor for %s failed: %s\n', t.name, ret))
162 end
163end
165--- Make a new subtype which constructs a new value when called.
166-- @local
167function AstElement:make_subtype(...)
168 local newtype = Type.make_subtype(self, ...)
169 newtype.__call = self.__call
170 return newtype
171end
173--- Create a new constructor
174-- @local
175-- @param tag Tag used to identify the constructor
176-- @param fn Function to be called when constructing a new element
177-- @param accessors names to use as accessors for numerical fields
178-- @return function that constructs a new element
179function AstElement:create_constructor(tag, fn, accessors)
180 local constr = self:make_subtype(tag, create_accessor_behavior(tag, accessors))
181 function constr:new(...)
182 return setmetatable(fn(...), self.behavior)
183 end
184 self.constructor = self.constructor or {}
185 self.constructor[tag] = constr
186 return constr
187end
189--- Ensure a given object is an Inline element, or convert it into one.
190local function ensureInlineList (x)
191 if type(x) == string then
192 return List:new{M.Str(x)}
193 elseif x.tag then
194 -- Lists are not tagged, but all elements are
195 return List:new{x}
196 else
197 return x
198 end
199end
201------------------------------------------------------------------------
202--- Pandoc Document
203-- @section document
205--- A complete pandoc document
206-- @function Pandoc
207-- @tparam {Block,...} blocks document content
208-- @tparam[opt] Meta meta document meta data
209M.Pandoc = AstElement:make_subtype'Pandoc'
210function M.Pandoc:new (blocks, meta)
211 return {
212 blocks = List:new(blocks),
213 meta = meta or {},
214 }
215end
217-- DEPRECATED synonym:
218M.Doc = M.Pandoc
220------------------------------------------------------------------------
221-- Meta
222-- @section Meta
224--- Create a new Meta object. It sets the metatable of the given table to
225--- `Meta`.
226-- @function Meta
227-- @tparam meta table table containing document meta information
228M.Meta = AstElement:make_subtype'Meta'
229function M.Meta:new (meta) return meta end
232------------------------------------------------------------------------
233-- MetaValue
234-- @section MetaValue
235M.MetaValue = AstElement:make_subtype('MetaValue')
237--- Meta blocks
238-- @function MetaBlocks
239-- @tparam {Block,...} blocks blocks
240M.MetaBlocks = M.MetaValue:create_constructor(
241 'MetaBlocks',
242 function (content) return List:new(content) end
245--- Meta inlines
246-- @function MetaInlines
247-- @tparam {Inline,...} inlines inlines
248M.MetaInlines = M.MetaValue:create_constructor(
249 'MetaInlines',
250 function (content) return ensureInlineList(content) end
253--- Meta list
254-- @function MetaList
255-- @tparam {MetaValue,...} meta_values list of meta values
256M.MetaList = M.MetaValue:create_constructor(
257 'MetaList',
258 function (content) return List:new(content) end
261--- Meta map
262-- @function MetaMap
263-- @tparam table key_value_map a string-indexed map of meta values
264M.MetaMap = M.MetaValue:create_constructor(
265 "MetaMap",
266 function (mm) return mm end
269--- Creates string to be used in meta data.
270-- Does nothing, lua strings are meta strings.
271-- @function MetaString
272-- @tparam string str string value
273function M.MetaString(str)
274 return str
275end
277--- Creates boolean to be used in meta data.
278-- Does nothing, lua booleans are meta booleans.
279-- @function MetaBool
280-- @tparam boolean bool boolean value
281function M.MetaBool(bool)
282 return bool
283end
285------------------------------------------------------------------------
286-- Blocks
287-- @section Block
289--- Block elements
290M.Block = AstElement:make_subtype'Block'
292--- Creates a block quote element
293-- @function BlockQuote
294-- @tparam {Block,...} content block content
295-- @treturn Block block quote element
296M.BlockQuote = M.Block:create_constructor(
297 "BlockQuote",
298 function(content) return {c = content} end,
299 "content"
302--- Creates a bullet (i.e. unordered) list.
303-- @function BulletList
304-- @tparam {{Block,...},...} content list of items
305-- @treturn Block bullet list element
306M.BulletList = M.Block:create_constructor(
307 "BulletList",
308 function(content) return {c = content} end,
309 "content"
312--- Creates a code block element
313-- @function CodeBlock
314-- @tparam string text code string
315-- @tparam[opt] Attr attr element attributes
316-- @treturn Block code block element
317M.CodeBlock = M.Block:create_constructor(
318 "CodeBlock",
319 function(text, attr) return {c = {attr or M.Attr(), text}} end,
320 {{"identifier", "classes", "attributes"}, "text"}
323--- Creates a definition list, containing terms and their explanation.
324-- @function DefinitionList
325-- @tparam {{{Inline,...},{Block,...}},...} content list of items
326-- @treturn Block definition list element
327M.DefinitionList = M.Block:create_constructor(
328 "DefinitionList",
329 function(content) return {c = List:new(content)} end,
330 "content"
333--- Creates a div element
334-- @function Div
335-- @tparam {Block,...} content block content
336-- @tparam[opt] Attr attr element attributes
337-- @treturn Block div element
338M.Div = M.Block:create_constructor(
339 "Div",
340 function(content, attr)
341 return {c = {attr or M.Attr(), List:new(content)}}
342 end,
343 {{"identifier", "classes", "attributes"}, "content"}
346--- Creates a header element.
347-- @function Header
348-- @tparam int level header level
349-- @tparam {Inline,...} content inline content
350-- @tparam[opt] Attr attr element attributes
351-- @treturn Block header element
352M.Header = M.Block:create_constructor(
353 "Header",
354 function(level, content, attr)
355 return {c = {level, attr or M.Attr(), ensureInlineList(content)}}
356 end,
357 {"level", {"identifier", "classes", "attributes"}, "content"}
360--- Creates a horizontal rule.
361-- @function HorizontalRule
362-- @treturn Block horizontal rule
363M.HorizontalRule = M.Block:create_constructor(
364 "HorizontalRule",
365 function() return {} end
368--- Creates a line block element.
369-- @function LineBlock
370-- @tparam {{Inline,...},...} content inline content
371-- @treturn Block line block element
372M.LineBlock = M.Block:create_constructor(
373 "LineBlock",
374 function(content) return {c = List:new(content)} end,
375 "content"
378--- Creates a null element.
379-- @function Null
380-- @treturn Block null element
381M.Null = M.Block:create_constructor(
382 "Null",
383 function() return {} end
386--- Creates an ordered list.
387-- @function OrderedList
388-- @tparam {{Block,...},...} items list items
389-- @param[opt] listAttributes list parameters
390-- @treturn Block ordered list element
391M.OrderedList = M.Block:create_constructor(
392 "OrderedList",
393 function(items, listAttributes)
394 listAttributes = listAttributes or {1, M.DefaultStyle, M.DefaultDelim}
395 return {c = {listAttributes, List:new(items)}}
396 end,
397 {{"start", "style", "delimiter"}, "content"}
400--- Creates a para element.
401-- @function Para
402-- @tparam {Inline,...} content inline content
403-- @treturn Block paragraph element
404M.Para = M.Block:create_constructor(
405 "Para",
406 function(content) return {c = ensureInlineList(content)} end,
407 "content"
410--- Creates a plain element.
411-- @function Plain
412-- @tparam {Inline,...} content inline content
413-- @treturn Block plain element
414M.Plain = M.Block:create_constructor(
415 "Plain",
416 function(content) return {c = ensureInlineList(content)} end,
417 "content"
420--- Creates a raw content block of the specified format.
421-- @function RawBlock
422-- @tparam string format format of content
423-- @tparam string text string content
424-- @treturn Block raw block element
425M.RawBlock = M.Block:create_constructor(
426 "RawBlock",
427 function(format, text) return {c = {format, text}} end,
428 {"format", "text"}
431--- Creates a table element.
432-- @function Table
433-- @tparam {Inline,...} caption table caption
434-- @tparam {AlignDefault|AlignLeft|AlignRight|AlignCenter,...} aligns alignments
435-- @tparam {int,...} widths column widths
436-- @tparam {Block,...} headers header row
437-- @tparam {{Block,...}} rows table rows
438-- @treturn Block table element
439M.Table = M.Block:create_constructor(
440 "Table",
441 function(caption, aligns, widths, headers, rows)
442 return {
443 c = {
444 ensureInlineList(caption),
445 List:new(aligns),
446 List:new(widths),
447 List:new(headers),
448 List:new(rows)
449 }
450 }
451 end,
452 {"caption", "aligns", "widths", "headers", "rows"}
456------------------------------------------------------------------------
457-- Inline
458-- @section Inline
460--- Inline element class
461M.Inline = AstElement:make_subtype'Inline'
463--- Creates a Cite inline element
464-- @function Cite
465-- @tparam {Inline,...} content List of inlines
466-- @tparam {Citation,...} citations List of citations
467-- @treturn Inline citations element
468M.Cite = M.Inline:create_constructor(
469 "Cite",
470 function(content, citations)
471 return {c = {List:new(citations), ensureInlineList(content)}}
472 end,
473 {"citations", "content"}
476--- Creates a Code inline element
477-- @function Code
478-- @tparam string text brief image description
479-- @tparam[opt] Attr attr additional attributes
480-- @treturn Inline code element
481M.Code = M.Inline:create_constructor(
482 "Code",
483 function(text, attr) return {c = {attr or M.Attr(), text}} end,
484 {{"identifier", "classes", "attributes"}, "text"}
487--- Creates an inline element representing emphasised text.
488-- @function Emph
489-- @tparam {Inline,..} content inline content
490-- @treturn Inline emphasis element
491M.Emph = M.Inline:create_constructor(
492 "Emph",
493 function(content) return {c = ensureInlineList(content)} end,
494 "content"
497--- Creates a Image inline element
498-- @function Image
499-- @tparam {Inline,..} caption text used to describe the image
500-- @tparam string src path to the image file
501-- @tparam[opt] string title brief image description
502-- @tparam[opt] Attr attr additional attributes
503-- @treturn Inline image element
504M.Image = M.Inline:create_constructor(
505 "Image",
506 function(caption, src, title, attr)
507 title = title or ""
508 attr = attr or M.Attr()
509 return {c = {attr, ensureInlineList(caption), {src, title}}}
510 end,
511 {{"identifier", "classes", "attributes"}, "caption", {"src", "title"}}
514--- Create a LineBreak inline element
515-- @function LineBreak
516-- @treturn Inline linebreak element
517M.LineBreak = M.Inline:create_constructor(
518 "LineBreak",
519 function() return {} end
522--- Creates a link inline element, usually a hyperlink.
523-- @function Link
524-- @tparam {Inline,..} content text for this link
525-- @tparam string target the link target
526-- @tparam[opt] string title brief link description
527-- @tparam[opt] Attr attr additional attributes
528-- @treturn Inline image element
529M.Link = M.Inline:create_constructor(
530 "Link",
531 function(content, target, title, attr)
532 title = title or ""
533 attr = attr or M.Attr()
534 return {c = {attr, ensureInlineList(content), {target, title}}}
535 end,
536 {{"identifier", "classes", "attributes"}, "content", {"target", "title"}}
539--- Creates a Math element, either inline or displayed.
540-- @function Math
541-- @tparam "InlineMath"|"DisplayMath" mathtype rendering specifier
542-- @tparam string text Math content
543-- @treturn Inline Math element
544M.Math = M.Inline:create_constructor(
545 "Math",
546 function(mathtype, text)
547 return {c = {mathtype, text}}
548 end,
549 {"mathtype", "text"}
551--- Creates a DisplayMath element (DEPRECATED).
552-- @function DisplayMath
553-- @tparam string text Math content
554-- @treturn Inline Math element
555M.DisplayMath = M.Inline:create_constructor(
556 "DisplayMath",
557 function(text) return M.Math("DisplayMath", text) end,
558 {"mathtype", "text"}
560--- Creates an InlineMath inline element (DEPRECATED).
561-- @function InlineMath
562-- @tparam string text Math content
563-- @treturn Inline Math element
564M.InlineMath = M.Inline:create_constructor(
565 "InlineMath",
566 function(text) return M.Math("InlineMath", text) end,
567 {"mathtype", "text"}
570--- Creates a Note inline element
571-- @function Note
572-- @tparam {Block,...} content footnote block content
573M.Note = M.Inline:create_constructor(
574 "Note",
575 function(content) return {c = List:new(content)} end,
576 "content"
579--- Creates a Quoted inline element given the quote type and quoted content.
580-- @function Quoted
581-- @tparam "DoubleQuote"|"SingleQuote" quotetype type of quotes to be used
582-- @tparam {Inline,..} content inline content
583-- @treturn Inline quoted element
584M.Quoted = M.Inline:create_constructor(
585 "Quoted",
586 function(quotetype, content) return {c = {quotetype, ensureInlineList(content)}} end,
587 {"quotetype", "content"}
589--- Creates a single-quoted inline element (DEPRECATED).
590-- @function SingleQuoted
591-- @tparam {Inline,..} content inline content
592-- @treturn Inline quoted element
593-- @see Quoted
594M.SingleQuoted = M.Inline:create_constructor(
595 "SingleQuoted",
596 function(content) return M.Quoted(M.SingleQuote, content) end,
597 {"quotetype", "content"}
599--- Creates a single-quoted inline element (DEPRECATED).
600-- @function DoubleQuoted
601-- @tparam {Inline,..} content inline content
602-- @treturn Inline quoted element
603-- @see Quoted
604M.DoubleQuoted = M.Inline:create_constructor(
605 "DoubleQuoted",
606 function(content) return M.Quoted("DoubleQuote", content) end,
607 {"quotetype", "content"}
610--- Creates a RawInline inline element
611-- @function RawInline
612-- @tparam string format format of the contents
613-- @tparam string text string content
614-- @treturn Inline raw inline element
615M.RawInline = M.Inline:create_constructor(
616 "RawInline",
617 function(format, text) return {c = {format, text}} end,
618 {"format", "text"}
621--- Creates text rendered in small caps
622-- @function SmallCaps
623-- @tparam {Inline,..} content inline content
624-- @treturn Inline smallcaps element
625M.SmallCaps = M.Inline:create_constructor(
626 "SmallCaps",
627 function(content) return {c = ensureInlineList(content)} end,
628 "content"
631--- Creates a SoftBreak inline element.
632-- @function SoftBreak
633-- @treturn Inline softbreak element
634M.SoftBreak = M.Inline:create_constructor(
635 "SoftBreak",
636 function() return {} end
639--- Create a Space inline element
640-- @function Space
641-- @treturn Inline space element
642M.Space = M.Inline:create_constructor(
643 "Space",
644 function() return {} end
647--- Creates a Span inline element
648-- @function Span
649-- @tparam {Inline,..} content inline content
650-- @tparam[opt] Attr attr additional attributes
651-- @treturn Inline span element
652M.Span = M.Inline:create_constructor(
653 "Span",
654 function(content, attr)
655 return {c = {attr or M.Attr(), ensureInlineList(content)}}
656 end,
657 {{"identifier", "classes", "attributes"}, "content"}
660--- Creates a Str inline element
661-- @function Str
662-- @tparam string text content
663-- @treturn Inline string element
664M.Str = M.Inline:create_constructor(
665 "Str",
666 function(text) return {c = text} end,
667 "text"
670--- Creates text which is striked out.
671-- @function Strikeout
672-- @tparam {Inline,..} content inline content
673-- @treturn Inline strikeout element
674M.Strikeout = M.Inline:create_constructor(
675 "Strikeout",
676 function(content) return {c = ensureInlineList(content)} end,
677 "content"
680--- Creates a Strong element, whose text is usually displayed in a bold font.
681-- @function Strong
682-- @tparam {Inline,..} content inline content
683-- @treturn Inline strong element
684M.Strong = M.Inline:create_constructor(
685 "Strong",
686 function(content) return {c = ensureInlineList(content)} end,
687 "content"
690--- Creates a Subscript inline element
691-- @function Subscript
692-- @tparam {Inline,..} content inline content
693-- @treturn Inline subscript element
694M.Subscript = M.Inline:create_constructor(
695 "Subscript",
696 function(content) return {c = ensureInlineList(content)} end,
697 "content"
700--- Creates a Superscript inline element
701-- @function Superscript
702-- @tparam {Inline,..} content inline content
703-- @treturn Inline strong element
704M.Superscript = M.Inline:create_constructor(
705 "Superscript",
706 function(content) return {c = ensureInlineList(content)} end,
707 "content"
711------------------------------------------------------------------------
712-- Element components
713-- @section components
715--- Check if the first element of a pair matches the given value.
716-- @param x key value to be checked
717-- @return function returning true iff first element of its argument matches x
718-- @local
719local function assoc_key_equals (x)
720 return function (y) return y[1] == x end
721end
723--- Lookup a value in an associative list
724-- @function lookup
725-- @local
726-- @tparam {{key, value},...} alist associative list
727-- @param key key for which the associated value is to be looked up
728local function lookup(alist, key)
729 return (List.find_if(alist, assoc_key_equals(key)) or {})[2]
730end
732--- Return an iterator which returns key-value pairs of an associative list.
733-- @function apairs
734-- @local
735-- @tparam {{key, value},...} alist associative list
736local apairs = function (alist)
737 local i = 1
738 local cur
739 function nxt ()
740 cur = rawget(alist, i)
741 if cur then
742 i = i + 1
743 return cur[1], cur[2]
744 end
745 return nil
746 end
747 return nxt, nil, nil
748end
750--- AttributeList, a metatable to allow table-like access to attribute lists
751-- represented by associative lists.
752-- @local
753local AttributeList = {
754 __index = function (t, k)
755 if type(k) == "number" then
756 return rawget(t, k)
757 else
758 return lookup(t, k)
759 end
760 end,
762 __newindex = function (t, k, v)
763 local cur, idx = List.find_if(t, assoc_key_equals(k))
764 if v == nil then
765 table.remove(t, idx)
766 elseif cur then
767 cur[2] = v
768 elseif type(k) == "number" then
769 rawset(t, k, v)
770 else
771 rawset(t, #t + 1, {k, v})
772 end
773 end,
775 __pairs = apairs
778--- Convert a table to an associative list. The order of key-value pairs in the
779-- alist is undefined. The table should either contain no numeric keys or
780-- already be an associative list.
781-- @local
782-- @tparam table tbl associative list or table without numeric keys.
783-- @treturn table associative list
784local to_alist = function (tbl)
785 if #tbl ~= 0 or next(tbl) == nil then
786 -- probably already an alist
787 return tbl
788 end
789 local alist = {}
790 local i = 1
791 for k, v in pairs(tbl) do
792 alist[i] = {k, v}
793 i = i + 1
794 end
795 return alist
796end
798-- Attr
800--- Create a new set of attributes (Attr).
801-- @function Attr
802-- @tparam[opt] string identifier element identifier
803-- @tparam[opt] {string,...} classes element classes
804-- @tparam[opt] table attributes table containing string keys and values
805-- @return element attributes
806M.Attr = AstElement:make_subtype'Attr'
807function M.Attr:new (identifier, classes, attributes)
808 identifier = identifier or ''
809 classes = List:new(classes or {})
810 attributes = setmetatable(to_alist(attributes or {}), AttributeList)
811 return {identifier, classes, attributes}
812end
813M.Attr.behavior._field_names = {identifier = 1, classes = 2, attributes = 3}
814M.Attr.behavior.__index = function(t, k)
815 return rawget(t, getmetatable(t)._field_names[k]) or
816 getmetatable(t)[k]
817end
818M.Attr.behavior.__newindex = function(t, k, v)
819 if getmetatable(t)._field_names[k] then
820 rawset(t, getmetatable(t)._field_names[k], v)
821 else
822 rawset(t, k, v)
823 end
824end
826-- Citation
827M.Citation = AstElement:make_subtype'Citation'
829--- Creates a single citation.
830-- @function Citation
831-- @tparam string id citation identifier (like a bibtex key)
832-- @tparam AuthorInText|SuppressAuthor|NormalCitation mode citation mode
833-- @tparam[opt] {Inline,...} prefix citation prefix
834-- @tparam[opt] {Inline,...} suffix citation suffix
835-- @tparam[opt] int note_num note number
836-- @tparam[opt] int hash hash number
837function M.Citation:new (id, mode, prefix, suffix, note_num, hash)
838 return {
839 id = id,
840 mode = mode,
841 prefix = prefix or {},
842 suffix = suffix or {},
843 note_num = note_num or 0,
844 hash = hash or 0,
845 }
846end
849------------------------------------------------------------------------
850-- Constants
851-- @section constants
853--- Author name is mentioned in the text.
854-- @see Citation
855-- @see Cite
856M.AuthorInText = "AuthorInText"
858--- Author name is suppressed.
859-- @see Citation
860-- @see Cite
861M.SuppressAuthor = "SuppressAuthor"
863--- Default citation style is used.
864-- @see Citation
865-- @see Cite
866M.NormalCitation = "NormalCitation"
868--- Table cells aligned left.
869-- @see Table
870M.AlignLeft = "AlignLeft"
872--- Table cells right-aligned.
873-- @see Table
874M.AlignRight = "AlignRight"
876--- Table cell content is centered.
877-- @see Table
878M.AlignCenter = "AlignCenter"
880--- Table cells are alignment is unaltered.
881-- @see Table
882M.AlignDefault = "AlignDefault"
884--- Default list number delimiters are used.
885-- @see OrderedList
886M.DefaultDelim = "DefaultDelim"
888--- List numbers are delimited by a period.
889-- @see OrderedList
890M.Period = "Period"
892--- List numbers are delimited by a single parenthesis.
893-- @see OrderedList
894M.OneParen = "OneParen"
896--- List numbers are delimited by a double parentheses.
897-- @see OrderedList
898M.TwoParens = "TwoParens"
900--- List are numbered in the default style
901-- @see OrderedList
902M.DefaultStyle = "DefaultStyle"
904--- List items are numbered as examples.
905-- @see OrderedList
906M.Example = "Example"
908--- List are numbered using decimal integers.
909-- @see OrderedList
910M.Decimal = "Decimal"
912--- List are numbered using lower-case roman numerals.
913-- @see OrderedList
914M.LowerRoman = "LowerRoman"
916--- List are numbered using upper-case roman numerals
917-- @see OrderedList
918M.UpperRoman = "UpperRoman"
920--- List are numbered using lower-case alphabetic characters.
921-- @see OrderedList
922M.LowerAlpha = "LowerAlpha"
924--- List are numbered using upper-case alphabetic characters.
925-- @see OrderedList
926M.UpperAlpha = "UpperAlpha"
928------------------------------------------------------------------------
929-- Functions which have moved to different modules
930local utils = require 'pandoc.utils'
931M.sha1 = utils.sha1
933return M