Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/resources/filters/common/citations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
-- restructured into the standard has
-- format

local constants = require("modules/constants")

local function processTypedId(el)
if pandoc.utils.type(el) == "Inlines" then
return { value = el }
Expand Down Expand Up @@ -36,23 +34,23 @@ end

function processCitationMeta(meta)
if meta then
local citationMeta = meta[constants.kCitation]
local citationMeta = meta[_quarto.modules.constants.kCitation]
if citationMeta and type(citationMeta) == "object" then
local containerIds = citationMeta[constants.kContainerId]
local containerIds = citationMeta[_quarto.modules.constants.kContainerId]
if containerIds ~= nil then
meta[constants.kCitation][constants.kContainerId] = normalizeTypedId(containerIds)
meta[_quarto.modules.constants.kCitation][_quarto.modules.constants.kContainerId] = normalizeTypedId(containerIds)
end

local articleIds = citationMeta[constants.kArticleId]
local articleIds = citationMeta[_quarto.modules.constants.kArticleId]
if articleIds ~= nil then
meta[constants.kCitation][constants.kArticleId] = normalizeTypedId(articleIds)
meta[_quarto.modules.constants.kCitation][_quarto.modules.constants.kArticleId] = normalizeTypedId(articleIds)
end

if citationMeta[constants.kPage] and citationMeta[constants.kPageFirst] == nil and citationMeta[constants.kPageLast] == nil then
local pagerange = split(pandoc.utils.stringify(citationMeta[constants.kPage]), '-')
meta[constants.kCitation][constants.kPageFirst] = pandoc.Inlines(pagerange[1])
if citationMeta[_quarto.modules.constants.kPage] and citationMeta[_quarto.modules.constants.kPageFirst] == nil and citationMeta[_quarto.modules.constants.kPageLast] == nil then
local pagerange = split(pandoc.utils.stringify(citationMeta[_quarto.modules.constants.kPage]), '-')
meta[_quarto.modules.constants.kCitation][_quarto.modules.constants.kPageFirst] = pandoc.Inlines(pagerange[1])
if pagerange[2] then
meta[constants.kCitation][constants.kPageLast] = pandoc.Inlines(pagerange[2])
meta[_quarto.modules.constants.kCitation][_quarto.modules.constants.kPageLast] = pandoc.Inlines(pagerange[2])
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions src/resources/filters/common/tables.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-- tables.lua
-- Copyright (C) 2021-2022 Posit Software, PBC

local patterns = require("modules/patterns")

function anonymousTblId()
return "tbl-anonymous-" .. tostring(math.random(10000000))
end
Expand Down Expand Up @@ -106,23 +104,23 @@ end

function hasGtHtmlTable(raw)
if _quarto.format.isRawHtml(raw) and _quarto.format.isHtmlOutput() then
return raw.text:match(patterns.html_gt_table)
return raw.text:match(_quarto.modules.patterns.html_gt_table)
else
return false
end
end

function hasPagedHtmlTable(raw)
if _quarto.format.isRawHtml(raw) and _quarto.format.isHtmlOutput() then
return raw.text:match(patterns.html_paged_table)
return raw.text:match(_quarto.modules.patterns.html_paged_table)
else
return false
end
end

function hasRawHtmlTable(raw)
if _quarto.format.isRawHtml(raw) and _quarto.format.isHtmlOutput() then
return raw.text:match(patterns.html_table)
return raw.text:match(_quarto.modules.patterns.html_table)
else
return false
end
Expand Down
6 changes: 2 additions & 4 deletions src/resources/filters/crossref/tables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
-- wrapped in a div so they can carry parent information and so that
-- we can create a hyperef target for latex)

local patterns = require("modules/patterns")

function preprocessRawTableBlock(rawEl, parentId)

local function divWrap(el, label, caption)
Expand All @@ -21,7 +19,7 @@ function preprocessRawTableBlock(rawEl, parentId)
end

if _quarto.format.isRawHtml(rawEl) and _quarto.format.isHtmlOutput() then
local captionPattern = patterns.html_table_caption
local captionPattern = _quarto.modules.patterns.html_table_caption
local _, caption, _ = string.match(rawEl.text, captionPattern)
if caption then
-- extract id if there is one
Expand Down Expand Up @@ -165,7 +163,7 @@ function processRawTable(divEl)
local label = divEl.attr.identifier
-- html table
if _quarto.format.isRawHtml(rawEl) then
local captionPattern = patterns.html_table_caption
local captionPattern = _quarto.modules.patterns.html_table_caption
local _, caption, _ = string.match(rawEl.text, captionPattern)
if caption then

