@caseparts-org/caseblocks 0.0.258 → 0.0.259

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.
@@ -2,3 +2,5 @@ export { Markdown } from './molecules/Markdown/Markdown';
2
2
  export type { MarkdownProps } from './molecules/Markdown/Markdown';
3
3
  export { usePreprocessedMarkdown } from './molecules/Markdown/usePreprocessedMarkdown';
4
4
  export type { LinkTarget, ValidateToken, BatchValidateTokens } from './molecules/Markdown/usePreprocessedMarkdown';
5
+ export { extractAdmonitions } from './molecules/Markdown/remarkAdmonition';
6
+ export type { MarkdownAdmonition } from './molecules/Markdown/remarkAdmonition';
@@ -1,6 +1,8 @@
1
1
  import { Markdown as e } from "./molecules/Markdown/Markdown.js";
2
- import { usePreprocessedMarkdown as p } from "./molecules/Markdown/usePreprocessedMarkdown.js";
2
+ import { usePreprocessedMarkdown as d } from "./molecules/Markdown/usePreprocessedMarkdown.js";
3
+ import { extractAdmonitions as n } from "./molecules/Markdown/remarkAdmonition.js";
3
4
  export {
4
5
  e as Markdown,
5
- p as usePreprocessedMarkdown
6
+ n as extractAdmonitions,
7
+ d as usePreprocessedMarkdown
6
8
  };
@@ -11,5 +11,16 @@ type MarkdownRoot = {
11
11
  type: "root";
12
12
  children: MarkdownNode[];
13
13
  };
14
+ type KnownAdmonitionVariant = "note" | "tip" | "attention" | "caution" | "warning";
15
+ type MarkdownAdmonitionVariant = KnownAdmonitionVariant | "upsell" | "unknown";
16
+ export type MarkdownAdmonition = {
17
+ type: string;
18
+ variant: MarkdownAdmonitionVariant;
19
+ title?: string;
20
+ icon?: string;
21
+ content: string;
22
+ };
23
+ /** Extracts fully formed triple-colon admonitions from a Markdown description. */
24
+ export declare const extractAdmonitions: (description: string) => MarkdownAdmonition[];
14
25
  export declare function remarkAdmonition(): (tree: MarkdownRoot) => void;
15
26
  export {};
@@ -1,9 +1,15 @@
1
- const y = /^[a-z][a-z0-9_-]*/, v = /^\s*(?:[a-z][a-z0-9_-]*="(?:[^"\\]|\\.)*"(?:[ \t]+[a-z][a-z0-9_-]*="(?:[^"\\]|\\.)*")*)?\s*$/, x = /([a-z][a-z0-9_-]*)="((?:[^"\\]|\\.)*)"/g, h = /^:::[ \t]*$/, A = /* @__PURE__ */ new Set(["note", "tip", "attention", "caution", "warning"]), f = (t) => t.type === "text" && typeof t.value == "string" ? t.value : t.type === "break" ? `
2
- ` : (t.type === "inlineCode" || t.type === "html") && typeof t.value == "string" ? t.value : Array.isArray(t.children) && t.children.length > 0 ? t.children.map(f).join("") : "", p = (t) => {
1
+ const v = /^[a-z][a-z0-9_-]*/, A = /^\s*(?:[a-z][a-z0-9_-]*="(?:[^"\\]|\\.)*"(?:[ \t]+[a-z][a-z0-9_-]*="(?:[^"\\]|\\.)*")*)?\s*$/, b = /([a-z][a-z0-9_-]*)="((?:[^"\\]|\\.)*)"/g, f = /^:::[ \t]*$/, I = /* @__PURE__ */ new Set([
2
+ "note",
3
+ "tip",
4
+ "attention",
5
+ "caution",
6
+ "warning"
7
+ ]), d = (t) => I.has(t), T = (t) => t === "upsell" ? "upsell" : d(t) ? t : "unknown", h = (t) => t.type === "text" && typeof t.value == "string" ? t.value : t.type === "break" ? `
8
+ ` : (t.type === "inlineCode" || t.type === "html") && typeof t.value == "string" ? t.value : Array.isArray(t.children) && t.children.length > 0 ? t.children.map(h).join("") : "", p = (t) => {
3
9
  if (t.type !== "paragraph" || !t.children || t.children.length === 0) return null;
4
- const n = t.children.map(f).join("");
10
+ const n = t.children.map(h).join("");
5
11
  return n.length > 0 ? n : null;
6
- }, T = (t) => {
12
+ }, E = (t) => {
7
13
  if (t.type !== "paragraph" || !Array.isArray(t.children)) return [];
8
14
  const n = [[]], r = () => {
9
15
  n.push([]);
@@ -18,23 +24,23 @@ const y = /^[a-z][a-z0-9_-]*/, v = /^\s*(?:[a-z][a-z0-9_-]*="(?:[^"\\]|\\.)*"(?:
18
24
  if (e.type === "text" && typeof e.value == "string" && e.value.includes(`
