Skip to content

Commit 6c59c00

Browse files
OmikhleiaDidier Willis
authored andcommitted
fix: Do not load the resilient base class for feature detection
It loaded the whole of the extensions provided by silex.sile, which is not what we wanted outside the resilient usage. It behaves badly with silex.sile 0.4 as overrides would now come too late possibly, causing havoc...
1 parent 1a5411f commit 6c59c00

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

markdown.sile-1.5.2-1.rockspec

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
rockspec_format = "3.0"
2+
package = "markdown.sile"
3+
version = "1.5.2-1"
4+
source = {
5+
url = "git+https://github.com/Omikhleia/markdown.sile.git",
6+
tag = "v1.5.2",
7+
}
8+
description = {
9+
summary = "Native Markdown support for the SILE typesetting system.",
10+
detailed = [[
11+
This package set for the SILE typesetting system provides a complete redesign
12+
of the native Markdown support for SILE, with a great set of Pandoc-like
13+
extensions and plenty of extra goodies.
14+
]],
15+
homepage = "https://github.com/Omikhleia/markdown.sile",
16+
license = "MIT",
17+
}
18+
dependencies = {
19+
"lua >= 5.1",
20+
"embedders.sile >= 0.1.0",
21+
"labelrefs.sile >= 0.1.0",
22+
"ptable.sile >= 2.0.2",
23+
"smartquotes.sile >= 1.0.0",
24+
"textsubsuper.sile >= 1.1.1",
25+
"silex.sile >= 0.4.0",
26+
}
27+
28+
build = {
29+
type = "builtin",
30+
modules = {
31+
["sile.classes.markdown"] = "classes/markdown.lua",
32+
["sile.inputters.markdown"] = "inputters/markdown.lua",
33+
["sile.inputters.pandocast"] = "inputters/pandocast.lua",
34+
["sile.inputters.djot"] = "inputters/djot.lua",
35+
["sile.packages.markdown"] = "packages/markdown/init.lua",
36+
["sile.packages.markdown.commands"] = "packages/markdown/commands.lua",
37+
["sile.packages.markdown.utils"] = "packages/markdown/utils.lua",
38+
["sile.packages.pandocast"] = "packages/pandocast/init.lua",
39+
["sile.packages.djot"] = "packages/djot/init.lua",
40+
41+
["sile.lunamark"] = "lua-libraries/lunamark.lua",
42+
["sile.lunamark.entities"] = "lua-libraries/lunamark/entities.lua",
43+
["sile.lunamark.reader"] = "lua-libraries/lunamark/reader.lua",
44+
["sile.lunamark.reader.markdown"] = "lua-libraries/lunamark/reader/markdown.lua",
45+
["sile.lunamark.util"] = "lua-libraries/lunamark/util.lua",
46+
["sile.lunamark.writer"] = "lua-libraries/lunamark/writer.lua",
47+
["sile.lunamark.writer.generic"] = "lua-libraries/lunamark/writer/generic.lua",
48+
["sile.lunamark.writer.html"] = "lua-libraries/lunamark/writer/html.lua",
49+
["sile.lunamark.writer.html5"] = "lua-libraries/lunamark/writer/html5.lua",
50+
51+
["sile.djot"] = "lua-libraries/djot.lua",
52+
["sile.djot.attributes"] = "lua-libraries/djot/attributes.lua",
53+
["sile.djot.json"] = "lua-libraries/djot/json.lua",
54+
["sile.djot.block"] = "lua-libraries/djot/block.lua",
55+
["sile.djot.inline"] = "lua-libraries/djot/inline.lua",
56+
["sile.djot.html"] = "lua-libraries/djot/html.lua",
57+
["sile.djot.ast"] = "lua-libraries/djot/ast.lua",
58+
["sile.djot.filter"] = "lua-libraries/djot/filter.lua",
59+
}
60+
}

packages/markdown/commands.lua

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,32 @@ function package:loadPackageAlt(resilientpack, legacypack)
147147
end
148148
end
149149

150+
-- For feature detection.
151+
-- NOTE: The previous implementation was clever;
152+
-- local ok, ResilientBase = pcall(require, 'classes.resilient.base')
153+
-- return ok and self.class:is_a(ResilientBase)
154+
-- However this loads the class, which loads all the silex extensions, even if
155+
-- the class is not used...
156+
-- Enforcing the silex extensions is not what we wanted.
157+
-- So we are back to a more naive implementation, checking the class hierarchy
158+
-- by name.
159+
-- This is lame and knows too much about internals, but heh.
160+
local function isResilientClass(cl)
161+
while cl do
162+
if cl._name == "resilient.base" then
163+
return true
164+
end
165+
cl = cl._base
166+
end
167+
return false
168+
end
169+
150170
function package:_init (_)
151171
base._init(self)
152172

153173
-- Check if document class is a resilient class or derived from one
154-
local ok, ResilientBase = pcall(require, 'classes.resilient.base')
155-
self.isResilient = ok and self.class:is_a(ResilientBase)
174+
self.isResilient = isResilientClass(self.class)
175+
SU.debug("markdown", self.isResilient and "Used in a resilient class" or "Used in a non-resilient class")
156176

157177
-- Only load low-level packages (= utilities)
158178
-- The class should be responsible for loading the appropriate higher-level

0 commit comments

Comments
 (0)