@stream-mdx/core 0.1.0 → 0.2.0
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/CHANGELOG.md +6 -0
- package/README.md +6 -0
- package/dist/code-highlighting.cjs +20 -0
- package/dist/code-highlighting.d.cts +9 -1
- package/dist/code-highlighting.d.ts +9 -1
- package/dist/code-highlighting.mjs +18 -0
- package/dist/index.cjs +354 -149
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +352 -149
- package/dist/mixed-content.cjs +14 -0
- package/dist/mixed-content.d.cts +3 -1
- package/dist/mixed-content.d.ts +3 -1
- package/dist/mixed-content.mjs +14 -0
- package/dist/perf/patch-coalescing.cjs +58 -1
- package/dist/perf/patch-coalescing.mjs +58 -1
- package/dist/types.d.cts +64 -1
- package/dist/types.d.ts +64 -1
- package/dist/utils.cjs +16 -6
- package/dist/utils.mjs +16 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -41,3 +41,9 @@ export function makeConfig(overrides?: Partial<typeof DEFAULT_BACKPRESSURE_CONFI
|
|
|
41
41
|
|
|
42
42
|
- API reference: `docs/PUBLIC_API.md`
|
|
43
43
|
- Security model: `docs/SECURITY_MODEL.md`
|
|
44
|
+
|
|
45
|
+
## Related packages
|
|
46
|
+
|
|
47
|
+
- `@stream-mdx/react` for the React renderer
|
|
48
|
+
- `@stream-mdx/worker` for hosted worker bundles
|
|
49
|
+
- `@stream-mdx/mermaid` for Mermaid diagram rendering (optional)
|
|
@@ -24,6 +24,8 @@ __export(code_highlighting_exports, {
|
|
|
24
24
|
extractCodeLines: () => extractCodeLines,
|
|
25
25
|
extractCodeWrapperAttributes: () => extractCodeWrapperAttributes,
|
|
26
26
|
extractHighlightedLines: () => extractHighlightedLines,
|
|
27
|
+
getDefaultCodeWrapperAttributes: () => getDefaultCodeWrapperAttributes,
|
|
28
|
+
normalizeHighlightedLines: () => normalizeHighlightedLines,
|
|
27
29
|
stripCodeFence: () => stripCodeFence
|
|
28
30
|
});
|
|
29
31
|
module.exports = __toCommonJS(code_highlighting_exports);
|
|
@@ -150,6 +152,22 @@ function manualExtractHighlightedLines(html, fallbackLength) {
|
|
|
150
152
|
}
|
|
151
153
|
return normalizeHighlightedLines(lines, fallbackLength);
|
|
152
154
|
}
|
|
155
|
+
function getDefaultCodeWrapperAttributes(lang, themes = { dark: "github-dark", light: "github-light" }) {
|
|
156
|
+
const language = lang && typeof lang === "string" && lang.length > 0 ? lang : "text";
|
|
157
|
+
const themeLabel = `${themes.dark} ${themes.light}`;
|
|
158
|
+
return {
|
|
159
|
+
preAttrs: {
|
|
160
|
+
class: `shiki shiki-themes ${themeLabel}`,
|
|
161
|
+
"data-language": language,
|
|
162
|
+
style: "--shiki-dark-bg: transparent; --shiki-light-bg: transparent"
|
|
163
|
+
},
|
|
164
|
+
codeAttrs: {
|
|
165
|
+
"data-language": language,
|
|
166
|
+
"data-theme": themeLabel,
|
|
167
|
+
style: "display: grid;"
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
153
171
|
function dedentIndentedCode(raw) {
|
|
154
172
|
if (!raw) return "";
|
|
155
173
|
const normalized = normalizeNewlines(raw);
|
|
@@ -215,5 +233,7 @@ function filterAllowedAttributes(attrs) {
|
|
|
215
233
|
extractCodeLines,
|
|
216
234
|
extractCodeWrapperAttributes,
|
|
217
235
|
extractHighlightedLines,
|
|
236
|
+
getDefaultCodeWrapperAttributes,
|
|
237
|
+
normalizeHighlightedLines,
|
|
218
238
|
stripCodeFence
|
|
219
239
|
});
|
|
@@ -5,6 +5,14 @@ declare function stripCodeFence(raw: string): {
|
|
|
5
5
|
hadFence: boolean;
|
|
6
6
|
};
|
|
7
7
|
declare function extractHighlightedLines(html: string, fallbackLength: number): HighlightedLine[];
|
|
8
|
+
declare function normalizeHighlightedLines(lines: HighlightedLine[], fallbackLength: number): HighlightedLine[];
|
|
9
|
+
declare function getDefaultCodeWrapperAttributes(lang?: string, themes?: {
|
|
10
|
+
dark: string;
|
|
11
|
+
light: string;
|
|
12
|
+
}): {
|
|
13
|
+
preAttrs: Record<string, string>;
|
|
14
|
+
codeAttrs: Record<string, string>;
|
|
15
|
+
};
|
|
8
16
|
declare function dedentIndentedCode(raw: string): string;
|
|
9
17
|
declare function extractCodeLines(raw: string): string[];
|
|
10
18
|
declare function extractCodeWrapperAttributes(html: string): {
|
|
@@ -12,4 +20,4 @@ declare function extractCodeWrapperAttributes(html: string): {
|
|
|
12
20
|
codeAttrs?: Record<string, string>;
|
|
13
21
|
};
|
|
14
22
|
|
|
15
|
-
export { type HighlightedLine, dedentIndentedCode, extractCodeLines, extractCodeWrapperAttributes, extractHighlightedLines, stripCodeFence };
|
|
23
|
+
export { type HighlightedLine, dedentIndentedCode, extractCodeLines, extractCodeWrapperAttributes, extractHighlightedLines, getDefaultCodeWrapperAttributes, normalizeHighlightedLines, stripCodeFence };
|
|
@@ -5,6 +5,14 @@ declare function stripCodeFence(raw: string): {
|
|
|
5
5
|
hadFence: boolean;
|
|
6
6
|
};
|
|
7
7
|
declare function extractHighlightedLines(html: string, fallbackLength: number): HighlightedLine[];
|
|
8
|
+
declare function normalizeHighlightedLines(lines: HighlightedLine[], fallbackLength: number): HighlightedLine[];
|
|
9
|
+
declare function getDefaultCodeWrapperAttributes(lang?: string, themes?: {
|
|
10
|
+
dark: string;
|
|
11
|
+
light: string;
|
|
12
|
+
}): {
|
|
13
|
+
preAttrs: Record<string, string>;
|
|
14
|
+
codeAttrs: Record<string, string>;
|
|
15
|
+
};
|
|
8
16
|
declare function dedentIndentedCode(raw: string): string;
|
|
9
17
|
declare function extractCodeLines(raw: string): string[];
|
|
10
18
|
declare function extractCodeWrapperAttributes(html: string): {
|
|
@@ -12,4 +20,4 @@ declare function extractCodeWrapperAttributes(html: string): {
|
|
|
12
20
|
codeAttrs?: Record<string, string>;
|
|
13
21
|
};
|
|
14
22
|
|
|
15
|
-
export { type HighlightedLine, dedentIndentedCode, extractCodeLines, extractCodeWrapperAttributes, extractHighlightedLines, stripCodeFence };
|
|
23
|
+
export { type HighlightedLine, dedentIndentedCode, extractCodeLines, extractCodeWrapperAttributes, extractHighlightedLines, getDefaultCodeWrapperAttributes, normalizeHighlightedLines, stripCodeFence };
|
|
@@ -122,6 +122,22 @@ function manualExtractHighlightedLines(html, fallbackLength) {
|
|
|
122
122
|
}
|
|
123
123
|
return normalizeHighlightedLines(lines, fallbackLength);
|
|
124
124
|
}
|
|
125
|
+
function getDefaultCodeWrapperAttributes(lang, themes = { dark: "github-dark", light: "github-light" }) {
|
|
126
|
+
const language = lang && typeof lang === "string" && lang.length > 0 ? lang : "text";
|
|
127
|
+
const themeLabel = `${themes.dark} ${themes.light}`;
|
|
128
|
+
return {
|
|
129
|
+
preAttrs: {
|
|
130
|
+
class: `shiki shiki-themes ${themeLabel}`,
|
|
131
|
+
"data-language": language,
|
|
132
|
+
style: "--shiki-dark-bg: transparent; --shiki-light-bg: transparent"
|
|
133
|
+
},
|
|
134
|
+
codeAttrs: {
|
|
135
|
+
"data-language": language,
|
|
136
|
+
"data-theme": themeLabel,
|
|
137
|
+
style: "display: grid;"
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
125
141
|
function dedentIndentedCode(raw) {
|
|
126
142
|
if (!raw) return "";
|
|
127
143
|
const normalized = normalizeNewlines(raw);
|
|
@@ -186,5 +202,7 @@ export {
|
|
|
186
202
|
extractCodeLines,
|
|
187
203
|
extractCodeWrapperAttributes,
|
|
188
204
|
extractHighlightedLines,
|
|
205
|
+
getDefaultCodeWrapperAttributes,
|
|
206
|
+
normalizeHighlightedLines,
|
|
189
207
|
stripCodeFence
|
|
190
208
|
};
|