Skip to content

Commit cedef50

Browse files
authored
use invokelatest to use reflection functions in the latest world (#1101)
1 parent fde1c2a commit cedef50

File tree

11 files changed

+23
-22
lines changed

11 files changed

+23
-22
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
</p>
2020
</h2>
2121

22-
> [!WARNING]
23-
> Franklin is depending on Julia internals concerning the world age. These internals changed in Julia 1.12, such that Franklin.jl currently only works up to version Julia 1.11.
24-
2522
Franklin is a simple **static site generator** (SSG) oriented towards technical blogging (code, maths, ...), flexibility and extensibility.
2623
The base syntax is plain markdown with a few extensions such as the ability to define and use LaTeX-like commands in or outside of maths environments and the possibility to evaluate code blocks on the fly.
2724

src/Franklin.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const FD_ENV = LittleDict(
9393

9494
utils_name() = "Utils_$(FD_ENV[:UTILS_COUNTER]::Int)"
9595
utils_symb() = Symbol(utils_name())
96-
utils_module() = getproperty(Main, utils_symb())
96+
utils_module() = @invokelatest getproperty(Main, utils_symb())
9797
utils_hash() = nothing
9898

9999
# HACK avoid stackoverflow for pagevar cycle (see juliacomputing issue #891)

src/converter/html/blocks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function process_html_for(hs::AS, qblocks::Vector{AbstractBlock},
179179
"Please make sure it's defined."))
180180
end
181181
if iname UTILS_NAMES # can only happen if Utils is defined.
182-
iter = getfield(utils_module(), Symbol(iname))
182+
iter = @invokelatest getglobal(utils_module(), Symbol(iname))
183183
else
184184
iter = locvar(iname)
185185
end

src/converter/html/functions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ function convert_html_fblock(β::HFun)::String
88
fun = Symbol("hfun_" * lowercase.fname))
99
ex = isempty.params) ? :($fun()) : :($fun($β.params))
1010
# see if a hfun was defined in utils
11-
if isdefined(Main, utils_symb()) && isdefined(utils_module(), fun)
11+
if @invokelatest(isdefined(Main, utils_symb())) && @invokelatest(isdefined(utils_module(), fun))
1212
# skip eval if the page is delayed
1313
isdelayed() && return ""
1414
res = Core.eval(utils_module(), ex)
1515
return string(res)
1616
end
1717
# see if a hfun was defined internally
18-
isdefined(Franklin, fun) && return eval(ex)
18+
@invokelatest(isdefined(Franklin, fun)) && return eval(ex)
1919
# if zero parameters, see if can fill (case: {{vname}})
2020
if isempty.params) &&
2121
(!isnothing(locvar.fname)) || β.fname in UTILS_NAMES)
@@ -53,7 +53,7 @@ function hfun_fill(params::Vector{String})::String
5353
vname = params[1]
5454
if length(params) == 1
5555
if vname in UTILS_NAMES
56-
repl = string(getfield(utils_module(), Symbol(vname)))
56+
repl = string(@invokelatest(getglobal(utils_module(), Symbol(vname))))
5757
else
5858
tmp_repl = locvar(vname)
5959
if isnothing(tmp_repl)

