@scalar/code-highlight 0.3.3 → 0.3.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/chunks/code.js +124 -0
  3. package/dist/chunks/code.js.map +1 -0
  4. package/dist/chunks/languages.js +12720 -0
  5. package/dist/chunks/languages.js.map +1 -0
  6. package/dist/chunks/lib.js +13688 -0
  7. package/dist/chunks/lib.js.map +1 -0
  8. package/dist/chunks/lib2.js +731 -0
  9. package/dist/chunks/lib2.js.map +1 -0
  10. package/dist/chunks/markdown.js +20921 -0
  11. package/dist/chunks/markdown.js.map +1 -0
  12. package/dist/chunks/rehype-alert.js +74 -0
  13. package/dist/chunks/rehype-alert.js.map +1 -0
  14. package/dist/chunks/rehype-highlight.js +2987 -0
  15. package/dist/chunks/rehype-highlight.js.map +1 -0
  16. package/dist/code/index.d.ts +1 -1
  17. package/dist/code/index.js +3 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +6 -5
  20. package/dist/languages/index.d.ts +3 -3
  21. package/dist/languages/index.js +2 -3
  22. package/dist/markdown/index.d.ts +1 -1
  23. package/dist/markdown/index.js +3 -1
  24. package/dist/markdown/markdown.d.ts.map +1 -1
  25. package/dist/rehype-alert/index.d.ts +1 -1
  26. package/dist/rehype-alert/index.js +2 -1
  27. package/dist/rehype-highlight/index.d.ts +1 -1
  28. package/dist/rehype-highlight/index.js +2 -1
  29. package/package.json +4 -4
  30. package/dist/code/highlight.js +0 -62
  31. package/dist/code/line-numbers.js +0 -94
  32. package/dist/constants.js +0 -11
  33. package/dist/languages/basic.js +0 -30
  34. package/dist/languages/curl.js +0 -86
  35. package/dist/languages/json-yaml.js +0 -9
  36. package/dist/languages/standard.js +0 -115
  37. package/dist/markdown/markdown.js +0 -162
  38. package/dist/rehype-alert/rehype-alert.js +0 -102
  39. package/dist/rehype-highlight/rehype-highlight.js +0 -98
