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
17 changes: 14 additions & 3 deletions src/command/render/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ async function resolveFilterExtension(
typeof (filter) === "string" &&
!existsSync(filter)
) {
let extensions = await options.services.extension?.find(
const extensions = await options.services.extension?.find(
filter,
options.source,
"filters",
Expand All @@ -783,16 +783,27 @@ async function resolveFilterExtension(
) || [];

// Filter this list of extensions
extensions = filterExtensions(extensions || [], filter, "filter");
const filteredExtensions = filterExtensions(
extensions || [],
filter,
"filter",
);
// Return any contributed plugins
if (extensions.length > 0) {
if (filteredExtensions.length > 0) {
// This matches an extension, use the contributed filters
const filters = extensions[0].contributes.filters;
if (filters) {
return filters;
} else {
return filter;
}
} else if (extensions.length > 0) {
// There was a matching extension with this name, but
// it was filtered out, just hide the filter altogether
return [];
} else {
// There were no extensions matching this name, just allow it
// through
return filter;
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/extension/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ export const kAuthor = "author";
export const kVersion = "version";
export const kQuartoRequired = "quarto-required";
export const kRevealJSPlugins = "revealjs-plugins";

// Special case for our lightbox extension, which we've built in
// manually (to better control filter placement)
export const kBuiltInExtNames = ["lightbox"];
12 changes: 7 additions & 5 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { quartoConfig } from "../core/quarto.ts";

import {
kAuthor,
kBuiltInExtNames,
kBuiltInExtOrg,
kCommon,
kExtensionDir,
Expand Down Expand Up @@ -187,7 +188,7 @@ function filterExtensionAndWarn(
warnToRemoveExtensions(filterOutExtensions);
// filter out the extensions that have become built in
return extensions.filter((ext) => {
return filterOutExtensions.map((ext) => ext.id.name).includes(
return !filterOutExtensions.map((ext) => ext.id.name).includes(
ext.id.name,
);
});
Expand Down Expand Up @@ -239,13 +240,14 @@ export function filterExtensions(
// referenced in the yaml so we don't break code in the wild)
const oldBuiltInExt = extensions?.filter((ext) => {
return (ext.id.organization === kQuartoExtOrganization &&
kQuartoExtBuiltIn.includes(ext.id.name));
(kQuartoExtBuiltIn.includes(ext.id.name) ||
kBuiltInExtNames.includes(ext.id.name)));
});
if (oldBuiltInExt.length > 0) {
filterExtensionAndWarn(extensions, oldBuiltInExt);
return filterExtensionAndWarn(extensions, oldBuiltInExt);
} else {
return extensions;
}

return extensions;
} else {
return extensions;
}
Expand Down
3 changes: 2 additions & 1 deletion src/resources/filters/ast/runemulation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ function run_as_extended_ast(specTable)
innerV._filter_name = string.format("%s-%s", v.name, j)
table.insert(finalResult, {
filter = innerV,
name = innerV._filter_name
name = innerV._filter_name,
flags = v.flags
})
end
else
Expand Down
12 changes: 9 additions & 3 deletions src/resources/filters/crossref/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ function titleString(type, default)
return pandoc.utils.stringify(title(type, default))
end

function titlePrefix(type, default, order)
function titlePrefix(type, default, order, with_delimiter)
if with_delimiter == nil then
with_delimiter = true
end

local prefix = title(type, default)
table.insert(prefix, nbspString())
tappend(prefix, numberOption(type, order))
tappend(prefix, titleDelim())
table.insert(prefix, pandoc.Space())
if with_delimiter then
tappend(prefix, titleDelim())
table.insert(prefix, pandoc.Space())
end
return prefix
end

Expand Down
4 changes: 2 additions & 2 deletions src/resources/filters/crossref/tables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ function isTableDiv(el)
end


function float_title_prefix(float)
function float_title_prefix(float, withDelimiter)
local category = crossref.categories.by_name[float.type]
if category == nil then
fail("unknown float type '" .. float.type .. "'")
return
end

return titlePrefix(category.ref_type, category.name, float.order)
return titlePrefix(category.ref_type, category.name, float.order, withDelimiter)
end

function tableTitlePrefix(order)
Expand Down
46 changes: 46 additions & 0 deletions src/resources/filters/customnodes/floatreftarget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,52 @@ function decorate_caption_with_crossref(float)
return float
end

function full_caption_prefix(float, subfloat)
if not param("enable-crossref", true) then
-- don't decorate captions with crossrefs information if crossrefs are disabled
return {}
end

float = ensure_custom(float)
-- nil should never happen here, but the Lua analyzer doesn't know it
if float == nil then
-- luacov: disable
internal_error()
-- luacov: enable
end

if subfloat ~= nil then
subfloat = ensure_custom(subfloat)
-- nil should never happen here, but the Lua analyzer doesn't know it
if subfloat == nil then
-- luacov: disable
internal_error()
-- luacov: enable
end
end

local float_title = {}
if not is_unlabeled_float(float) then
float_title = float_title_prefix(float, false)
end

local subfloat_title = pandoc.Inlines({})
if subfloat ~= nil then
if subfloat.order == nil then
warn("Subfloat without crossref information")
else
prependSubrefNumber(subfloat_title, subfloat.order)
end
end
if #subfloat_title > 0 then
tappend(float_title,{nbspString()})
end
tappend(float_title, subfloat_title)
tappend(float_title, titleDelim())
tappend(float_title, {pandoc.Space()})
return pandoc.Inlines(float_title)
end

-- capture relevant figure attributes then strip them
local function get_figure_attributes(el)
local align = figAlignAttribute(el)
Expand Down
Loading