src/converter/latex/latex.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function resolve_lxobj(lxo::LxObj, lxdefs::Vector{LxDef};
3434
# it will be `nothing` in math mode or when defined in utils
3535
if isnothing(lxd)
3636
# check if it's defined in Utils and act accordingly
37-
if isdefined(Main, utils_symb()) && isdefined(utils_module(), fun)
37+
if @invokelatest(isdefined(Main, utils_symb())) && @invokelatest(isdefined(utils_module(), fun))
3838
raw = Core.eval(utils_module(), :($fun($lxo, $lxdefs)))
3939
return reprocess(raw, lxdefs)
4040
else
@@ -49,7 +49,7 @@ function resolve_lxobj(lxo::LxObj, lxdefs::Vector{LxDef};
4949
# the output of lx_label is direct HTML.
5050
if (!env && isempty(lxd)) || (env && isempty(lxd.first) && isempty(lxd.second))
5151
name = getname(lxo)
52-
isdefined(Franklin, fun) && return eval(:($fun($lxo, $lxdefs)))
52+
@invokelatest(isdefined(Franklin, fun)) && return eval(:($fun($lxo, $lxdefs)))
5353
return ""
5454
end
5555

src/converter/markdown/mddefs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function process_mddefs(blocks::Vector{OCBlock}, isconfig::Bool,
3333
filter!(v -> v isa Symbol, vnames)
3434
for vname in vnames
3535
key = String(vname)
36-
value = getproperty(mdl, vname)
36+
value = @invokelatest getglobal(mdl, vname)
3737
set_var!(curdict, key, value; isglobal=isconfig)
3838
end
3939
end

src/eval/codeblock.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ function resolve_code_block(
128128
modname = modulename(locvar(:fd_rpath)::String)
129129
# >> check if relevant module exists, otherwise create one
130130
mod = ismodule(modname) ?
131-
getfield(Main, Symbol(modname)) :
131+
@invokelatest(getglobal(Main, Symbol(modname))) :
132132
newmodule(modname)
133-
133+
134134
# >> retrieve the code paths
135135
cp = form_codepaths(rpath)
136136
# >> write the code to file
@@ -172,7 +172,7 @@ function resolve_code_block(
172172
chunk_ast = nothing
173173
end
174174
end
175-
175+
176176
# NOTE: shell, pkg, and help mode are currently fairly rudimentary
177177
# and should be considered experimental
178178

@@ -239,7 +239,7 @@ function resolve_code_block(
239239
if any((repl, shell, help, pkg))
240240
s = repl ? :repl : shell ? :shell : help ? :help : :pkg
241241
return html_repl_code(repl_code_chunks, s)
242-
242+
243243
elseif shortcut || locvar(:showall)::Bool
244244
return html_code(code, lang) *
245245
reprocess("\\show{$rpath}", [GLOBAL_LXDEFS["\\show"]])

src/eval/module.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Checks whether a name is a defined module.
1717
"""
1818
function ismodule(name::String)::Bool
1919
s = Symbol(name)
20-
isdefined(Main, s) || return false
21-
typeof(getfield(Main, s)) === Module
20+
@invokelatest(isdefined(Main, s)) || return false
21+
typeof(@invokelatest(getglobal(Main, s))) === Module
2222
end
2323

2424
"""

src/manager/file_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function process_utils()::Nothing
8181
Base.include(utils_module(), utils)
8282

8383
# keep track of utils names
84-
ns = String.(names(utils_module(), all=true))
84+
ns = String.(@invokelatest(names(utils_module(), all=true)))
8585
filter!(n -> n[1] != '#' && n ("eval", "include", "Utils"), ns)
8686
empty!(UTILS_NAMES)
8787
append!(UTILS_NAMES, ns)

src/parser/latex/blocks.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ function get_lxdef_ref(lxname::SubString, lxdefs::Vector{LxDef},
162162
# 3. throw an error
163163
if isempty(ks)
164164
# check if defined in utils
165-
if isdefined(Main, utils_symb())
165+
if @invokelatest isdefined(Main, utils_symb())
166166
# env def 'env_***'
167-
flag = isenv && isdefined(utils_module(), Symbol("env_$(lxname)"))
167+
flag = isenv && @invokelatest isdefined(utils_module(), Symbol("env_$(lxname)"))
168168
# com def 'lx_***'
169-
flag |= isdefined(utils_module(), Symbol("lx_$(lxname[2:end])"))
169+
flag |= @invokelatest isdefined(utils_module(), Symbol("lx_$(lxname[2:end])"))
170170
flag && return (Ref(nothing), true)
171171
end
172172
# if we're here, and in math mode, let the math engine deal with it

0 commit comments

Comments
 (0)