@@ -0,0 +1,74 @@
1
+ import { t as visit } from "./lib2.js";
2
+ //#region src/rehype-alert/rehype-alert.ts
3
+ var ALERT_TYPES = [
4
+ "note",
5
+ "tip",
6
+ "important",
7
+ "warning",
8
+ "caution",
9
+ "success"
10
+ ];
11
+ function isWhitespace(node) {
12
+ return node.type === "text" && typeof node.value === "string" && /^\s*$/.test(node.value);
13
+ }
14
+ function rehypeAlert() {
15
+ return (tree) => {
16
+ visit(tree, "element", (node, index, parent) => {
17
+ if (node.tagName !== "blockquote" || typeof index !== "number" || !parent || parent.type !== "root") return;
18
+ const headIndex = node.children.findIndex((child) => !isWhitespace(child));
19
+ if (headIndex === -1) return;
20
+ const head = node.children[headIndex];
21
+ if (!head || head.type !== "element" || head.tagName !== "p") return;
22
+ const text = head.children[0];
23
+ if (!text || text.type !== "text" || !text.value.startsWith("[!")) return;
24
+ const end = text.value.indexOf("]");
25
+ if (end === -1) return;
26
+ const alertType = text.value.slice(2, end).toLowerCase();
27
+ if (!ALERT_TYPES.includes(alertType)) return;
28
+ if (end + 1 === text.value.length) {
29
+ const next = head.children[1];
30
+ if (next) {
31
+ if (next.type !== "element" || next.tagName !== "br") return;
32
+ if (!head.children[2]) return;
33
+ head.children = head.children.slice(2);
34
+ const node = head.children[0];
35
+ if (node && node.type === "text" && node.value.charAt(0) === "\n") node.value = node.value.slice(1);
36
+ } else {
37
+ const nextIndex = headIndex + 1 < node.children.length && isWhitespace(node.children[headIndex + 1]) ? headIndex + 2 : headIndex + 1;
38
+ if (nextIndex >= node.children.length || node.children[nextIndex]?.type !== "element") return;
39
+ node.children = node.children.slice(nextIndex);
40
+ }
41
+ } else if (text.value.charAt(end + 1) === "\n" && (end + 2 === text.value.length || !/^\s*$/.test(text.value.slice(end + 2)))) text.value = text.value.slice(end + 2);
42
+ else text.value = text.value.replace(/^\s*\[!.*?\]\s*/, "");
43
+ const contentChildren = [];
44
+ for (let i = headIndex; i < node.children.length; i++) {
45
+ const child = node.children[i];
46
+ if (child?.type === "element" && child.tagName === "p" && child.children) contentChildren.push(...child.children);
47
+ else contentChildren.push(child);
48
+ }
49
+ parent.children[index] = {
50
+ type: "element",
51
+ tagName: "div",
52
+ properties: { className: ["markdown-alert", `markdown-alert-${alertType}`] },
53
+ children: [{
54
+ type: "element",
55
+ tagName: "div",
56
+ properties: { className: ["markdown-alert-icon"] },
57
+ children: []
58
+ }, {
59
+ type: "element",
60
+ tagName: "div",
61
+ properties: { className: ["markdown-alert-content"] },
62
+ children: [{
63
+ type: "text",
64
+ value: " "
65
+ }, ...contentChildren]
66
+ }]
67
+ };
68
+ });
69
+ };
70
+ }
71
+ //#endregion
72
+ export { rehypeAlert as t };
73
+
74
+ //# sourceMappingURL=rehype-alert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rehype-alert.js","names":[],"sources":["../../src/rehype-alert/rehype-alert.ts"],"sourcesContent":["import type { Element } from 'hast'\nimport type { Root } from 'mdast'\nimport { visit } from 'unist-util-visit'\n\nconst ALERT_TYPES = ['note', 'tip', 'important', 'warning', 'caution', 'success'] as const\n\n// Simple whitespace check function\nfunction isWhitespace(node: any): boolean {\n return node.type === 'text' && typeof node.value === 'string' && /^\\s*$/.test(node.value)\n}\n\nexport function rehypeAlert() {\n return (tree: Root) => {\n visit(tree, 'element', (node: Element, index, parent: any) => {\n if (node.tagName !== 'blockquote' || typeof index !== 'number' || !parent || parent.type !== 'root') {\n return\n }\n\n // Find the first non-whitespace child\n const headIndex = node.children.findIndex((child) => !isWhitespace(child))\n if (headIndex === -1) {\n return\n }\n\n const head = node.children[headIndex]\n\n if (!head || head.type !== 'element' || head.tagName !== 'p') {\n return\n }\n\n const text = head.children[0]\n if (!text || text.type !== 'text' || !text.value.startsWith('[!')) {\n return\n }\n\n const end = text.value.indexOf(']')\n if (end === -1) {\n return\n }\n\n // Extract the alert type\n const alertType = text.value.slice(2, end).toLowerCase() as (typeof ALERT_TYPES)[number]\n if (!ALERT_TYPES.includes(alertType)) {\n return\n }\n\n // Remove the blockquote if it's empty\n if (end + 1 === text.value.length) {\n const next = head.children[1]\n if (next) {\n if (next.type !== 'element' || next.tagName !== 'br') {\n return\n }\n if (!head.children[2]) {\n return\n }\n head.children = head.children.slice(2)\n const node = head.children[0]\n if (node && node.type === 'text' && node.value.charAt(0) === '\\n') {\n node.value = node.value.slice(1)\n }\n } else {\n const skipped = headIndex + 1 < node.children.length && isWhitespace(node.children[headIndex + 1])\n const nextIndex = skipped ? headIndex + 2 : headIndex + 1\n if (nextIndex >= node.children.length || node.children[nextIndex]?.type !== 'element') {\n return\n }\n\n node.children = node.children.slice(nextIndex)\n }\n } else if (\n text.value.charAt(end + 1) === '\\n' &&\n // Check if the next character is a newline or a non-whitespace character\n (end + 2 === text.value.length || !/^\\s*$/.test(text.value.slice(end + 2)))\n ) {\n text.value = text.value.slice(end + 2)\n } else {\n // Remove the alert marker if it's not followed by a newline or a non-whitespace character\n text.value = text.value.replace(/^\\s*\\[!.*?\\]\\s*/, '')\n }\n\n // Extract content from paragraphs to avoid wrapping in <p> tags\n const contentChildren = []\n for (let i = headIndex; i < node.children.length; i++) {\n const child = node.children[i]\n if (child?.type === 'element' && child.tagName === 'p' && child.children) {\n contentChildren.push(...child.children)\n } else {\n contentChildren.push(child)\n }\n }\n\n // Replace the blockquote with a div containing the alert\n parent.children[index] = {\n type: 'element',\n tagName: 'div',\n properties: { className: ['markdown-alert', `markdown-alert-${alertType}`] },\n children: [\n {\n type: 'element',\n tagName: 'div',\n properties: { className: ['markdown-alert-icon'] },\n children: [],\n },\n {\n type: 'element',\n tagName: 'div',\n properties: { className: ['markdown-alert-content'] },\n children: [{ type: 'text', value: ' ' }, ...contentChildren],\n },\n ],\n }\n })\n }\n}\n"],"mappings":";;AAIA,IAAM,cAAc;CAAC;CAAQ;CAAO;CAAa;CAAW;CAAW;CAAU;AAGjF,SAAS,aAAa,MAAoB;AACxC,QAAO,KAAK,SAAS,UAAU,OAAO,KAAK,UAAU,YAAY,QAAQ,KAAK,KAAK,MAAM;;AAG3F,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