Skip to content

Commit a413fb0

Browse files
committed
Allow PDF to specify both bgcolor and border color
fixes #2242
1 parent 64dc0b1 commit a413fb0

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/resources/filters/layout/meta.lua

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ function layoutMetaInject()
4444

4545
-- figure out the shadecolor
4646
local shadeColor = nil
47+
local bgColor = nil
48+
4749
if useCodeBlockBorder and meta[kCodeBlockBorderLeft] and type(meta[kCodeBlockBorderLeft]) ~= "boolean" then
4850
shadeColor = latexXColor(meta[kCodeBlockBorderLeft])
49-
elseif useCodeBlockBg and meta[kCodeBlockBackground] and type(meta[kCodeBlockBackground]) ~= "boolean" then
50-
shadeColor = latexXColor(meta[kCodeBlockBackground])
51+
end
52+
if useCodeBlockBg and meta[kCodeBlockBackground] and type(meta[kCodeBlockBackground]) ~= "boolean" then
53+
bgColor = latexXColor(meta[kCodeBlockBackground])
5154
end
5255

5356
-- ensure shadecolor is defined
@@ -63,24 +66,32 @@ function layoutMetaInject()
6366
end
6467
end)
6568

69+
metaInjectLatex(meta, function(inject)
70+
if (bgColor ~= nil) then
71+
inject(
72+
"\\@ifundefined{codebgcolor}{\\definecolor{codebgcolor}" .. bgColor .. "}"
73+
)
74+
end
75+
end)
76+
6677
-- set color options for code blocks ('Shaded')
78+
-- core options
6779
local options = {
68-
['interior hidden'] = "",
6980
boxrule = '0pt',
7081
['frame hidden'] = "",
7182
['sharp corners'] = "",
7283
['breakable'] = "",
7384
enhanced = "",
7485
['borderline west'] = '{3pt}{0pt}{shadecolor}'
7586
}
76-
if useCodeBlockBg then
77-
options = {
78-
colback = "{shadecolor}",
79-
boxrule = '0pt',
80-
['frame hidden'] = "",
81-
['breakable'] = "",
82-
enhanced = "",
83-
}
87+
if bgColor then
88+
options.colback = "{codebgcolor}"
89+
else
90+
options['interior hidden'] = ""
91+
end
92+
93+
if shadeColor then
94+
options['borderline west'] = '{3pt}{0pt}{shadecolor}'
8495
end
8596

8697
-- redefined the 'Shaded' environment that pandoc uses for fenced

0 commit comments

Comments
 (0)