@stream-mdx/core 0.1.1 → 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.
@@ -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
  };