Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(classes,packages): Add variant styling support on block quotes #118

Merged
merged 1 commit into from
Jan 15, 2025
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
3 changes: 2 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ files["lua-libraries"] = {
}
max_line_length = false
ignore = {
"581" -- operator order warning doesn't account for custom table metamethods
"581", -- operator order warning doesn't account for custom table metamethods
"212/self", -- unused argument self: counterproductive warning in methods
}
-- vim: ft=lua
6 changes: 5 additions & 1 deletion classes/resilient/base.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--
-- Base resilient class
-- 2023, Didier Willis
-- 2023, 2025 Didier Willis
-- License: MIT
--
require("silex")
Expand Down Expand Up @@ -45,6 +45,10 @@ function class:resolveStyle (name, discardable)
return self.styles:resolveStyle(name, discardable)
end

function class:hasStyle (name)
return self.styles:hasStyle(name)
end

-- For overriding in subclass
function class.registerStyles (_) end

Expand Down
8 changes: 5 additions & 3 deletions classes/resilient/book.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--
-- A new advanced book class for SILE
-- 2021-2023, Didier Willis
-- 2021-2025, Didier Willis
-- License: MIT
--
local base = require("classes.resilient.base")
Expand Down Expand Up @@ -665,8 +665,10 @@ function class:registerCommands ()
end)
end, "Typeset its contents in a right and left indented block (variant).")

self:registerCommand("blockquote", function (_, content)
SILE.call("style:apply:paragraph", { name = "blockquote" }, content)
self:registerCommand("blockquote", function (options, content)
local variant = options.variant and "blockquote-" .. options.variant or nil
local style = variant and self.styles:hasStyle(variant) and variant or "blockquote"
SILE.call("style:apply:paragraph", { name = style }, content)
end, "Typeset its contents in a styled blockquote.")

-- Captioned elements
Expand Down
11 changes: 5 additions & 6 deletions examples/manual-classes/classes.sil
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,12 @@ commands are available, as well as \autodoc:command{\header:rule}.
\section{Block-indented quotes}

The class provides the \autodoc:environment{blockquote} environment to typeset simple block-indented
paragraphs of the kind shown in the \autodoc:package{resilient.styles} package documentation. It is sort
of an extra, but it was so often needed by this author that he decided to include it in
standard.
paragraphs.
Indented quotes can be nested.

The environment relies on the same-named style for its styling and on the
\autodoc:setting{book.blockquote.margin} setting for its indentation (defaults to 2em). Indented
quotes can be nested.
The environment relies on the same-named style for its styling and on the \autodoc:setting{book.blockquote.margin} setting for its indentation (defaults to 2em).

The environment also accepts a \autodoc:parameter{variant} option, to switch to an alternate style, assumed to be named \code{blockquote-⟨\em{variant}⟩}.

\section{Other features}

Expand Down
8 changes: 5 additions & 3 deletions packages/resilient/defn/init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--
-- Definition environment for SILE
-- Very minimal implementation for Djot/Markdown needs, with styling support.
-- 2023, Didier Willis
-- 2023, 2025 Didier Willis
-- License: MIT
--
local ast = require("silex.ast")
Expand Down Expand Up @@ -50,14 +50,16 @@ function package:registerCommands ()

self:registerCommand("defn:internal:term", function (options, content)
local variant = options.variant or SILE.settings:get("defn.variant")
local style = variant and "defn-term-" .. variant or "defn-term"
local varstyle = variant and "defn-term-" .. variant
local style = varstyle and self.styles:hasStyle(varstyle) and varstyle or "defn-term"

SILE.call("style:apply:paragraph", { name = style }, content)
end, "Definition term (internal)")

self:registerCommand("defn:internal:desc", function (options, content)
local variant = options.variant or SILE.settings:get("defn.variant")
local style = variant and "defn-desc-" .. variant or "defn-desc"
local varstyle = variant and "defn-desc-" .. variant
local style = varstyle and self.styles:hasStyle(varstyle) and varstyle or "defn-desc"

SILE.settings:temporarily(function ()
local indent = SILE.settings:get("defn.indent"):absolute()
Expand Down
7 changes: 6 additions & 1 deletion packages/resilient/styles/init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--
-- A style package for SILE
-- License: MIT
-- 2021-2024, Didier Willis
-- 2021-2025, Didier Willis
--
local base = require("packages.base")

Expand Down Expand Up @@ -229,6 +229,11 @@ function package:resolveStyle (name, discardable)
return pl.tablex.deepcopy(stylespec.style)
end

function package:hasStyle (name)
local stylespec = SILE.scratch.styles.specs[name]
return stylespec and true or false
end

function package:resolveParagraphStyle (name, discardable)
local styledef = self:resolveStyle(name, discardable)
-- Apply defaults
Expand Down