Skip to content

Commit

Permalink
feat(classes,packages): Add variant styling support on block quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Jan 11, 2025
1 parent a5be6c0 commit 282860e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
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, discardable)
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

0 comments on commit 282860e

Please sign in to comment.