Skip to content

Commit 25021e0

Browse files
committed
feat: Move pandoc builtins to their own module and split filters, readers, and writers
1 parent edd9456 commit 25021e0

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

luacheck-dev-1.rockspec

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ build = {
4646
["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua",
4747
["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua",
4848
["luacheck.builtin_standards.minetest"] = "src/luacheck/builtin_standards/minetest.lua",
49+
["luacheck.builtin_standards.pandoc"] = "src/luacheck/builtin_standards/pandoc.lua",
4950
["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua",
5051
["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua",
5152
["luacheck.cache"] = "src/luacheck/cache.lua",

src/luacheck/builtin_standards/init.lua

+5-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local love = require "luacheck.builtin_standards.love"
22
local minetest = require "luacheck.builtin_standards.minetest"
3+
local pandoc = require "luacheck.builtin_standards.pandoc"
34
local playdate = require "luacheck.builtin_standards.playdate"
45
local ngx = require "luacheck.builtin_standards.ngx"
56
local standards = require "luacheck.standards"
@@ -344,25 +345,10 @@ builtin_standards.sile = {
344345
}
345346
}
346347

347-
-- https://pandoc.org/lua-filters.html#global-variables
348-
builtin_standards.pandoc = {
349-
globals = {
350-
-- Global modules
351-
"pandoc", "lpeg", "re",
352-
-- Global variables passed to filters
353-
"FORMAT", "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_VERSION", "PANDOC_API_VERSION",
354-
"PANDOC_SCRIPT_FILE", "PANDOC_STATE",
355-
-- Globals that can be used to create filter elements
356-
-- - top level
357-
"Inlines", "Inline", "Blocks", "Block", "Meta", "Pandoc",
358-
-- - inline
359-
"Cite", "Code", "Emph", "Image", "LineBreak", "Link", "Math", "Note", "Quoted", "RawInline", "SmallCaps",
360-
"SoftBreak", "Space", "Span", "Str", "Strikeout", "Strong", "Subscript", "Superscript", "Underline",
361-
-- - block
362-
"BlockQuote", "BulletList", "CodeBlock", "DefinitionList", "Div", "Figure", "Header", "HorizontalRule",
363-
"LineBlock", "OrderedList", "Para", "Plain", "RawBlock", "Table",
364-
}
365-
}
348+
builtin_standards.pandoc = pandoc.pandoc
349+
builtin_standards.pandoc_filter = pandoc.filter
350+
builtin_standards.pandoc_reader = pandoc.reader
351+
builtin_standards.pandoc_writer = pandoc.writer
366352

367353
builtin_standards.none = {}
368354

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
local add_std_table = require "luacheck.standards".add_std_table
2+
3+
local function combine(...)
4+
local res = {}
5+
for _, def in ipairs({...}) do
6+
add_std_table(res, def)
7+
end
8+
return res.fields
9+
end
10+
11+
local common = {
12+
read_globals = {
13+
"pandoc", "lpeg", "re",
14+
},
15+
}
16+
17+
-- https://pandoc.org/lua-filters.html
18+
local filter = {
19+
read_globals = {
20+
"FORMAT", "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_VERSION", "PANDOC_API_VERSION",
21+
"PANDOC_SCRIPT_FILE", "PANDOC_STATE",
22+
},
23+
globals = {
24+
-- - top level
25+
"Inlines", "Inline", "Blocks", "Block", "Meta", "Pandoc",
26+
-- - inline
27+
"Cite", "Code", "Emph", "Image", "LineBreak", "Link", "Math", "Note", "Quoted", "RawInline", "SmallCaps",
28+
"SoftBreak", "Space", "Span", "Str", "Strikeout", "Strong", "Subscript", "Superscript", "Underline",
29+
-- - block
30+
"BlockQuote", "BulletList", "CodeBlock", "DefinitionList", "Div", "Figure", "Header", "HorizontalRule",
31+
"LineBlock", "OrderedList", "Para", "Plain", "RawBlock", "Table",
32+
},
33+
}
34+
35+
-- https://pandoc.org/custom-readers.html
36+
local reader = {
37+
globals = {
38+
"Reader", "Extensions",
39+
"ByteStringReader"
40+
},
41+
}
42+
43+
-- https://pandoc.org/custom-writers.html
44+
local writer = {
45+
globals = {
46+
"PANDOC_DOCUMENT", "Writer", "Extensions", "Doc", "Template",
47+
"Blocksep", "ByteStringWriter", "CaptionedImage", "DisplayMath", "DoubleQuoted", "InlineMath", "SingleQuoted",
48+
},
49+
}
50+
51+
local variants = {
52+
pandoc = { globals = combine(common, filter, reader, writer) },
53+
filter = { globals = combine(common, filter) },
54+
reader = { globals = combine(common, reader) },
55+
writer = { globals = combine(common, writer) },
56+
}
57+
58+
return variants

0 commit comments

Comments
 (0)