Skip to content

Commit

Permalink
Merge pull request #102 from Omikhleia/fix-lua51-compat
Browse files Browse the repository at this point in the history
Lua 5.1 minimum compatibility
  • Loading branch information
Omikhleia authored Dec 28, 2023
2 parents 1846d38 + 27a3e19 commit 1a5411f
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Luacheck
uses: lunarmodules/luacheck@v0
uses: lunarmodules/luacheck@v1
61 changes: 47 additions & 14 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,32 +1,65 @@
std = "max"
std = "min+sile"
include_files = {
"**/*.lua",
"sile.in",
"*.rockspec",
".busted",
".luacheckrc"
}
exclude_files = {
"benchmark-*",
"compare-*",
"sile-*",
"lua_modules",
"lua-libraries",
".lua",
".luarocks",
".install"
}
globals = {
-- acceptable as SILE has the necessary compatibility shims:
-- pl.utils.unpack provides extra functionality and nil handling
-- but our modules shouldn't be using that anyway.
"table.unpack"
}
files["**/*_spec.lua"] = {
std = "+busted"
}
globals = {
"SILE",
"SU",
"luautf8",
"pl",
"fluent",
"SYSTEM_SILE_PATH",
"SHARED_LIB_EXT"
-- Vendored libraries with our modifications and/or extensions:
-- We want to ensure a minimal level of decent linting on these files
-- in order to avoid the worst mistakes when modifying them.
files["lua-libraries/lunamark"] = {
globals = {
-- used in compatibility shims and feature detection
"loadstring",
"setfenv",
"unpack",
"utf8",
},
}
files["lua-libraries/djot.lua"] = {
globals = {
-- used in compatibility shims and feature detection
"unpack",
},
ignore = {
-- -- matter of taste and not harmful
"211", -- unused function / unused variable
"212", -- unused argument
}
}
files["lua-libraries/djot"] = {
globals = {
-- used in compatibility shims and feature detection
"loadstring",
"unpack",
"utf8",
},
ignore = {
-- usually bad but used in compatiblity shims...
"121", -- setting a read-only global variable
-- usually questionable but weird use in constructors...
"312", -- value of argument self is overwritten before use
-- matter of taste and not harmful
"211", -- unused function / unused variable
"212", -- unused argument
"213", -- unused loop variable
}
}
max_line_length = false
ignore = {
Expand Down
2 changes: 1 addition & 1 deletion inputters/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local function extractLineBlockLevel (inlines)
if f and type(f) == "string" then
local line = f
line = line:gsub("^[ ]+", function (match) -- Warning, U+00A0 here.
level = utf8.len(match)
level = luautf8.len(match)
return ""
end)
if line == "" then -- and #inlines == 1 then
Expand Down
2 changes: 1 addition & 1 deletion inputters/pandocast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ local function extractLineBlockLevel (inlines)
-- Or any other inline content if there are not leading spaces.
local line = f.c
line = line:gsub("^[ ]+", function (match) -- Warning, U+00A0 here.
level = utf8.len(match)
level = luautf8.len(match)
return ""
end)
f.c = line -- replace
Expand Down
11 changes: 7 additions & 4 deletions lua-libraries/djot/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ local escape_char_map = {
[ "\t" ] = "t",
}

local escape_char_map_inv = { [ "/" ] = "/" }
for k, v in pairs(escape_char_map) do
escape_char_map_inv[v] = k
end
-- BEGIN EXTENSION DIDIER 20231227
-- This escape_char_map_inv is not used...
-- local escape_char_map_inv = { [ "/" ] = "/" }
-- for k, v in pairs(escape_char_map) do
-- escape_char_map_inv[v] = k
-- end
-- END EXTENSION DIDIER 20231227


local function escape_char(c)
Expand Down
16 changes: 8 additions & 8 deletions lua-libraries/lunamark/reader/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ parsers.attrvalue = (parsers.dquote
* parsers.squote)
+ C((parsers.anyescaped - parsers.dquote - parsers.space - P("}"))^1)

parsers.attrpair = Cg(C((parsers.attrid)^1)
parsers.attrpair = Cg(C(parsers.attrid)
* parsers.optionalspace * parsers.equal * parsers.optionalspace
* parsers.attrvalue)
* parsers.optionalspace^-1
Expand Down Expand Up @@ -1221,12 +1221,11 @@ function M.new(writer, options)
parsers.doubletildes)
) / writer.strikeout

larsers.Mark
= ( parsers.between(parsers.Inline, parsers.doubleequals,
parsers.doubleequals)
) / function (inlines, x, y)
return writer.span(inlines, { class="mark" })
end
larsers.Mark = parsers.between(parsers.Inline, parsers.doubleequals,
parsers.doubleequals)
/ function (inlines)
return writer.span(inlines, { class="mark" })
end

larsers.Span = ( parsers.between(parsers.Inline, parsers.lbracket,
parsers.rbracket) ) * ( parsers.attributes )
Expand Down Expand Up @@ -1402,7 +1401,8 @@ function M.new(writer, options)
larsers.Blockquote = Cs((((parsers.leader * parsers.more * parsers.space^-1)/""
* parsers.linechar^0 * parsers.newline)^1
* (-(parsers.leader * parsers.more
+ parsers.blankline + larsers.fenced_div_out) * parsers.linechar^1
+ parsers.blankline
+ larsers.fenced_div_out) * parsers.linechar^1
* parsers.newline)^0 * parsers.blankline^0
)^1) / parse_blocks / writer.blockquote

