Skip to content

Commit 6b79a24

Browse files
authored
Merge pull request #2429 from alixander/fix-dark-theme-c4-theme
fix markdown not adapting colors to themes
2 parents 4e85eb7 + 9009e08 commit 6b79a24

File tree

102 files changed

+210
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+210
-299
lines changed

d2renderers/d2sketch/testdata/opacity/sketch.exp.svg

+1-2
Loading

d2renderers/d2sketch/testdata/opacity_dark/sketch.exp.svg

+1-2
Loading

d2renderers/d2sketch/testdata/root-fill/sketch.exp.svg

+1-2
Loading

d2renderers/d2sketch/testdata/twitter/sketch.exp.svg

+2-3
Loading

d2renderers/d2sketch/testdata/twitter_dark/sketch.exp.svg

+2-3
Loading

d2renderers/d2svg/d2svg.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -1732,23 +1732,31 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape
17321732
render = strings.ReplaceAll(render, "<hr>", "<hr />")
17331733

17341734
mdEl := d2themes.NewThemableElement("div", inlineTheme)
1735-
mdEl.ClassName = "md"
17361735
mdEl.Content = render
17371736

17381737
// We have to set with styles since within foreignObject, we're in html
17391738
// land and not SVG attributes
17401739
var styles []string
1740+
var classes []string = []string{"md"}
17411741
if targetShape.FontSize != textmeasure.MarkdownFontSize {
17421742
styles = append(styles, fmt.Sprintf("font-size:%vpx", targetShape.FontSize))
17431743
}
1744+
17441745
if targetShape.Fill != "" && targetShape.Fill != "transparent" {
1745-
styles = append(styles, fmt.Sprintf(`background-color:%s`, targetShape.Fill))
1746+
if color.IsThemeColor(targetShape.Fill) {
1747+
classes = append(classes, fmt.Sprintf("fill-%s", targetShape.Fill))
1748+
} else {
1749+
styles = append(styles, fmt.Sprintf(`background-color:%s`, targetShape.Fill))
1750+
}
17461751
}
1752+
17471753
if !color.IsThemeColor(targetShape.Color) {
17481754
styles = append(styles, fmt.Sprintf(`color:%s`, targetShape.Color))
1749-
} else if inlineTheme != nil {
1750-
styles = append(styles, fmt.Sprintf(`color:%s`, d2themes.ResolveThemeColor(*inlineTheme, targetShape.Color)))
1755+
} else {
1756+
classes = append(classes, fmt.Sprintf("color-%s", targetShape.Color))
17511757
}
1758+
1759+
mdEl.ClassName = strings.Join(classes, " ")
17521760
// When using dark theme, inlineTheme is nil and we rely on CSS variables
17531761

17541762
mdEl.Style = strings.Join(styles, ";")
@@ -1948,6 +1956,7 @@ func EmbedFonts(buf *bytes.Buffer, diagramHash, source string, fontFamily *d2fon
19481956
`class="text"`,
19491957
`class="text `,
19501958
`class="md"`,
1959+
`class="md `,
19511960
},
19521961
fmt.Sprintf(`
19531962
.%s .text {
@@ -1967,7 +1976,10 @@ func EmbedFonts(buf *bytes.Buffer, diagramHash, source string, fontFamily *d2fon
19671976
appendOnTrigger(
19681977
buf,
19691978
source,
1970-
[]string{`class="md"`},
1979+
[]string{
1980+
`class="md"`,
1981+
`class="md `,
1982+
},
19711983
fmt.Sprintf(`
19721984
@font-face {
19731985
font-family: %s-font-semibold;

d2renderers/d2svg/dark_theme/testdata/code/dark_theme.exp.svg

+1-2
Loading

d2renderers/d2svg/dark_theme/testdata/opacity/dark_theme.exp.svg

+1-2
Loading

0 commit comments

Comments
 (0)