Skip to content

Commit

Permalink
feat: support a default URL-styling with SILE 0.13.4 urlstyle
Browse files Browse the repository at this point in the history
Override the new urlstyle hook from SILE 0.13.4 in resilient.book,
so it can rely on a dedicated style.
  • Loading branch information
Omikhleia authored and Didier Willis committed Apr 16, 2023
1 parent c168d68 commit 56dea5e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 24 deletions.
40 changes: 31 additions & 9 deletions classes/resilient/book.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
-- 2021-2023, Didier Willis
-- License: MIT
--
local plain = require("classes.resilient.base")
local class = pl.class(plain)
local base = require("classes.resilient.base")
local class = pl.class(base)
class._name = "resilient.book"

local utils = require("resilient.utils")
Expand All @@ -13,7 +13,7 @@ local layoutParser = require("resilient.layoutparser")
-- CLASS DEFINITION

function class:_init (options)
plain._init(self, options)
base._init(self, options)

self:loadPackage("resilient.sectioning")
self:loadPackage("masters")
Expand Down Expand Up @@ -52,9 +52,16 @@ function class:_init (options)
-- https://github.com/sile-typesetter/sile/issues/1371
SILE.settings:set("shaper.spaceenlargementfactor", 1)

-- Override the standard foliostyle hook to rely on styles
-- Command override from loaded packages.
-- TRICKY, TO REMEMBER: Such overrides cannot be done in registerCommands()
-- as packages are not loaded yet.
-- ASSUMPTION: The corresponding packages are already loaded.
-- (Also, we must be sure that reloading them will not reset the hook...
-- but our base class cancels the multiple instanciation from SILE 0.14,
-- so we should be safe here)

-- Override the standard foliostyle hook to rely on styles
-- Package "folio" is loaded by the plain class.
self:registerCommand("foliostyle", function (_, content)
local styleName = SILE.documentState.documentClass:oddPage() and "folio-odd" or "folio-even"
SILE.call("style:apply:paragraph", { name = styleName }, function ()
Expand All @@ -68,10 +75,16 @@ function class:_init (options)
SILE.process(content)
end)
end)

-- Override the standard urlstyle hook to rely on styles
-- Package "url" is loaded by the markdown package.
self:registerCommand("urlstyle", function (_, content)
SILE.call("style:apply", { name = "url" }, content)
end)
end

function class:declareOptions ()
plain.declareOptions(self)
base.declareOptions(self)

self:declareOption("layout", function(_, value)
if value then
Expand All @@ -91,7 +104,7 @@ end
function class:setOptions (options)
options = options or {}
options.layout = options.layout or "division"
plain:setOptions(options) -- so that papersize etc. get processed...
base:setOptions(options) -- so that papersize etc. get processed...

local layout = layoutParser:match(options.layout)
if not layout then
Expand All @@ -114,6 +127,8 @@ function class:setOptions (options)
end

function class:registerStyles ()
base:registerStyles()

-- Sectioning styles
self:registerStyle("sectioning-base", {}, {
paragraph = { before = { indent = false },
Expand Down Expand Up @@ -328,6 +343,13 @@ function class:registerStyles ()
self:registerStyle("table-caption-ref-number", { inherit = "table-caption-base-number" }, {
numbering = { before = { text = "table " } }
})

-- url style
-- Default is similar to the plain \code command, and quite as bad, but at
-- least uses a font-relative size.
self:registerStyle("url", {}, {
font = { family = "Hack", size = "1.4ex" }
})
end

function class:endPage ()
Expand All @@ -336,11 +358,11 @@ function class:endPage ()
if headerContent then
self.packages["resilient.headers"]:outputHeader(headerContent)
end
return plain:endPage()
return base:endPage()
end

function class.declareSettings (_)
plain:declareSettings()
base:declareSettings()

SILE.settings:declare({
parameter = "book.blockquote.margin",
Expand All @@ -351,7 +373,7 @@ function class.declareSettings (_)
end

function class:registerCommands ()
plain:registerCommands()
base:registerCommands()

-- Running headers

Expand Down
14 changes: 8 additions & 6 deletions classes/resilient/resume.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
--
-- This is indeed very minimalist :)
--
local plain = require("classes.resilient.base")
local class = pl.class(plain)
local base = require("classes.resilient.base")
local class = pl.class(base)
class._name = "resilient.resume"

local utils = require("resilient.utils")
Expand Down Expand Up @@ -79,7 +79,7 @@ class.nextFrameset = {
}

function class:_init (options)
plain._init(self, options)
base._init(self, options)

self:loadPackage("color")
self:loadPackage("rules") -- for section rules
Expand Down Expand Up @@ -139,7 +139,7 @@ function class:newPage ()
-- See https://github.com/sile-typesetter/sile/issues/1544
-- Ditching the folio numbering check as the folio is not even incremented yet (?!)
-- Then the mess below _seems_ to work:
plain:newPage() -- It calls and returns self:initialFrame(), but heh...
base:newPage() -- It calls and returns self:initialFrame(), but heh...
self:switchMaster("next")
return self:initialFrame() -- And now this (?!)
end
Expand All @@ -162,11 +162,13 @@ function class:endPage ()
SILE.call("eject") -- for vfill to be effective
SILE.settings:popState()
end)
return plain:endPage()
return base:endPage()
end

-- STYLES
function class:registerStyles ()
base:registerStyles()

self:registerStyle("resume-firstname", {}, {
font = { style = "light" },
color = "#a6a6a6"
Expand Down Expand Up @@ -290,7 +292,7 @@ local doSection = function (rows, _, content)
end

function class:registerCommands ()
plain:registerCommands()
base:registerCommands()

self:registerCommand("cv-header", function (_, content)
local closure = SILE.settings:wrap()
Expand Down
4 changes: 4 additions & 0 deletions examples/lefevre-tuor-idril-styles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,7 @@ toc-pageno:
origin: "resilient.tableofcontents"
style:

url:
origin: "resilient.book"
style:

11 changes: 2 additions & 9 deletions examples/lefevre-tuor-idril.sil
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
\language[main=fr]
\font[family=Libertinus Serif]
%
% No longer required (bug in SILE 0.14.2
%\script{SILE.outputter:_ensureInit()}
%
% UGLY: We don't want URLs to be typeset using a typewriter font :)
% Just cancel the \code command so the default text font is used.
% Waiting for urlstyle in SILE code...
\define[command=code]{\process}%
%
\define[command=smallcaps]{\font[features=+smcp]{\process}}
\define[command=foreign:en]{\em{\language[main=en]{\process}}}
\define[command=foreign:gr]{\em{\language[main=und]{\process}}}
Expand All @@ -33,7 +25,8 @@
% We therefore wrap the concerned paragraph in a temporary environment where the
% stretchability is canceled...
\script{
SILE.registerCommand("initial", function (options, content)
local class = SILE.documentState.documentClass
class:registerCommand("initial", function (options, content)
SILE.settings:temporarily(function()
local blSkip = SILE.settings:get("document.baselineskip")
SILE.settings:set("document.baselineskip", SILE.nodefactory.vglue(SILE.length(blSkip.height.length)))
Expand Down
7 changes: 7 additions & 0 deletions examples/manual-styles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,10 @@ toc-pageno:
origin: "resilient.tableofcontents"
style:

url:
origin: "resilient.book"
style:
font:
family: "Hack"
size: "1.4ex"

0 comments on commit 56dea5e

Please sign in to comment.