Expand Down
46 changes: 22 additions & 24 deletions src/resources/filters/customnodes/content-hidden.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
-- Copyright (C) 2022 Posit Software, PBC


local constants = require("modules/constants")

local kConditions = pandoc.List({
constants.kWhenMeta, constants.kUnlessMeta,
constants.kWhenFormat, constants.kUnlessFormat,
constants.kWhenProfile, constants.kUnlessProfile
_quarto.modules.constants.kWhenMeta, _quarto.modules.constants.kUnlessMeta,
_quarto.modules.constants.kWhenFormat, _quarto.modules.constants.kUnlessFormat,
_quarto.modules.constants.kWhenProfile, _quarto.modules.constants.kUnlessProfile
})

function is_visible(node)
local profiles = pandoc.List(param("quarto_profile", {}))
local match = propertiesMatch(node.condition, profiles)
if node.behavior == constants.kContentVisible then
if node.behavior == _quarto.modules.constants.kContentVisible then
return match
elseif node.behavior == constants.kContentHidden then
elseif node.behavior == _quarto.modules.constants.kContentHidden then
return not match
else
-- luacov: disable
Expand All @@ -26,14 +24,14 @@ function is_visible(node)
end

_quarto.ast.add_handler({
class_name = { constants.kContentVisible, constants.kContentHidden },
class_name = { _quarto.modules.constants.kContentVisible, _quarto.modules.constants.kContentHidden },

ast_name = "ConditionalBlock",

kind = "Block",

parse = function(div)
local behavior = div.classes:find(constants.kContentVisible) or div.classes:find(constants.kContentHidden)
local behavior = div.classes:find(_quarto.modules.constants.kContentVisible) or div.classes:find(_quarto.modules.constants.kContentHidden)
local condition = pandoc.List({})
local remaining_attributes = pandoc.List({})
for i, v in ipairs(div.attributes) do
Expand All @@ -44,7 +42,7 @@ _quarto.ast.add_handler({
end
end
div.attributes = remaining_attributes
div.classes = div.classes:filter(function(k) return k ~= constants.kContentVisible and k ~= constants.kContentHidden end)
div.classes = div.classes:filter(function(k) return k ~= _quarto.modules.constants.kContentVisible and k ~= _quarto.modules.constants.kContentHidden end)

return quarto.ConditionalBlock({
node = div,
Expand Down Expand Up @@ -144,10 +142,10 @@ end
function handleHiddenVisible(profiles)
return function(el)
local visible
if el.attr.classes:find(constants.kContentVisible) then
if el.attr.classes:find(_quarto.modules.constants.kContentVisible) then
visible = propertiesMatch(el.attributes, profiles)
clearHiddenVisibleAttributes(el)
elseif el.attr.classes:find(constants.kContentHidden) then
elseif el.attr.classes:find(_quarto.modules.constants.kContentHidden) then
visible = not propertiesMatch(el.attributes, profiles)
clearHiddenVisibleAttributes(el)
else
Expand Down Expand Up @@ -191,12 +189,12 @@ function propertiesMatch(properties, profiles)
end
end
local tests = {
{ constants.kWhenMeta, check_meta, false },
{ constants.kUnlessMeta, check_meta, true },
{ constants.kWhenFormat, quarto.format.is_format, false },
{ constants.kUnlessFormat, quarto.format.is_format, true },
{ constants.kWhenProfile, check_profile, false },
{ constants.kUnlessProfile, check_profile, true }
{ _quarto.modules.constants.kWhenMeta, check_meta, false },
{ _quarto.modules.constants.kUnlessMeta, check_meta, true },
{ _quarto.modules.constants.kWhenFormat, quarto.format.is_format, false },
{ _quarto.modules.constants.kUnlessFormat, quarto.format.is_format, true },
{ _quarto.modules.constants.kWhenProfile, check_profile, false },
{ _quarto.modules.constants.kUnlessProfile, check_profile, true }
}
local match = true
for _, test in ipairs(tests) do
Expand All @@ -211,10 +209,10 @@ function propertiesMatch(properties, profiles)
end

function clearHiddenVisibleAttributes(el)
el.attributes[constants.kUnlessFormat] = nil
el.attributes[constants.kWhenFormat] = nil
el.attributes[constants.kUnlessProfile] = nil
el.attributes[constants.kWhenProfile] = nil
el.attr.classes = removeClass(el.attr.classes, constants.kContentVisible)
el.attr.classes = removeClass(el.attr.classes, constants.kContentHidden)
el.attributes[_quarto.modules.constants.kUnlessFormat] = nil
el.attributes[_quarto.modules.constants.kWhenFormat] = nil
el.attributes[_quarto.modules.constants.kUnlessProfile] = nil
el.attributes[_quarto.modules.constants.kWhenProfile] = nil
el.attr.classes = removeClass(el.attr.classes, _quarto.modules.constants.kContentVisible)
el.attr.classes = removeClass(el.attr.classes, _quarto.modules.constants.kContentHidden)
end
3 changes: 1 addition & 2 deletions src/resources/filters/customnodes/floatreftarget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
-- Copyright (C) 2023 Posit Software, PBC

local drop_class = require("modules/filters").drop_class
local patterns = require("modules/patterns")

-- Track whether we've injected the Typst show rule for listing alignment
local injected_listing_align_rule = false
Expand Down Expand Up @@ -565,7 +564,7 @@ end, function(float)
-- and recreating it below.
-- See #7937
if _quarto.format.isRawLatex(float.content) then
local _b, _e, _beginenv, inner_content, _endenv = float.content.text:find(patterns.latex_table_star)
local _b, _e, _beginenv, inner_content, _endenv = float.content.text:find(_quarto.modules.patterns.latex_table_star)
if _b ~= nil then
figEnv = "table*"
float.content.text = inner_content
Expand Down
10 changes: 4 additions & 6 deletions src/resources/filters/layout/figures.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
-- figures.lua
-- Copyright (C) 2020-2022 Posit Software, PBC

local constants = require("modules/constants")

function preventExtendedFigure(el)
el.attr.attributes[constants.kFigExtended] = "false"
el.attr.attributes[_quarto.modules.constants.kFigExtended] = "false"
end

function forceExtendedFigure(el)
el.attr.attributes[constants.kFigExtended] = "true"
el.attr.attributes[_quarto.modules.constants.kFigExtended] = "true"
end

function shouldHandleExtended(el)
return el.attr.attributes[constants.kFigExtended] ~= "false"
return el.attr.attributes[_quarto.modules.constants.kFigExtended] ~= "false"
end

-- By default, images without captions should be
Expand All @@ -38,7 +36,7 @@ function shouldHandleExtendedImage(el)
end

-- handle extended if it was explicitly enabled
if el.attr.attributes[constants.kFigExtended] == "true" then
if el.attr.attributes[_quarto.modules.constants.kFigExtended] == "true" then
return true
end

Expand Down
5 changes: 1 addition & 4 deletions src/resources/filters/layout/lightbox.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
-- lightbox.lua
-- Copyright (C) 2020-2022 Posit Software, PBC

local lightbox_module = require("modules/lightbox")


-- attributes to forward from the image to the newly created link
local kDescription = "description"
local kForwardedAttr = {
Expand Down Expand Up @@ -178,7 +175,7 @@ function lightbox()

Meta = function(meta)
-- Set auto lightbox mode, if need be
auto = lightbox_module.automatic(meta) == true
auto = _quarto.modules.lightbox.automatic(meta) == true
imgCount = 0
end,
-- Find images that are already within links
Expand Down
13 changes: 6 additions & 7 deletions src/resources/filters/layout/manuscript.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-- manuscript.lua
-- Copyright (C) 2021-2022 Posit Software, PBC

local constants = require("modules/constants")
local kUnrollMarkdownCells = "unroll-markdown-cells"

function manuscriptUnroll()
Expand All @@ -28,10 +27,10 @@ function manuscript()
if _quarto.format.isWordProcessorOutput() or _quarto.format.isLatexOutput() then

local language = param("language", nil);
local notebookPrefix = language[constants.kLangSourcePrefix]
local notebookPrefix = language[_quarto.modules.constants.kLangSourcePrefix]

local manuscriptBaseUrl = param(constants.kManuscriptUrl)
local notebookLinks = param(constants.kNotebookLinks)
local manuscriptBaseUrl = param(_quarto.modules.constants.kManuscriptUrl)
local notebookLinks = param(_quarto.modules.constants.kNotebookLinks)

return {
traverse = 'topdown',
Expand All @@ -51,8 +50,8 @@ function manuscript()
end

-- Read notebook parameters from the cell, if present
local nbAbsPath = divEl.attributes[constants.kNotebook]
local nbTitle = divEl.attributes[constants.kNotebookTitle]
local nbAbsPath = divEl.attributes[_quarto.modules.constants.kNotebook]
local nbTitle = divEl.attributes[_quarto.modules.constants.kNotebookTitle]

-- If this is a notebook embed cell, 'lift' the contents of any child divs
-- up (unroll their contents), this will help us avoid
Expand Down Expand Up @@ -115,7 +114,7 @@ function manuscript()
end

-- The Id
local cellId = divEl.attributes[constants.kNotebookCellId];
local cellId = divEl.attributes[_quarto.modules.constants.kNotebookCellId];
if cellId ~= nil then
cellId = '#' .. cellId
else
Expand Down
4 changes: 1 addition & 3 deletions src/resources/filters/layout/pandoc3_figure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
-- never cross-referenceable but they need to be rendered as
-- if they were.

local scope_utils = require("modules/scope")

function render_pandoc3_figure()
local function html_handle_linked_image(figure)
local div = pandoc.Div({})
Expand Down Expand Up @@ -151,7 +149,7 @@ function render_pandoc3_figure()
image.attributes['quarto-caption-env'] = 'subcaption'
end
image.classes:extend(figure.classes)
if scope_utils.lookup_class(scope, "column-margin") then
if _quarto.modules.scope.lookup_class(scope, "column-margin") then
image.classes:insert("column-margin")
end
return latexImageFigure(image)
Expand Down
16 changes: 6 additions & 10 deletions src/resources/filters/normalize/flags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
-- so that we can skip as many filters as possible
-- when we don't need them

local patterns = require("modules/patterns")
local constants = require("modules/constants")
local lightbox_module = require("modules/lightbox")

flags = {}

function compute_flags()
local table_pattern = patterns.html_table
local table_tag_pattern = patterns.html_table_tag_name
local gt_table_pattern = patterns.html_gt_table
local table_pattern = _quarto.modules.patterns.html_table
local table_tag_pattern = _quarto.modules.patterns.html_table_tag_name
local gt_table_pattern = _quarto.modules.patterns.html_gt_table
local function find_shortcode_in_attributes(el)
for k, v in pairs(el.attributes) do
if type(v) == "string" and v:find("%{%{%<") then
Expand Down Expand Up @@ -79,7 +75,7 @@ function compute_flags()
flags.has_theorem_refs = true
end

local has_lightbox = lightbox_module.el_has_lightbox(node)
local has_lightbox = _quarto.modules.lightbox.el_has_lightbox(node)
if has_lightbox then
flags.has_lightbox = true
end
Expand Down Expand Up @@ -161,7 +157,7 @@ function compute_flags()
flags.has_shortcodes = true
end

local has_lightbox = lightbox_module.el_has_lightbox(node)
local has_lightbox = _quarto.modules.lightbox.el_has_lightbox(node)
if has_lightbox then
flags.has_lightbox = true
end
Expand Down Expand Up @@ -193,7 +189,7 @@ function compute_flags()
end,
}, {
Meta = function(el)
local lightbox_auto = lightbox_module.automatic(el)
local lightbox_auto = _quarto.modules.lightbox.automatic(el)
if lightbox_auto then
flags.has_lightbox = true
elseif lightbox_auto == false then
Expand Down
2 changes: 1 addition & 1 deletion src/resources/filters/quarto-init/includes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function read_includes(meta)
ensureIncludes(meta, constants.kHeaderIncludes)
ensureIncludes(meta, constants.kIncludeBefore)
ensureIncludes(meta, constants.kIncludeAfter)

-- read file includes
readIncludeFiles(meta, constants.kIncludeInHeader, constants.kHeaderIncludes)
readIncludeFiles(meta, constants.kIncludeBeforeBody, constants.kIncludeBefore)
Expand Down
Loading
Loading