From daa458b38cdb091f47b94ee90d2c810b52aec9f2 Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Wed, 13 Mar 2024 23:57:34 +0100 Subject: [PATCH] feat: Support bare percentage in width and height options --- examples/sile-and-djot.dj | 6 +++--- examples/sile-and-markdown.md | 4 ++-- packages/markdown/cmbase.lua | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/examples/sile-and-djot.dj b/examples/sile-and-djot.dj index ef0ac8a..9a22118 100644 --- a/examples/sile-and-djot.dj +++ b/examples/sile-and-djot.dj @@ -56,7 +56,7 @@ The core concepts in Djot mirror those of Markdown, featuring inline and block e Attributes are additional properties or metadata that can be associated with certain elements, allowing for more fine-grained control over the appearance and behavior of elements. -![Djot concepts at a glance.](./djot-concept-simplified.svg){width="75%lw"} +![Djot concepts at a glance.](./djot-concept-simplified.svg){width="75%"} ## Attributes @@ -346,14 +346,14 @@ This inline "manicule" is obtained with: Files in Graphviz DOT graph language (`.dot`) are supported and rendered as images, when the *embedders.sile* collection is properly configured. -![The *markdown.sile* ecosystem (simplified).](./markdown-sile-schema.dot){width="90%lw"} +![The *markdown.sile* ecosystem (simplified).](./markdown-sile-schema.dot){width="90%"} This image is obtained with the following syntax. {custom-style=CodeBlock} ::: ``` -![The *markdown.sile* ecosystem (simplified).](./markdown-sile-schema.dot){width="90%lw"} +![The *markdown.sile* ecosystem (simplified).](./markdown-sile-schema.dot){width="90%"} ``` ::: diff --git a/examples/sile-and-markdown.md b/examples/sile-and-markdown.md index e3933e2..40c3f84 100644 --- a/examples/sile-and-markdown.md +++ b/examples/sile-and-markdown.md @@ -323,13 +323,13 @@ This inline "manicule" is obtained with: Files in Graphviz DOT graph language (`.dot`) are supported and rendered as images, when the **embedders.sile** collection is properly configured. -![The **markdown.sile** ecosystem (simplified).](./markdown-sile-schema.dot){width="90%lw"} +![The **markdown.sile** ecosystem (simplified).](./markdown-sile-schema.dot){width="90%"} This image is obtained with the following syntax. ::: {custom-style=CodeBlock} ``` -![The **markdown.sile** ecosystem (simplified).](./markdown-sile-schema.dot){width="90%lw"} +![The **markdown.sile** ecosystem (simplified).](./markdown-sile-schema.dot){width="90%"} ``` ::: diff --git a/packages/markdown/cmbase.lua b/packages/markdown/cmbase.lua index 11f4336..20ecf2b 100644 --- a/packages/markdown/cmbase.lua +++ b/packages/markdown/cmbase.lua @@ -115,6 +115,23 @@ function package:_init (_) end) end +function package:registerCommand(name, func, help, pack) + local tweakCommandWithKnownOptions = function (options, content) + options = options or {} + -- Tweak known options to be compatible with SILE units. + -- width and height in percentage are replaced by line and frame relative + -- units, respectively. + if options.width and type(options.width) == "string" then + options.width = options.width:gsub("%%$", "%%lw") + end + if options.height and type(options.height) == "string" then + options.height = options.height:gsub("%%$", "%%fh") + end + return func(options, content) + end + base.registerCommand(self, name, tweakCommandWithKnownOptions, help, pack) +end + --- Register a style (as in resilient packages). function package:registerStyle (name, opts, styledef) return self.styles:defineStyle(name, opts, styledef, self._name)