@ape-egg/codie 0.1.0 → 0.1.1

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/codie.js CHANGED
@@ -41,8 +41,8 @@ const getHighlightModes = (el) => {
41
41
  const highlight = (code, modes, options = {}) => {
42
42
  const escaped = escapeHTML(code);
43
43
 
44
- // When all modes are enabled (no explicit attribute), detect JSON by content
45
- const looksLikeJSON = /^\s*[{\[]/.test(code);
44
+ // Detect JSON by content: must start with { or [ AND contain quoted key patterns
45
+ const looksLikeJSON = /^\s*[{\[]/.test(code) && /"[^"]*"\s*:/.test(code);
46
46
 
47
47
  // JSON takes priority over HTML when content looks like JSON
48
48
  if (modes.json && looksLikeJSON) {
@@ -57,9 +57,12 @@ const highlight = (code, modes, options = {}) => {
57
57
  });
58
58
  }
59
59
 
60
- // Fallback: explicit mode selected or no HTML detected
61
- if (modes.json && !modes.html) {
62
- return highlightJSON(escaped);
60
+ // Standalone mode (no HTML): use direct highlighters, not the *Only variants
61
+ if (!modes.html) {
62
+ if (modes.json) return highlightJSON(escaped);
63
+ if (modes.css) return highlightCSS(escaped);
64
+ if (modes.js) return highlightJS(escaped);
65
+ return escaped;
63
66
  }
64
67
 
65
68
  let result = escaped;
package/highlight.js CHANGED
@@ -405,6 +405,12 @@ export const highlightHTML = (
405
405
  ? match
406
406
  : open + highlightCSS(content) + close,
407
407
  );
408
+
409
+ // CSS rules outside <style> tags (bare CSS blocks in mixed HTML+CSS snippets)
410
+ highlighted = highlighted.replace(
411
+ /([^<>{}]+\{[^<>{}]*\})/g,
412
+ (match) => /[\w-]+\s*:\s*/.test(match) ? highlightCSS(match) : match,
413
+ );
408
414
  }
409
415
 
410
416
  // Remaining @[...] patterns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ape-egg/codie",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Modular code display and editing package",
5
5
  "type": "module",
6
6
  "main": "codie.js",
@@ -21,9 +21,6 @@
21
21
  "syntax-highlighting",
22
22
  "code-display"
23
23
  ],
24
- "author": "Kim Korte",
25
- "license": "ISC",
26
- "publishConfig": {
27
- "access": "public"
28
- }
24
+ "author": "kortes",
25
+ "license": "MIT"
29
26
  }