@expressive-code/core
Advanced tools
Comparing version 0.35.1 to 0.35.2
@@ -48,5 +48,9 @@ import { Element } from 'hast'; | ||
* You can set the value to an empty string or `null` to remove the property. | ||
* | ||
* Use `valueFormat` to specify how the value should be serialized: | ||
* - `'raw'`: The value is used as-is. This is the default. | ||
* - `'string'`: The value is serialized as a CSS string value, escaping special characters. | ||
*/ | ||
declare function setInlineStyle(node: Element, cssProperty: string, value: string | null): void; | ||
declare function setInlineStyle(node: Element, cssProperty: string, value: string | null, valueFormat?: 'raw' | 'string'): void; | ||
export { addClassName, getClassNames, getInlineStyles, removeClassName, setInlineStyle, setInlineStyles, setProperty }; |
@@ -9,2 +9,23 @@ // src/hast.ts | ||
import postcss, { Declaration } from "postcss"; | ||
// src/internal/escaping.ts | ||
function serializeCssStringValue(value, quoteStyle = "single") { | ||
const quote = quoteStyle === "single" ? "'" : '"'; | ||
const escapedValue = Array.from(value).map((char) => { | ||
const code = char.charCodeAt(0); | ||
switch (true) { | ||
case code === 0: | ||
return "\uFFFD"; | ||
case (code >= 1 && code <= 31 || code === 127): | ||
return `\\${code.toString(16)} `; | ||
case (char === quote || char === "\\"): | ||
return `\\${char}`; | ||
default: | ||
return char; | ||
} | ||
}).join(""); | ||
return `${quote}${escapedValue}${quote}`; | ||
} | ||
// src/hast.ts | ||
function setProperty(node, propertyName, value) { | ||
@@ -69,6 +90,6 @@ const properties = node.properties || {}; | ||
} | ||
function setInlineStyle(node, cssProperty, value) { | ||
function setInlineStyle(node, cssProperty, value, valueFormat = "raw") { | ||
const styles = getInlineStyles(node); | ||
if (value !== null) { | ||
styles.set(cssProperty, value); | ||
styles.set(cssProperty, valueFormat === "string" ? serializeCssStringValue(value) : value); | ||
} else { | ||
@@ -75,0 +96,0 @@ styles.delete(cssProperty); |
{ | ||
"name": "@expressive-code/core", | ||
"version": "0.35.1", | ||
"version": "0.35.2", | ||
"description": "A text marking & annotation engine for presenting source code on the web.", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
647432
6827