@particle-academy/fancy-code 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1234,6 +1234,10 @@ registerTheme({
1234
1234
  function escapeHtml(text) {
1235
1235
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1236
1236
  }
1237
+ var COLOR_RE = /^(#[0-9a-fA-F]{3,8}|(?:rgb|rgba|hsl|hsla)\([\d\s,.%/-]+\)|[a-zA-Z]+)$/;
1238
+ function safeColor(value) {
1239
+ return typeof value === "string" && COLOR_RE.test(value.trim()) ? value.trim() : "inherit";
1240
+ }
1237
1241
  function highlightCode(source, tokens, colors) {
1238
1242
  if (tokens.length === 0) return escapeHtml(source);
1239
1243
  const colorMap = {
@@ -1258,7 +1262,7 @@ function highlightCode(source, tokens, colors) {
1258
1262
  parts.push(escapeHtml(source.slice(pos, token.start)));
1259
1263
  }
1260
1264
  const text = escapeHtml(source.slice(token.start, token.end));
1261
- const color = colorMap[token.type];
1265
+ const color = safeColor(colorMap[token.type]);
1262
1266
  const style = token.type === "comment" ? `color:${color};font-style:italic` : `color:${color}`;
1263
1267
  parts.push(`<span style="${style}">${text}</span>`);
1264
1268
  pos = token.end;