first pass at color name => theme color processing for pikchr

This commit is contained in:
2023-05-09 21:32:48 -07:00
parent 3553ced719
commit d9c3371245
2 changed files with 151 additions and 20 deletions

View File

@@ -14,6 +14,7 @@ import { bind_data_async } from './async-steps';
import { render_vega_spec } from './vega';
import { parse_attributes } from './attrs';
import { MarkdownOptions } from './render';
import { post_process_pikchr_svg } from './pikchr';
export function create_renderer(opts: MarkdownOptions) {
const renderer = new marked.Renderer();
@@ -275,23 +276,3 @@ function post_process_nomnoml_svg(svg: string, size?: string) {
return svg;
}
const svg_text_fill_rgb_000 = /\b<text fill="rgb\(0,0,0\)"/gi;
const svg_fill_rgb_000 = /fill:rgb\(0,0,0\)/gi;
const svg_stroke_rgb_000 = /stroke:rgb\(0,0,0\)/gi;
// todo: css variables
function post_process_pikchr_svg(svg: string, size?: string) {
svg = strip_svg(svg);
// text
svg = svg.replace(svg_text_fill_rgb_000, '<text fill="var(--theme-text-body, currentcolor)"');
// arrow heads
svg = svg.replace(svg_fill_rgb_000, 'fill:var(--theme-line, currentcolor)');
// lines / boxes
svg = svg.replace(svg_stroke_rgb_000, 'stroke:var(--theme-line, currentcolor)');
return svg;
}