@particle-academy/fancy-code 0.4.2 → 0.4.4

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.js CHANGED
@@ -1232,6 +1232,10 @@ registerTheme({
1232
1232
  function escapeHtml(text) {
1233
1233
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1234
1234
  }
1235
+ var COLOR_RE = /^(#[0-9a-fA-F]{3,8}|(?:rgb|rgba|hsl|hsla)\([\d\s,.%/-]+\)|[a-zA-Z]+)$/;
1236
+ function safeColor(value) {
1237
+ return typeof value === "string" && COLOR_RE.test(value.trim()) ? value.trim() : "inherit";
1238
+ }
1235
1239
  function highlightCode(source, tokens, colors) {
1236
1240
  if (tokens.length === 0) return escapeHtml(source);
1237
1241
  const colorMap = {
@@ -1256,7 +1260,7 @@ function highlightCode(source, tokens, colors) {
1256
1260
  parts.push(escapeHtml(source.slice(pos, token.start)));
1257
1261
  }
1258
1262
  const text = escapeHtml(source.slice(token.start, token.end));
1259
- const color = colorMap[token.type];
1263
+ const color = safeColor(colorMap[token.type]);
1260
1264
  const style = token.type === "comment" ? `color:${color};font-style:italic` : `color:${color}`;
1261
1265
  parts.push(`<span style="${style}">${text}</span>`);
1262
1266
  pos = token.end;