19
25
  `)) {
20
26
  const s = e.value.split(/\r?\n/);
21
- s.forEach((l, c) => {
22
- l.length > 0 && i({ type: "text", value: l }), c < s.length - 1 && r();
27
+ s.forEach((o, l) => {
28
+ o.length > 0 && i({ type: "text", value: o }), l < s.length - 1 && r();
23
29
  });
24
30
  continue;
25
31
  }
26
32
  i(e);
27
33
  }
28
34
  return n;
29
- }, b = (t) => t.replace(/\\(.)/g, "$1"), E = (t) => {
30
- if (!v.test(t)) return null;
35
+ }, N = (t) => t.replace(/\\(.)/g, "$1"), _ = (t) => {
36
+ if (!A.test(t)) return null;
31
37
  const n = {};
32
- for (const r of t.matchAll(x)) {
33
- const i = r[1], e = b(r[2]);
38
+ for (const r of t.matchAll(b)) {
39
+ const i = r[1], e = N(r[2]);
34
40
  (i === "icon" || i === "title") && (n[i] = e);
35
41
  }
36
42
  return n;
37
- }, I = (t) => {
43
+ }, z = (t) => {
38
44
  let n = !1, r = !1;
39
45
  for (let i = 1; i < t.length; i += 1) {
40
46
  const e = t[i];
@@ -54,67 +60,85 @@ const y = /^[a-z][a-z0-9_-]*/, v = /^\s*(?:[a-z][a-z0-9_-]*="(?:[^"\\]|\\.)*"(?:
54
60
  return i;
55
61
  }
56
62
  return -1;
57
- }, N = (t) => {
63
+ }, g = (t) => {
58
64
  if (!t.startsWith(":::")) return null;
59
65
  let n = t.slice(3);
60
- const r = n.match(y);
66
+ const r = n.match(v);
61
67
  if (!r) return null;
62
68
  const i = r[0];
63
69
  n = n.slice(i.length);
64
70
  let e;
65
71
  if (n.startsWith("[")) {
66
- const l = n.indexOf("]");
67
- if (l < 0) return null;
68
- e = n.slice(1, l), n = n.slice(l + 1);
72
+ const o = n.indexOf("]");
73
+ if (o < 0) return null;
74
+ e = n.slice(1, o), n = n.slice(o + 1);
69
75
  }
70
76
  let s = {};
71
77
  if (n.startsWith("{")) {
72
- const l = I(n);
73
- if (l < 0) return null;
74
- const c = E(n.slice(1, l));
75
- if (!c) return null;
76
- s = c, n = n.slice(l + 1);
78
+ const o = z(n);
79
+ if (o < 0) return null;
80
+ const l = _(n.slice(1, o));
81
+ if (!l) return null;
82
+ s = l, n = n.slice(o + 1);
77
83
  }
78
84
  return /^[ \t]*$/.test(n) ? { name: i, title: e, attributes: s } : null;
79
- }, _ = (t, n) => {
85
+ }, w = (t) => {
86
+ const n = t.split(/\r?\n/), r = [];
87
+ for (let i = 0; i < n.length; i += 1) {
88
+ const e = g(n[i]);
89
+ if (!e) continue;
90
+ const s = n.findIndex(
91
+ (o, l) => l > i && f.test(o)
92
+ );
93
+ s < 0 || (r.push({
94
+ type: e.name,
95
+ variant: T(e.name),
96
+ title: e.title ?? e.attributes.title,
97
+ icon: e.attributes.icon,
98
+ content: n.slice(i + 1, s).join(`
99
+ `)
100
+ }), i = s);
101
+ }
102
+ return r;
103
+ }, k = (t, n) => {
80
104
  for (let r = n; r < t.length; r += 1) {
81
105
  const i = p(t[r]);
82
- if (i && h.test(i))
106
+ if (i && f.test(i))
83
107
  return r;
84
108
  }
85
109
  return -1;
86
- }, z = (t, n) => {
87
- const r = T(t);
88
- return r.length ? r.slice(1, n).filter((i) => i.some((e) => f(e).trim().length > 0)).map((i) => ({
110
+ }, R = (t, n) => {
111
+ const r = E(t);
112
+ return r.length ? r.slice(1, n).filter((i) => i.some((e) => h(e).trim().length > 0)).map((i) => ({
89
113
  type: "paragraph",
90
114
  children: i
91
115
  })) : [];
92
116
  };
93
- function R() {
117
+ function C() {
94
118
  return (t) => {
95
119
  if (!(!t || t.type !== "root" || !Array.isArray(t.children)))
96
120
  for (let n = 0; n < t.children.length; n += 1) {
97
121
  const r = p(t.children[n]);
98
122
  if (!r) continue;
99
- const i = r.split(/\r?\n/), e = N(i[0] ?? "");
123
+ const i = r.split(/\r?\n/), e = g(i[0] ?? "");
100
124
  if (!e) continue;
101
- let s = [], l = 0;
125
+ let s = [], o = 0;
102
126
  if (i.length > 1) {
103
- const o = i.findIndex((u, m) => m > 0 && h.test(u));
104
- if (o < 0 || i.slice(o + 1).some((u) => u.trim().length > 0))
127
+ const c = i.findIndex((u, x) => x > 0 && f.test(u));
128
+ if (c < 0 || i.slice(c + 1).some((u) => u.trim().length > 0))
105
129
  continue;
106
- s = z(t.children[n], o), l = 1;
130
+ s = R(t.children[n], c), o = 1;
107
131
  } else {
108
- const o = _(t.children, n + 1);
109
- if (o < 0) continue;
110
- s = t.children.slice(n + 1, o), l = o - n + 1;
132
+ const c = k(t.children, n + 1);
133
+ if (c < 0) continue;
134
+ s = t.children.slice(n + 1, c), o = c - n + 1;
111
135
  }
112
- const c = e.title ?? e.attributes.title, d = A.has(e.name) ? e.name : "unknown", a = {
136
+ const l = e.title ?? e.attributes.title, m = d(e.name) ? e.name : "unknown", a = {
113
137
  "data-admonition": e.name,
114
- "data-admonition-variant": d
138
+ "data-admonition-variant": m
115
139
  };
116
- c !== void 0 && (a["data-admonition-title"] = c), e.attributes.icon !== void 0 && (a["data-admonition-icon"] = e.attributes.icon);
117
- const g = {
140
+ l !== void 0 && (a["data-admonition-title"] = l), e.attributes.icon !== void 0 && (a["data-admonition-icon"] = e.attributes.icon);
141
+ const y = {
118
142
  type: "admonition",
119
143
  data: {
120
144
  hName: "aside",
@@ -122,10 +146,11 @@ function R() {
122
146
  },
123
147
  children: s
124
148
  };
125
- t.children.splice(n, l, g);
149
+ t.children.splice(n, o, y);
126
150
  }
127
151
  };
128
152
  }
129
153
  export {
130
- R as remarkAdmonition
154
+ w as extractAdmonitions,
155
+ C as remarkAdmonition
131
156
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@caseparts-org/caseblocks",
3
3
  "private": false,
4
- "version": "0.0.258",
4
+ "version": "0.0.259",
5
5
  "type": "module",
6
6
  "module": "dist/main.js",
7
7
  "types": "dist/main.d.ts",