From 92f09091a83016dd3ac2f99dc7be19f027d2d553 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 8 Aug 2023 15:16:28 -0700 Subject: [PATCH 1/2] fix markdown color --- d2renderers/d2svg/d2svg.go | 13 +- e2etests/stable_test.go | 5 + .../stable/font_colors/dagre/board.exp.json | 40 + .../stable/font_colors/dagre/sketch.exp.svg | 913 ++++++++++++++++-- .../stable/font_colors/elk/board.exp.json | 40 + .../stable/font_colors/elk/sketch.exp.svg | 913 ++++++++++++++++-- 6 files changed, 1759 insertions(+), 165 deletions(-) diff --git a/d2renderers/d2svg/d2svg.go b/d2renderers/d2svg/d2svg.go index 75d4d487c9..2a7428ac52 100644 --- a/d2renderers/d2svg/d2svg.go +++ b/d2renderers/d2svg/d2svg.go @@ -1312,9 +1312,20 @@ func drawShape(writer, appendixWriter io.Writer, diagramHash string, targetShape mdEl := d2themes.NewThemableElement("div") mdEl.ClassName = "md" mdEl.Content = render + + // We have to set with styles since within foreignObject, we're in html + // land and not SVG attributes + var styles []string if targetShape.FontSize != textmeasure.MarkdownFontSize { - mdEl.Style = fmt.Sprintf("font-size:%vpx", targetShape.FontSize) + styles = append(styles, fmt.Sprintf("font-size:%vpx", targetShape.FontSize)) + } + + if !color.IsThemeColor(targetShape.Color) { + styles = append(styles, fmt.Sprintf(`color:%s`, targetShape.Color)) } + + mdEl.Style = strings.Join(styles, ";") + fmt.Fprint(writer, mdEl.Render()) fmt.Fprint(writer, ``) } else { diff --git a/e2etests/stable_test.go b/e2etests/stable_test.go index 0af331dafb..ae6f36ac01 100644 --- a/e2etests/stable_test.go +++ b/e2etests/stable_test.go @@ -1349,6 +1349,11 @@ beta: { alpha -> beta: gamma { style.font-color: green } +c: |md + colored +| { + style.font-color: blue +} `, }, { diff --git a/e2etests/testdata/stable/font_colors/dagre/board.exp.json b/e2etests/testdata/stable/font_colors/dagre/board.exp.json index 837aadec2a..f866fb0928 100644 --- a/e2etests/testdata/stable/font_colors/dagre/board.exp.json +++ b/e2etests/testdata/stable/font_colors/dagre/board.exp.json @@ -84,6 +84,46 @@ "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 + }, + { + "id": "c", + "type": "text", + "pos": { + "x": 145, + "y": 21 + }, + "width": 52, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "N1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "colored", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "blue", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 52, + "labelHeight": 24, + "zIndex": 0, + "level": 1 } ], "connections": [ diff --git a/e2etests/testdata/stable/font_colors/dagre/sketch.exp.svg b/e2etests/testdata/stable/font_colors/dagre/sketch.exp.svg index 0c0b27e9fe..681f52a5a4 100644 --- a/e2etests/testdata/stable/font_colors/dagre/sketch.exp.svg +++ b/e2etests/testdata/stable/font_colors/dagre/sketch.exp.svg @@ -1,17 +1,28 @@ -alphabeta gamma - + .d2-2495316546 .fill-N1{fill:#0A0F25;} + .d2-2495316546 .fill-N2{fill:#676C7E;} + .d2-2495316546 .fill-N3{fill:#9499AB;} + .d2-2495316546 .fill-N4{fill:#CFD2DD;} + .d2-2495316546 .fill-N5{fill:#DEE1EB;} + .d2-2495316546 .fill-N6{fill:#EEF1F8;} + .d2-2495316546 .fill-N7{fill:#FFFFFF;} + .d2-2495316546 .fill-B1{fill:#0D32B2;} + .d2-2495316546 .fill-B2{fill:#0D32B2;} + .d2-2495316546 .fill-B3{fill:#E3E9FD;} + .d2-2495316546 .fill-B4{fill:#E3E9FD;} + .d2-2495316546 .fill-B5{fill:#EDF0FD;} + .d2-2495316546 .fill-B6{fill:#F7F8FE;} + .d2-2495316546 .fill-AA2{fill:#4A6FF3;} + .d2-2495316546 .fill-AA4{fill:#EDF0FD;} + .d2-2495316546 .fill-AA5{fill:#F7F8FE;} + .d2-2495316546 .fill-AB4{fill:#EDF0FD;} + .d2-2495316546 .fill-AB5{fill:#F7F8FE;} + .d2-2495316546 .stroke-N1{stroke:#0A0F25;} + .d2-2495316546 .stroke-N2{stroke:#676C7E;} + .d2-2495316546 .stroke-N3{stroke:#9499AB;} + .d2-2495316546 .stroke-N4{stroke:#CFD2DD;} + .d2-2495316546 .stroke-N5{stroke:#DEE1EB;} + .d2-2495316546 .stroke-N6{stroke:#EEF1F8;} + .d2-2495316546 .stroke-N7{stroke:#FFFFFF;} + .d2-2495316546 .stroke-B1{stroke:#0D32B2;} + .d2-2495316546 .stroke-B2{stroke:#0D32B2;} + .d2-2495316546 .stroke-B3{stroke:#E3E9FD;} + .d2-2495316546 .stroke-B4{stroke:#E3E9FD;} + .d2-2495316546 .stroke-B5{stroke:#EDF0FD;} + .d2-2495316546 .stroke-B6{stroke:#F7F8FE;} + .d2-2495316546 .stroke-AA2{stroke:#4A6FF3;} + .d2-2495316546 .stroke-AA4{stroke:#EDF0FD;} + .d2-2495316546 .stroke-AA5{stroke:#F7F8FE;} + .d2-2495316546 .stroke-AB4{stroke:#EDF0FD;} + .d2-2495316546 .stroke-AB5{stroke:#F7F8FE;} + .d2-2495316546 .background-color-N1{background-color:#0A0F25;} + .d2-2495316546 .background-color-N2{background-color:#676C7E;} + .d2-2495316546 .background-color-N3{background-color:#9499AB;} + .d2-2495316546 .background-color-N4{background-color:#CFD2DD;} + .d2-2495316546 .background-color-N5{background-color:#DEE1EB;} + .d2-2495316546 .background-color-N6{background-color:#EEF1F8;} + .d2-2495316546 .background-color-N7{background-color:#FFFFFF;} + .d2-2495316546 .background-color-B1{background-color:#0D32B2;} + .d2-2495316546 .background-color-B2{background-color:#0D32B2;} + .d2-2495316546 .background-color-B3{background-color:#E3E9FD;} + .d2-2495316546 .background-color-B4{background-color:#E3E9FD;} + .d2-2495316546 .background-color-B5{background-color:#EDF0FD;} + .d2-2495316546 .background-color-B6{background-color:#F7F8FE;} + .d2-2495316546 .background-color-AA2{background-color:#4A6FF3;} + .d2-2495316546 .background-color-AA4{background-color:#EDF0FD;} + .d2-2495316546 .background-color-AA5{background-color:#F7F8FE;} + .d2-2495316546 .background-color-AB4{background-color:#EDF0FD;} + .d2-2495316546 .background-color-AB5{background-color:#F7F8FE;} + .d2-2495316546 .color-N1{color:#0A0F25;} + .d2-2495316546 .color-N2{color:#676C7E;} + .d2-2495316546 .color-N3{color:#9499AB;} + .d2-2495316546 .color-N4{color:#CFD2DD;} + .d2-2495316546 .color-N5{color:#DEE1EB;} + .d2-2495316546 .color-N6{color:#EEF1F8;} + .d2-2495316546 .color-N7{color:#FFFFFF;} + .d2-2495316546 .color-B1{color:#0D32B2;} + .d2-2495316546 .color-B2{color:#0D32B2;} + .d2-2495316546 .color-B3{color:#E3E9FD;} + .d2-2495316546 .color-B4{color:#E3E9FD;} + .d2-2495316546 .color-B5{color:#EDF0FD;} + .d2-2495316546 .color-B6{color:#F7F8FE;} + .d2-2495316546 .color-AA2{color:#4A6FF3;} + .d2-2495316546 .color-AA4{color:#EDF0FD;} + .d2-2495316546 .color-AA5{color:#F7F8FE;} + .d2-2495316546 .color-AB4{color:#EDF0FD;} + .d2-2495316546 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>alphabeta

colored

+
gamma + +
\ No newline at end of file diff --git a/e2etests/testdata/stable/font_colors/elk/board.exp.json b/e2etests/testdata/stable/font_colors/elk/board.exp.json index 2b2fec8124..7362626fe4 100644 --- a/e2etests/testdata/stable/font_colors/elk/board.exp.json +++ b/e2etests/testdata/stable/font_colors/elk/board.exp.json @@ -84,6 +84,46 @@ "labelPosition": "INSIDE_MIDDLE_CENTER", "zIndex": 0, "level": 1 + }, + { + "id": "c", + "type": "text", + "pos": { + "x": 117, + "y": 33 + }, + "width": 52, + "height": 24, + "opacity": 1, + "strokeDash": 0, + "strokeWidth": 2, + "borderRadius": 0, + "fill": "transparent", + "stroke": "N1", + "shadow": false, + "3d": false, + "multiple": false, + "double-border": false, + "tooltip": "", + "link": "", + "icon": null, + "iconPosition": "", + "blend": false, + "fields": null, + "methods": null, + "columns": null, + "label": "colored", + "fontSize": 16, + "fontFamily": "DEFAULT", + "language": "markdown", + "color": "blue", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 52, + "labelHeight": 24, + "zIndex": 0, + "level": 1 } ], "connections": [ diff --git a/e2etests/testdata/stable/font_colors/elk/sketch.exp.svg b/e2etests/testdata/stable/font_colors/elk/sketch.exp.svg index 13ebf427eb..19b9d29077 100644 --- a/e2etests/testdata/stable/font_colors/elk/sketch.exp.svg +++ b/e2etests/testdata/stable/font_colors/elk/sketch.exp.svg @@ -1,17 +1,28 @@ -alphabeta gamma - + .d2-2154937806 .fill-N1{fill:#0A0F25;} + .d2-2154937806 .fill-N2{fill:#676C7E;} + .d2-2154937806 .fill-N3{fill:#9499AB;} + .d2-2154937806 .fill-N4{fill:#CFD2DD;} + .d2-2154937806 .fill-N5{fill:#DEE1EB;} + .d2-2154937806 .fill-N6{fill:#EEF1F8;} + .d2-2154937806 .fill-N7{fill:#FFFFFF;} + .d2-2154937806 .fill-B1{fill:#0D32B2;} + .d2-2154937806 .fill-B2{fill:#0D32B2;} + .d2-2154937806 .fill-B3{fill:#E3E9FD;} + .d2-2154937806 .fill-B4{fill:#E3E9FD;} + .d2-2154937806 .fill-B5{fill:#EDF0FD;} + .d2-2154937806 .fill-B6{fill:#F7F8FE;} + .d2-2154937806 .fill-AA2{fill:#4A6FF3;} + .d2-2154937806 .fill-AA4{fill:#EDF0FD;} + .d2-2154937806 .fill-AA5{fill:#F7F8FE;} + .d2-2154937806 .fill-AB4{fill:#EDF0FD;} + .d2-2154937806 .fill-AB5{fill:#F7F8FE;} + .d2-2154937806 .stroke-N1{stroke:#0A0F25;} + .d2-2154937806 .stroke-N2{stroke:#676C7E;} + .d2-2154937806 .stroke-N3{stroke:#9499AB;} + .d2-2154937806 .stroke-N4{stroke:#CFD2DD;} + .d2-2154937806 .stroke-N5{stroke:#DEE1EB;} + .d2-2154937806 .stroke-N6{stroke:#EEF1F8;} + .d2-2154937806 .stroke-N7{stroke:#FFFFFF;} + .d2-2154937806 .stroke-B1{stroke:#0D32B2;} + .d2-2154937806 .stroke-B2{stroke:#0D32B2;} + .d2-2154937806 .stroke-B3{stroke:#E3E9FD;} + .d2-2154937806 .stroke-B4{stroke:#E3E9FD;} + .d2-2154937806 .stroke-B5{stroke:#EDF0FD;} + .d2-2154937806 .stroke-B6{stroke:#F7F8FE;} + .d2-2154937806 .stroke-AA2{stroke:#4A6FF3;} + .d2-2154937806 .stroke-AA4{stroke:#EDF0FD;} + .d2-2154937806 .stroke-AA5{stroke:#F7F8FE;} + .d2-2154937806 .stroke-AB4{stroke:#EDF0FD;} + .d2-2154937806 .stroke-AB5{stroke:#F7F8FE;} + .d2-2154937806 .background-color-N1{background-color:#0A0F25;} + .d2-2154937806 .background-color-N2{background-color:#676C7E;} + .d2-2154937806 .background-color-N3{background-color:#9499AB;} + .d2-2154937806 .background-color-N4{background-color:#CFD2DD;} + .d2-2154937806 .background-color-N5{background-color:#DEE1EB;} + .d2-2154937806 .background-color-N6{background-color:#EEF1F8;} + .d2-2154937806 .background-color-N7{background-color:#FFFFFF;} + .d2-2154937806 .background-color-B1{background-color:#0D32B2;} + .d2-2154937806 .background-color-B2{background-color:#0D32B2;} + .d2-2154937806 .background-color-B3{background-color:#E3E9FD;} + .d2-2154937806 .background-color-B4{background-color:#E3E9FD;} + .d2-2154937806 .background-color-B5{background-color:#EDF0FD;} + .d2-2154937806 .background-color-B6{background-color:#F7F8FE;} + .d2-2154937806 .background-color-AA2{background-color:#4A6FF3;} + .d2-2154937806 .background-color-AA4{background-color:#EDF0FD;} + .d2-2154937806 .background-color-AA5{background-color:#F7F8FE;} + .d2-2154937806 .background-color-AB4{background-color:#EDF0FD;} + .d2-2154937806 .background-color-AB5{background-color:#F7F8FE;} + .d2-2154937806 .color-N1{color:#0A0F25;} + .d2-2154937806 .color-N2{color:#676C7E;} + .d2-2154937806 .color-N3{color:#9499AB;} + .d2-2154937806 .color-N4{color:#CFD2DD;} + .d2-2154937806 .color-N5{color:#DEE1EB;} + .d2-2154937806 .color-N6{color:#EEF1F8;} + .d2-2154937806 .color-N7{color:#FFFFFF;} + .d2-2154937806 .color-B1{color:#0D32B2;} + .d2-2154937806 .color-B2{color:#0D32B2;} + .d2-2154937806 .color-B3{color:#E3E9FD;} + .d2-2154937806 .color-B4{color:#E3E9FD;} + .d2-2154937806 .color-B5{color:#EDF0FD;} + .d2-2154937806 .color-B6{color:#F7F8FE;} + .d2-2154937806 .color-AA2{color:#4A6FF3;} + .d2-2154937806 .color-AA4{color:#EDF0FD;} + .d2-2154937806 .color-AA5{color:#F7F8FE;} + .d2-2154937806 .color-AB4{color:#EDF0FD;} + .d2-2154937806 .color-AB5{color:#F7F8FE;}.appendix text.text{fill:#0A0F25}.md{--color-fg-default:#0A0F25;--color-fg-muted:#676C7E;--color-fg-subtle:#9499AB;--color-canvas-default:#FFFFFF;--color-canvas-subtle:#EEF1F8;--color-border-default:#0D32B2;--color-border-muted:#0D32B2;--color-neutral-muted:#EEF1F8;--color-accent-fg:#0D32B2;--color-accent-emphasis:#0D32B2;--color-attention-subtle:#676C7E;--color-danger-fg:red;}.sketch-overlay-B1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B2{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-B3{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-B6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-AA4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AA5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB4{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-AB5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N1{fill:url(#streaks-darker);mix-blend-mode:lighten}.sketch-overlay-N2{fill:url(#streaks-dark);mix-blend-mode:overlay}.sketch-overlay-N3{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N4{fill:url(#streaks-normal);mix-blend-mode:color-burn}.sketch-overlay-N5{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N6{fill:url(#streaks-bright);mix-blend-mode:darken}.sketch-overlay-N7{fill:url(#streaks-bright);mix-blend-mode:darken}.light-code{display: block}.dark-code{display: none}]]>alphabeta

colored

+
gamma + +
\ No newline at end of file From ae2b298de11a1c935b8af336ac5eb521731278ef Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 8 Aug 2023 15:17:42 -0700 Subject: [PATCH 2/2] changelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index f32b367f3b..bae88cb9ef 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -5,6 +5,7 @@ #### Improvements 🧹 - Latex now includes Mathjax's ASM extension for more powerful Latex functionality [#1544](https://github.com/terrastruct/d2/pull/1544) +- `font-color` works on Markdown [#1546](https://github.com/terrastruct/d2/pull/1546) #### Bugfixes ⛑️