Skip to content

Commit c37cf92

Browse files
cdervclaude
andcommitted
Decode Unicode variable names in CSS vars export block
The SCSS analyzer encodes non-ASCII characters as _u<hex>_ for parsing, but cssVarsBlock emitted these encoded names into the CSS vars block. Dart Sass then failed because the encoded names don't match the original SCSS variable names. Decode before emitting so names round-trip correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 800a3d4 commit c37cf92

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/core/sass/add-css-vars.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ import { getVariableDependencies } from "./analyzer/get-dependencies.ts";
1616

1717
const { getSassAst } = makeParserModule(parse);
1818

19+
// Reverse the _u<hex>_ encoding applied in parse.ts so that
20+
// variable names emitted into the CSS vars block match the
21+
// original SCSS source that Dart Sass compiles against.
22+
const decodeScssName = (name: string) =>
23+
name.replace(/_u([0-9a-f]+)_/g, (_, hex: string) =>
24+
String.fromCodePoint(parseInt(hex, 16))
25+
);
26+
1927
export class SCSSParsingError extends Error {
2028
constructor(message: string) {
2129
super(`SCSS Parsing Error: ${message}`);
@@ -38,7 +46,8 @@ export const cssVarsBlock = (scssSource: string) => {
3846
for (const [dep, _] of deps) {
3947
const decl = ast.get(dep);
4048
if (decl.valueType === "color") {
41-
output.push(`--quarto-scss-export-${dep}: #{$${dep}};`);
49+
const originalName = decodeScssName(dep);
50+
output.push(`--quarto-scss-export-${originalName}: #{$${originalName}};`);
4251
}
4352
}
4453
output.push("}");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*-- scss:defaults --*/
2+
$présentation-bg: #ff0000;
3+
4+
/*-- scss:rules --*/
5+
#test-unicode-var {
6+
background-color: $présentation-bg;
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: "Unicode SCSS Variable Test"
3+
format:
4+
html:
5+
theme:
6+
- default
7+
- custom-14065-var.scss
8+
_quarto:
9+
tests:
10+
html:
11+
ensureCssRegexMatches:
12+
- ['#test-unicode-var', 'background-color']
13+
---
14+
15+
Content with a unicode-named color variable in SCSS.

0 commit comments

Comments
 (0)