Skip to content

Commit

Permalink
put css-typst translation in brand.lua
Browse files Browse the repository at this point in the history
unclear if this is a win, since it forces get_background_color to reside in modules/brand.lua
  • Loading branch information
gordonwoodhull committed Aug 26, 2024
1 parent 20648fc commit 4874d1e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
24 changes: 22 additions & 2 deletions src/resources/filters/modules/brand/brand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@

local function get_color(name)
local brand = param("brand").processedData -- from src/core/brand/brand.ts
return brand.color[name]
local cssColor = brand.color[name]
if not cssColor then return nil end
if _quarto.format.isTypstOutput() then
return output_typst_color(parse_css_color(cssColor))
end
return cssColor
end

local BACKGROUND_OPACITY = 0.1

local function get_background_color(name)
local brand = param("brand").processedData -- from src/core/brand/brand.ts
local cssColor = brand.color[name]
if not cssColor then return nil end
if _quarto.format.isTypstOutput() then
return output_typst_color(parse_css_color(cssColor), {unit = 'fraction', value = BACKGROUND_OPACITY})
end
-- todo: implement for html if useful
return cssColor
end

return {
get_color = get_color
BACKGROUND_OPACITY = BACKGROUND_OPACITY,
get_color = get_color,
get_background_color = get_background_color,
}
1 change: 1 addition & 0 deletions src/resources/filters/modules/import_all.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
_quarto.modules = {
astshortcode = require("modules/astshortcode"),
authors = require("modules/authors"),
brand = require("modules/brand/brand"),
callouts = require("modules/callouts"),
classpredicates = require("modules/classpredicates"),
constants = require("modules/constants"),
Expand Down
11 changes: 5 additions & 6 deletions src/resources/filters/quarto-post/typst-brand-yaml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ function render_typst_brand_yaml()
if brand and brand.processedData and brand.processedData.color and next(brand.processedData.color) then
local brandColor = brand.processedData.color
local colors = {}
for name, color in pairs(brandColor) do
colors[name] = output_typst_color(parse_css_color(color))
for name, _ in pairs(brandColor) do
colors[name] = _quarto.modules.brand.get_color(name)
end
local decl = '#let brand-color = ' .. to_typst_dict_indent(colors)
quarto.doc.include_text('in-header', decl)
local BACKGROUND_OPACITY = 0.1
local themebk = {}
for name, color in pairs(brandColor) do
themebk[name] = output_typst_color(parse_css_color(color),
{unit = 'fraction', value = BACKGROUND_OPACITY})
for name, _ in pairs(brandColor) do
themebk[name] = _quarto.modules.brand.get_background_color(name)
end
-- for demo purposes only, should implement backgroundcolor and fontcolor
if brandColor.background then
Expand All @@ -60,7 +59,7 @@ function render_typst_brand_yaml()
if brandColor.foreground then
quarto.doc.include_text('in-header', '#set text(fill: brand-color.foreground)')
end
local decl = '// theme colors at opacity ' .. BACKGROUND_OPACITY .. '\n#let brand-color-background = ' .. to_typst_dict_indent(themebk)
local decl = '// theme colors at opacity ' .. _quarto.modules.brand.BACKGROUND_OPACITY .. '\n#let brand-color-background = ' .. to_typst_dict_indent(themebk)
quarto.doc.include_text('in-header', decl)
end
end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _quarto:
-
- 'burgundy: rgb\("#9a4665"\),'
- 'primary: rgb\("#447099"\),'
- 'primary: rgb\("#44709919"\),' # background
- 'title: (\r\n?|\n)\[(\r\n?|\n)Note(\r\n?|\n)\](\r\n?|\n), (\r\n?|\n)background_color: (\r\n?|\n)brand-color-background.primary'
- 'title: (\r\n?|\n)\[(\r\n?|\n)Warning(\r\n?|\n)\](\r\n?|\n), (\r\n?|\n)background_color: (\r\n?|\n)brand-color-background.warning'
-
Expand Down

0 comments on commit 4874d1e

Please sign in to comment.