@san-siva/blogkit-md 0.2.9 → 0.3.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/dist/index.js +27 -10
- package/package.json +2 -2
- package/src/utils/renderMarkdown.tsx +28 -7
package/dist/index.js
CHANGED
|
@@ -51,6 +51,7 @@ var parseMarkdown = (content) => {
|
|
|
51
51
|
import {
|
|
52
52
|
BlogSection,
|
|
53
53
|
Callout,
|
|
54
|
+
CheckList,
|
|
54
55
|
CodeBlock,
|
|
55
56
|
Mermaid,
|
|
56
57
|
Table
|
|
@@ -216,7 +217,8 @@ function renderNode({
|
|
|
216
217
|
key,
|
|
217
218
|
nextNode,
|
|
218
219
|
inList = false,
|
|
219
|
-
inCallout = false
|
|
220
|
+
inCallout = false,
|
|
221
|
+
counters
|
|
220
222
|
}) {
|
|
221
223
|
var _a;
|
|
222
224
|
switch (node.type) {
|
|
@@ -231,10 +233,11 @@ function renderNode({
|
|
|
231
233
|
}
|
|
232
234
|
case "code": {
|
|
233
235
|
if (node.lang === "mermaid") {
|
|
236
|
+
const mermaidId = counters.mermaid++;
|
|
234
237
|
return /* @__PURE__ */ jsx2(
|
|
235
238
|
Mermaid,
|
|
236
239
|
{
|
|
237
|
-
id: `mermaid-${
|
|
240
|
+
id: `mermaid-${mermaidId}`,
|
|
238
241
|
code: node.value,
|
|
239
242
|
hasMarginUp: true,
|
|
240
243
|
hasMarginDown: true
|
|
@@ -318,17 +321,30 @@ function renderNode({
|
|
|
318
321
|
node: child,
|
|
319
322
|
key: index,
|
|
320
323
|
nextNode: strippedChildren[index + 1],
|
|
321
|
-
inCallout: true
|
|
324
|
+
inCallout: true,
|
|
325
|
+
counters
|
|
322
326
|
})
|
|
323
327
|
) }, key);
|
|
324
328
|
}
|
|
325
329
|
case "list": {
|
|
330
|
+
const isTaskList = node.children.every((item) => item.checked !== null && item.checked !== void 0);
|
|
331
|
+
if (isTaskList) {
|
|
332
|
+
const items = node.children.map((item, index) => ({
|
|
333
|
+
id: String(index),
|
|
334
|
+
isChecked: item.checked === true,
|
|
335
|
+
children: item.children.map(
|
|
336
|
+
(child, childIndex) => renderNode({ node: child, key: childIndex, inList: true, counters })
|
|
337
|
+
)
|
|
338
|
+
}));
|
|
339
|
+
return /* @__PURE__ */ jsx2(CheckList, { items, hasMarginUp: true, hasMarginDown: true }, key);
|
|
340
|
+
}
|
|
326
341
|
const Tag = node.ordered ? "ol" : "ul";
|
|
327
342
|
return /* @__PURE__ */ jsx2(Tag, { className: styles2["margin-bottom--2"], children: node.children.map((item, index) => /* @__PURE__ */ jsx2("li", { children: item.children.map(
|
|
328
343
|
(child, index2) => renderNode({
|
|
329
344
|
node: child,
|
|
330
345
|
key: index2,
|
|
331
|
-
inList: true
|
|
346
|
+
inList: true,
|
|
347
|
+
counters
|
|
332
348
|
})
|
|
333
349
|
) }, index)) }, key);
|
|
334
350
|
}
|
|
@@ -337,24 +353,25 @@ function renderNode({
|
|
|
337
353
|
}
|
|
338
354
|
}
|
|
339
355
|
}
|
|
340
|
-
function renderNodes(nodes) {
|
|
356
|
+
function renderNodes(nodes, counters) {
|
|
341
357
|
return nodes.map(
|
|
342
|
-
(node, index) => renderNode({ node, key: index, nextNode: nodes[index + 1] })
|
|
358
|
+
(node, index) => renderNode({ node, key: index, nextNode: nodes[index + 1], counters })
|
|
343
359
|
);
|
|
344
360
|
}
|
|
345
|
-
function renderSection(section, key = -1) {
|
|
361
|
+
function renderSection(section, counters, key = -1) {
|
|
346
362
|
var _a;
|
|
347
363
|
return /* @__PURE__ */ jsxs(BlogSection, { title: (_a = section == null ? void 0 : section.title) != null ? _a : "", children: [
|
|
348
|
-
renderNodes(section.nodes),
|
|
364
|
+
renderNodes(section.nodes, counters),
|
|
349
365
|
section.subsections.map(
|
|
350
|
-
(subsection, index) => renderSection(subsection, index)
|
|
366
|
+
(subsection, index) => renderSection(subsection, counters, index)
|
|
351
367
|
)
|
|
352
368
|
] }, key);
|
|
353
369
|
}
|
|
354
370
|
var renderMarkdownAst = (ast) => {
|
|
371
|
+
const counters = { mermaid: 0 };
|
|
355
372
|
const grouped = groupSections(ast.children);
|
|
356
373
|
return {
|
|
357
|
-
sections: grouped.map((section, index) => renderSection(section, index))
|
|
374
|
+
sections: grouped.map((section, index) => renderSection(section, counters, index))
|
|
358
375
|
};
|
|
359
376
|
};
|
|
360
377
|
var MarkdownSections = ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@san-siva/blogkit-md",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Converts markdown files into JSX blog posts for Blogkit",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"fix": "eslint . --config eslint.config.ts --fix"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@san-siva/blogkit": "^1.1.
|
|
24
|
+
"@san-siva/blogkit": "^1.1.24",
|
|
25
25
|
"@san-siva/stylekit": "^1.0.12",
|
|
26
26
|
"next": "^16.0.10",
|
|
27
27
|
"react": "^19.0.0",
|
|
@@ -3,6 +3,8 @@ import React from 'react';
|
|
|
3
3
|
import {
|
|
4
4
|
BlogSection,
|
|
5
5
|
Callout,
|
|
6
|
+
CheckList,
|
|
7
|
+
type CheckListItem,
|
|
6
8
|
CodeBlock,
|
|
7
9
|
Mermaid,
|
|
8
10
|
Table,
|
|
@@ -15,18 +17,22 @@ import { renderPhrasingContent } from './renderPhrasingContent';
|
|
|
15
17
|
|
|
16
18
|
import styles from '@san-siva/stylekit/styles/index.module.scss';
|
|
17
19
|
|
|
20
|
+
type Counters = { mermaid: number };
|
|
21
|
+
|
|
18
22
|
function renderNode({
|
|
19
23
|
node,
|
|
20
24
|
key,
|
|
21
25
|
nextNode,
|
|
22
26
|
inList = false,
|
|
23
27
|
inCallout = false,
|
|
28
|
+
counters,
|
|
24
29
|
}: {
|
|
25
30
|
node: RootContent;
|
|
26
31
|
key: number;
|
|
27
32
|
nextNode?: RootContent;
|
|
28
33
|
inList?: boolean;
|
|
29
34
|
inCallout?: boolean;
|
|
35
|
+
counters: Counters;
|
|
30
36
|
}): React.ReactNode {
|
|
31
37
|
switch (node.type) {
|
|
32
38
|
case 'paragraph': {
|
|
@@ -51,10 +57,11 @@ function renderNode({
|
|
|
51
57
|
}
|
|
52
58
|
case 'code': {
|
|
53
59
|
if (node.lang === 'mermaid') {
|
|
60
|
+
const mermaidId = counters.mermaid++;
|
|
54
61
|
return (
|
|
55
62
|
<Mermaid
|
|
56
63
|
key={key}
|
|
57
|
-
id={`mermaid-${
|
|
64
|
+
id={`mermaid-${mermaidId}`}
|
|
58
65
|
code={node.value}
|
|
59
66
|
hasMarginUp
|
|
60
67
|
hasMarginDown
|
|
@@ -148,12 +155,24 @@ function renderNode({
|
|
|
148
155
|
key: index,
|
|
149
156
|
nextNode: strippedChildren[index + 1],
|
|
150
157
|
inCallout: true,
|
|
158
|
+
counters,
|
|
151
159
|
})
|
|
152
160
|
)}
|
|
153
161
|
</Callout>
|
|
154
162
|
);
|
|
155
163
|
}
|
|
156
164
|
case 'list': {
|
|
165
|
+
const isTaskList = node.children.every(item => item.checked !== null && item.checked !== undefined);
|
|
166
|
+
if (isTaskList) {
|
|
167
|
+
const items: CheckListItem[] = node.children.map((item, index) => ({
|
|
168
|
+
id: String(index),
|
|
169
|
+
isChecked: item.checked === true,
|
|
170
|
+
children: item.children.map((child, childIndex) =>
|
|
171
|
+
renderNode({ node: child as RootContent, key: childIndex, inList: true, counters })
|
|
172
|
+
),
|
|
173
|
+
}));
|
|
174
|
+
return <CheckList key={key} items={items} hasMarginUp hasMarginDown />;
|
|
175
|
+
}
|
|
157
176
|
const Tag = node.ordered ? 'ol' : 'ul';
|
|
158
177
|
return (
|
|
159
178
|
<Tag key={key} className={styles['margin-bottom--2']}>
|
|
@@ -164,6 +183,7 @@ function renderNode({
|
|
|
164
183
|
node: child as RootContent,
|
|
165
184
|
key: index,
|
|
166
185
|
inList: true,
|
|
186
|
+
counters,
|
|
167
187
|
})
|
|
168
188
|
)}
|
|
169
189
|
</li>
|
|
@@ -177,18 +197,18 @@ function renderNode({
|
|
|
177
197
|
}
|
|
178
198
|
}
|
|
179
199
|
|
|
180
|
-
function renderNodes(nodes: RootContent[]): React.ReactNode[] {
|
|
200
|
+
function renderNodes(nodes: RootContent[], counters: Counters): React.ReactNode[] {
|
|
181
201
|
return nodes.map((node, index) =>
|
|
182
|
-
renderNode({ node, key: index, nextNode: nodes[index + 1] })
|
|
202
|
+
renderNode({ node, key: index, nextNode: nodes[index + 1], counters })
|
|
183
203
|
);
|
|
184
204
|
}
|
|
185
205
|
|
|
186
|
-
function renderSection(section: Section, key = -1): React.ReactNode {
|
|
206
|
+
function renderSection(section: Section, counters: Counters, key = -1): React.ReactNode {
|
|
187
207
|
return (
|
|
188
208
|
<BlogSection key={key} title={section?.title ?? ''}>
|
|
189
|
-
{renderNodes(section.nodes)}
|
|
209
|
+
{renderNodes(section.nodes, counters)}
|
|
190
210
|
{section.subsections.map((subsection, index) =>
|
|
191
|
-
renderSection(subsection, index)
|
|
211
|
+
renderSection(subsection, counters, index)
|
|
192
212
|
)}
|
|
193
213
|
</BlogSection>
|
|
194
214
|
);
|
|
@@ -199,9 +219,10 @@ export type RenderedMarkdown = {
|
|
|
199
219
|
};
|
|
200
220
|
|
|
201
221
|
export const renderMarkdownAst = (ast: Root): RenderedMarkdown => {
|
|
222
|
+
const counters: Counters = { mermaid: 0 };
|
|
202
223
|
const grouped = groupSections(ast.children);
|
|
203
224
|
return {
|
|
204
|
-
sections: grouped.map((section, index) => renderSection(section, index)),
|
|
225
|
+
sections: grouped.map((section, index) => renderSection(section, counters, index)),
|
|
205
226
|
};
|
|
206
227
|
};
|
|
207
228
|
|