Expand Down
60 changes: 60 additions & 0 deletions markdown.sile-1.5.1-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
rockspec_format = "3.0"
package = "markdown.sile"
version = "1.5.1-1"
source = {
url = "git+https://github.com/Omikhleia/markdown.sile.git",
tag = "v1.5.1",
}
description = {
summary = "Native Markdown support for the SILE typesetting system.",
detailed = [[
This package set for the SILE typesetting system provides a complete redesign
of the native Markdown support for SILE, with a great set of Pandoc-like
extensions and plenty of extra goodies.
]],
homepage = "https://github.com/Omikhleia/markdown.sile",
license = "MIT",
}
dependencies = {
"lua >= 5.1",
"embedders.sile >= 0.1.0",
"labelrefs.sile >= 0.1.0",
"ptable.sile >= 2.0.2",
"smartquotes.sile >= 1.0.0",
"textsubsuper.sile >= 1.1.1",
"silex.sile >= 0.3.0",
}

build = {
type = "builtin",
modules = {
["sile.classes.markdown"] = "classes/markdown.lua",
["sile.inputters.markdown"] = "inputters/markdown.lua",
["sile.inputters.pandocast"] = "inputters/pandocast.lua",
["sile.inputters.djot"] = "inputters/djot.lua",
["sile.packages.markdown"] = "packages/markdown/init.lua",
["sile.packages.markdown.commands"] = "packages/markdown/commands.lua",
["sile.packages.markdown.utils"] = "packages/markdown/utils.lua",
["sile.packages.pandocast"] = "packages/pandocast/init.lua",
["sile.packages.djot"] = "packages/djot/init.lua",

["sile.lunamark"] = "lua-libraries/lunamark.lua",
["sile.lunamark.entities"] = "lua-libraries/lunamark/entities.lua",
["sile.lunamark.reader"] = "lua-libraries/lunamark/reader.lua",
["sile.lunamark.reader.markdown"] = "lua-libraries/lunamark/reader/markdown.lua",
["sile.lunamark.util"] = "lua-libraries/lunamark/util.lua",
["sile.lunamark.writer"] = "lua-libraries/lunamark/writer.lua",
["sile.lunamark.writer.generic"] = "lua-libraries/lunamark/writer/generic.lua",
["sile.lunamark.writer.html"] = "lua-libraries/lunamark/writer/html.lua",
["sile.lunamark.writer.html5"] = "lua-libraries/lunamark/writer/html5.lua",

["sile.djot"] = "lua-libraries/djot.lua",
["sile.djot.attributes"] = "lua-libraries/djot/attributes.lua",
["sile.djot.json"] = "lua-libraries/djot/json.lua",
["sile.djot.block"] = "lua-libraries/djot/block.lua",
["sile.djot.inline"] = "lua-libraries/djot/inline.lua",
["sile.djot.html"] = "lua-libraries/djot/html.lua",
["sile.djot.ast"] = "lua-libraries/djot/ast.lua",
["sile.djot.filter"] = "lua-libraries/djot/filter.lua",
}
}

0 comments on commit 1a5411f

Please sign in to comment.