Skip to content

Commit

Permalink
lua - more local variable cleanup from non-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cscheid committed May 16, 2024
1 parent 95d87f7 commit 876097c
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 220 deletions.
29 changes: 12 additions & 17 deletions src/resources/filters/customnodes/callout.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
-- callout.lua
-- Copyright (C) 2021-2022 Posit Software, PBC

local constants = require("modules/constants")
local class_predicates = require("modules/classpredicates")

local function _main()
local callouts = require("modules/callouts")

function _callout_main()
local calloutidx = 1

local function calloutType(div)
for _, class in ipairs(div.attr.classes) do
if class_predicates.isCallout(class) then
if _quarto.modules.classpredicates.isCallout(class) then
local type = class:match("^callout%-(.*)")
if type == nil then
type = "none"
Expand Down Expand Up @@ -40,7 +35,7 @@ local function _main()

-- an HTML callout div
local function calloutDiv(node)
node = callouts.decorate_callout_title_with_crossref(node)
node = _quarto.modules.callouts.decorate_callout_title_with_crossref(node)

-- the first heading is the title
local div = pandoc.Div({})
Expand All @@ -66,8 +61,8 @@ local function _main()
end
})

if calloutAppearance == constants.kCalloutAppearanceDefault and pandoc.utils.stringify(title) == "" and not found then
title = quarto.utils.as_inlines(pandoc.Plain(callouts.displayName(node.type)))
if calloutAppearance == _quarto.modules.constants.kCalloutAppearanceDefault and pandoc.utils.stringify(title) == "" and not found then
title = quarto.utils.as_inlines(pandoc.Plain(_quarto.modules.callouts.displayName(node.type)))
end

-- Make an outer card div and transfer classes and id
Expand Down Expand Up @@ -98,7 +93,7 @@ local function _main()
local noicon = ""

-- Check to see whether this is a recognized type
if icon == false or not callouts.isBuiltInType(callout_type) or type == nil then
if icon == false or not _quarto.modules.callouts.isBuiltInType(callout_type) or type == nil then
noicon = " no-icon"
calloutDiv.attr.classes:insert("no-icon")
end
Expand Down Expand Up @@ -272,7 +267,7 @@ local function _main()
_quarto.ast.add_renderer("Callout", function(_)
return true
end, function(node)
node = callouts.decorate_callout_title_with_crossref(node)
node = _quarto.modules.callouts.decorate_callout_title_with_crossref(node)
local contents = resolveCalloutContents(node, true)
local callout = pandoc.BlockQuote(contents)
local result = pandoc.Div(callout, pandoc.Attr(node.attr.identifier or ""))
Expand All @@ -291,8 +286,8 @@ local function _main()
local calloutAppearance = node.appearance
local hasIcon = node.icon

if calloutAppearance == constants.kCalloutAppearanceDefault and pandoc.utils.stringify(title) == "" then
title = callouts.displayName(type)
if calloutAppearance == _quarto.constants.kCalloutAppearanceDefault and pandoc.utils.stringify(title) == "" then
title = _quarto.modules.callouts.displayName(type)
end

-- the body of the callout
Expand Down Expand Up @@ -378,7 +373,7 @@ local function _main()
end, function(callout)
ensure_typst_font_awesome()

local attrs = callouts.callout_attrs[callout.type]
local attrs = _quarto.modules.callouts.callout_attrs[callout.type]
local background_color, icon_color, icon
if attrs == nil then
background_color = "white"
Expand All @@ -392,7 +387,7 @@ local function _main()

local title = callout.title
if title == nil then
title = pandoc.Plain(callouts.displayName(callout.type))
title = pandoc.Plain(_quarto.modules.callouts.displayName(callout.type))
end

local typst_callout = _quarto.format.typst.function_call("callout", {
Expand Down Expand Up @@ -425,7 +420,7 @@ local function _main()
return calloutDocx(callout)
end)
end
_main()
_callout_main()

function docx_callout_and_table_fixup()
if not _quarto.format.isDocxOutput() then
Expand Down
2 changes: 2 additions & 0 deletions src/resources/filters/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ end

import("./mainstateinit.lua")

import("./modules/import_all.lua")

import("./ast/scopedwalk.lua")
import("./ast/customnodes.lua")
import("./ast/emulatedfilter.lua")
Expand Down
22 changes: 22 additions & 0 deletions src/resources/filters/modules/import_all.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- import_all.lua
-- imports all modules into _quarto.modules

_quarto.modules = {
astshortcode = require("modules/astshortcode"),
authors = require("modules/authors"),
callouts = require("modules/callouts"),
classpredicates = require("modules/classpredicates"),
constants = require("modules/constants"),
dashboard = require("modules/dashboard"),
filenames = require("modules/filenames"),
filters = require("modules/filters"),
license = require("modules/license"),
lightbox = require("modules/lightbox"),
mediabag = require("modules/mediabag"),
openxml = require("modules/openxml"),
patterns = require("modules/patterns"),
scope = require("modules/scope"),
string = require("modules/string"),
tablecolwidths = require("modules/tablecolwidths"),
typst = require("modules/typst")
}
Loading

0 comments on commit 876097c

Please sign in to comment.