@san-siva/blogkit-md 0.2.7 → 0.2.9

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 CHANGED
@@ -78,6 +78,17 @@ var consumeNode = (nodes, index, sections, section) => {
78
78
  const headingLevel = node.depth;
79
79
  const isIncrementingHeading = headingLevel > section.headingLevel;
80
80
  if (isIncrementingHeading) {
81
+ if (section.nodes.length > 0) {
82
+ const subSection = {
83
+ title: "",
84
+ headingLevel: section.headingLevel,
85
+ nodes: section.nodes,
86
+ subsections: [],
87
+ previousSection: section
88
+ };
89
+ section.subsections.push(subSection);
90
+ section.nodes = [];
91
+ }
81
92
  const subsection = {
82
93
  title: extractText(node.children),
83
94
  headingLevel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@san-siva/blogkit-md",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Converts markdown files into JSX blog posts for Blogkit",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
@@ -21,8 +21,8 @@
21
21
  "fix": "eslint . --config eslint.config.ts --fix"
22
22
  },
23
23
  "dependencies": {
24
- "@san-siva/blogkit": "^1.1.21",
25
- "@san-siva/stylekit": "^1.0.11",
24
+ "@san-siva/blogkit": "^1.1.23",
25
+ "@san-siva/stylekit": "^1.0.12",
26
26
  "next": "^16.0.10",
27
27
  "react": "^19.0.0",
28
28
  "react-dom": "^19.0.0",
@@ -39,7 +39,6 @@
39
39
  "@types/eslint": "^9.6.1",
40
40
  "@types/eslint__js": "^9.14.0",
41
41
  "@types/mdast": "^4.0.4",
42
- "tsup": "^8.0.0",
43
42
  "@types/node": "^22",
44
43
  "@types/react": "^19",
45
44
  "@types/react-dom": "^19",
@@ -57,6 +56,7 @@
57
56
  "eslint-plugin-unicorn": "^62.0.0",
58
57
  "jiti": "^2.0.0",
59
58
  "prettier": "^3.0.0",
59
+ "tsup": "^8.0.0",
60
60
  "typescript": "^5.0.0",
61
61
  "typescript-eslint": "^8.0.0",
62
62
  "vitest": "^4.1.0"
@@ -59,6 +59,27 @@ describe('groupSections', () => {
59
59
  });
60
60
  });
61
61
 
62
+ describe('content before a deeper heading', () => {
63
+ it('moves content preceding a subsection into its own untitled subsection', () => {
64
+ const result = sections('## Parent\n\nsome text\n\n### Child');
65
+ expect(result).toHaveLength(1);
66
+ expect(result[0].title).toBe('Parent');
67
+ expect(result[0].nodes).toHaveLength(0);
68
+ expect(result[0].subsections).toHaveLength(2);
69
+ expect(result[0].subsections[0].title).toBe('');
70
+ expect(result[0].subsections[0].nodes).toHaveLength(1);
71
+ expect(result[0].subsections[1].title).toBe('Child');
72
+ });
73
+
74
+ it('skips the untitled subsection when no content precedes the deeper heading', () => {
75
+ const result = sections('## Parent\n\n### Child');
76
+ expect(result).toHaveLength(1);
77
+ expect(result[0].title).toBe('Parent');
78
+ expect(result[0].subsections).toHaveLength(1);
79
+ expect(result[0].subsections[0].title).toBe('Child');
80
+ });
81
+ });
82
+
62
83
  describe('nested sections (H3)', () => {
63
84
  it('nests H3 under a preceding H2', () => {
64
85
  const result = sections('## Parent\n\n### Child');
@@ -30,6 +30,22 @@ const consumeNode = (
30
30
  const headingLevel = node.depth;
31
31
  const isIncrementingHeading = headingLevel > section.headingLevel;
32
32
  if (isIncrementingHeading) {
33
+ // If a section has content nodes before a deeper heading, wrap those
34
+ // nodes in an untitled subsection so they aren't lost.
35
+ // e.g. ## Parent > "intro text" > ### Child
36
+ // becomes: Parent { subsections: [{ title: '', nodes: [...] }, Child] }
37
+ // instead of: Parent { nodes: [...], subsections: [Child] }
38
+ if (section.nodes.length > 0) {
39
+ const subSection: Section = {
40
+ title: '',
41
+ headingLevel: section.headingLevel,
42
+ nodes: section.nodes,
43
+ subsections: [],
44
+ previousSection: section,
45
+ };
46
+ section.subsections.push(subSection);
47
+ section.nodes = [];
48
+ }
33
49
  const subsection: Section = {
34
50
  title: extractText(node.children),
35
51
  headingLevel,