Skip to content

Commit

Permalink
fix: Do not load the resilient base class for feature detection
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
Omikhleia authored and Didier Willis committed Jan 28, 2024
1 parent 1a5411f commit 52af1f5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/markdown/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,32 @@ function package:loadPackageAlt(resilientpack, legacypack)
end
end

-- For feature detection.
-- NOTE: The previous implementation was clever;
-- local ok, ResilientBase = pcall(require, 'classes.resilient.base')
-- return ok and self.class:is_a(ResilientBase)
-- However this loads the class, which loads all the silex extensions, even if
-- the class is not used...
-- Enforcing the silex extensions is not what we wanted.
-- So we are back to a more naive implementation, checking the class hierarchy
-- by name.
-- This is lame and knows too much about internals, but heh.
local function isResilientClass(cl)
while cl do
if cl._name == "resilient.base" then
return true
end
cl = cl._base
end
return false
end

function package:_init (_)
base._init(self)

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

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

0 comments on commit 52af1f5

Please sign in to comment.