nx-json-parser 1.0.0 → 1.1.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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/parser.d.ts +22 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +191 -13
- package/dist/parser.js.map +1 -1
- package/dist/plugins/bullet-sections.d.ts.map +1 -1
- package/dist/plugins/bullet-sections.js +42 -72
- package/dist/plugins/bullet-sections.js.map +1 -1
- package/dist/plugins/detect-bullet-mode.d.ts +7 -0
- package/dist/plugins/detect-bullet-mode.d.ts.map +1 -0
- package/dist/plugins/detect-bullet-mode.js +126 -0
- package/dist/plugins/detect-bullet-mode.js.map +1 -0
- package/dist/remark-markdown-parser.d.ts +41 -0
- package/dist/remark-markdown-parser.d.ts.map +1 -0
- package/dist/remark-markdown-parser.js +294 -0
- package/dist/remark-markdown-parser.js.map +1 -0
- package/dist/types.d.ts +17 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/parser.ts +213 -15
- package/src/plugins/bullet-sections.ts +58 -83
- package/src/plugins/bullet-sections.ts.old +86 -0
- package/src/plugins/detect-bullet-mode.ts +161 -0
- package/src/remark-markdown-parser.ts +340 -0
- package/src/types.ts +22 -6
- package/test/bullet-mode.test.ts +99 -0
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAI7C;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAGpD"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC3C,MAAM,WAAW,GAAG,IAAI,eAAe,EAAE,CAAC;IAC1C,OAAO,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
import { MarkdownSection } from './types.js';
|
|
1
|
+
import { MarkdownSection, ParserOptions } from './types.js';
|
|
2
2
|
export declare class RemarkParser {
|
|
3
3
|
private processor;
|
|
4
|
+
private options;
|
|
5
|
+
constructor(options?: ParserOptions);
|
|
4
6
|
parse(markdown: string): MarkdownSection[];
|
|
7
|
+
/**
|
|
8
|
+
* Process content nodes into appropriate format
|
|
9
|
+
*/
|
|
5
10
|
private processContent;
|
|
11
|
+
/**
|
|
12
|
+
* Process a bullet list item as a section (Mode 2: SECTIONS)
|
|
13
|
+
*/
|
|
14
|
+
private processBulletAsSection;
|
|
15
|
+
/**
|
|
16
|
+
* Convert list to simple array of strings (Mode 1: ARRAY)
|
|
17
|
+
*/
|
|
18
|
+
private listToArray;
|
|
19
|
+
/**
|
|
20
|
+
* Convert table to array of objects
|
|
21
|
+
*/
|
|
6
22
|
private tableToArray;
|
|
23
|
+
/**
|
|
24
|
+
* Convert sections to object (utility method)
|
|
25
|
+
*/
|
|
26
|
+
sectionsToObject(sections: MarkdownSection[]): Record<string, any>;
|
|
27
|
+
private mergeAndPushSection;
|
|
7
28
|
}
|
|
8
29
|
//# sourceMappingURL=parser.d.ts.map
|
package/dist/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAc,aAAa,EAAE,MAAM,YAAY,CAAC;AAIxE,qBAAa,YAAY;IACrB,OAAO,CAAC,SAAS,CAEG;IAEpB,OAAO,CAAC,OAAO,CAA0B;gBAE7B,OAAO,GAAE,aAAkB;IAOvC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,EAAE;IAmF1C;;OAEG;IACH,OAAO,CAAC,cAAc;IA+BtB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAuE9B;;OAEG;IACH,OAAO,CAAC,WAAW;IAQnB;;OAEG;IACH,OAAO,CAAC,YAAY;IAoBpB;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAWlE,OAAO,CAAC,mBAAmB;CA0B9B"}
|
package/dist/parser.js
CHANGED
|
@@ -2,24 +2,44 @@ import { unified } from 'unified';
|
|
|
2
2
|
import remarkParse from 'remark-parse';
|
|
3
3
|
import remarkGfm from 'remark-gfm';
|
|
4
4
|
import { toString } from 'mdast-util-to-string';
|
|
5
|
-
import {
|
|
5
|
+
import { BulletMode } from './types.js';
|
|
6
|
+
import { detectBulletMode } from './plugins/detect-bullet-mode.js';
|
|
6
7
|
import { toCamelCase } from 'nx-helpers';
|
|
7
8
|
export class RemarkParser {
|
|
8
9
|
processor = unified()
|
|
9
10
|
.use(remarkParse)
|
|
10
|
-
.use(remarkGfm)
|
|
11
|
-
|
|
11
|
+
.use(remarkGfm);
|
|
12
|
+
options;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.options = {
|
|
15
|
+
bulletMode: options.bulletMode ?? BulletMode.AUTO,
|
|
16
|
+
debug: options.debug ?? false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
12
19
|
parse(markdown) {
|
|
13
20
|
const tree = this.processor.runSync(this.processor.parse(markdown));
|
|
21
|
+
// Detect bullet mode if AUTO
|
|
22
|
+
let bulletMode = this.options.bulletMode;
|
|
23
|
+
if (bulletMode === BulletMode.AUTO) {
|
|
24
|
+
const detection = detectBulletMode(tree);
|
|
25
|
+
bulletMode = detection.mode === 'sections' ? BulletMode.SECTIONS : BulletMode.ARRAY;
|
|
26
|
+
if (this.options.debug) {
|
|
27
|
+
console.log('🔍 Bullet Mode Detection:');
|
|
28
|
+
console.log(` Mode: ${detection.mode}`);
|
|
29
|
+
console.log(` Confidence: ${(detection.confidence * 100).toFixed(0)}%`);
|
|
30
|
+
console.log(` Reasons:`);
|
|
31
|
+
detection.reasons.forEach(r => console.log(` - ${r}`));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
14
34
|
const sections = [];
|
|
15
35
|
let currentSection = null;
|
|
16
36
|
let currentNodes = [];
|
|
17
37
|
const rootChildren = tree.children;
|
|
18
38
|
for (const node of rootChildren) {
|
|
19
39
|
if (node.type === 'heading') {
|
|
40
|
+
// Standard heading section (### Section)
|
|
20
41
|
if (currentSection) {
|
|
21
|
-
|
|
22
|
-
sections.push(currentSection);
|
|
42
|
+
this.mergeAndPushSection(sections, currentSection, currentNodes, bulletMode);
|
|
23
43
|
}
|
|
24
44
|
currentSection = {
|
|
25
45
|
heading: toString(node).trim(),
|
|
@@ -29,43 +49,164 @@ export class RemarkParser {
|
|
|
29
49
|
};
|
|
30
50
|
currentNodes = [];
|
|
31
51
|
}
|
|
52
|
+
else if (node.type === 'list' && bulletMode === BulletMode.SECTIONS) {
|
|
53
|
+
// Bullet-style sections mode: each root-level bullet is a section
|
|
54
|
+
if (currentSection) {
|
|
55
|
+
this.mergeAndPushSection(sections, currentSection, currentNodes, bulletMode);
|
|
56
|
+
currentSection = null;
|
|
57
|
+
currentNodes = [];
|
|
58
|
+
}
|
|
59
|
+
// Process each list item as a section
|
|
60
|
+
const newSections = [];
|
|
61
|
+
for (const listItem of node.children) {
|
|
62
|
+
newSections.push(...this.processBulletAsSection(listItem));
|
|
63
|
+
}
|
|
64
|
+
if (newSections.length > 0) {
|
|
65
|
+
// Push all except the last one as complete sections
|
|
66
|
+
for (let i = 0; i < newSections.length - 1; i++) {
|
|
67
|
+
sections.push(newSections[i]);
|
|
68
|
+
}
|
|
69
|
+
// Keep the last one as currentSection to capture subsequent loose content
|
|
70
|
+
currentSection = newSections[newSections.length - 1];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
32
73
|
else {
|
|
33
74
|
currentNodes.push(node);
|
|
34
75
|
}
|
|
35
76
|
}
|
|
77
|
+
// Save last section
|
|
36
78
|
if (currentSection) {
|
|
37
|
-
|
|
38
|
-
sections.push(currentSection);
|
|
79
|
+
this.mergeAndPushSection(sections, currentSection, currentNodes, bulletMode);
|
|
39
80
|
}
|
|
40
81
|
else if (currentNodes.length > 0) {
|
|
82
|
+
// No sections found, put everything in root
|
|
41
83
|
sections.push({
|
|
42
84
|
heading: 'Root',
|
|
43
|
-
content: this.processContent(currentNodes),
|
|
85
|
+
content: this.processContent(currentNodes, bulletMode),
|
|
44
86
|
level: 0,
|
|
45
87
|
format: 'text'
|
|
46
88
|
});
|
|
47
89
|
}
|
|
48
90
|
return sections;
|
|
49
91
|
}
|
|
50
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Process content nodes into appropriate format
|
|
94
|
+
*/
|
|
95
|
+
processContent(nodes, bulletMode) {
|
|
51
96
|
if (nodes.length === 0)
|
|
52
97
|
return '';
|
|
98
|
+
// Single table - return as array of objects
|
|
53
99
|
if (nodes.length === 1 && nodes[0].type === 'table') {
|
|
54
100
|
return this.tableToArray(nodes[0]);
|
|
55
101
|
}
|
|
102
|
+
// Single list - behavior depends on mode
|
|
56
103
|
if (nodes.length === 1 && nodes[0].type === 'list') {
|
|
57
|
-
|
|
104
|
+
if (bulletMode === BulletMode.ARRAY) {
|
|
105
|
+
// Mode 1: Return as simple array of strings
|
|
106
|
+
return this.listToArray(nodes[0]);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Mode 2: In sections mode, nested lists are still arrays
|
|
110
|
+
return this.listToArray(nodes[0]);
|
|
111
|
+
}
|
|
58
112
|
}
|
|
113
|
+
// Multiple nodes or mixed content
|
|
59
114
|
return nodes.map(node => {
|
|
60
115
|
if (node.type === 'table') {
|
|
61
|
-
return
|
|
116
|
+
return this.tableToArray(node);
|
|
117
|
+
}
|
|
118
|
+
if (node.type === 'list') {
|
|
119
|
+
return this.listToArray(node);
|
|
62
120
|
}
|
|
63
121
|
return toString(node);
|
|
64
122
|
}).join('\n\n').trim();
|
|
65
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Process a bullet list item as a section (Mode 2: SECTIONS)
|
|
126
|
+
*/
|
|
127
|
+
processBulletAsSection(listItem) {
|
|
128
|
+
const sections = [];
|
|
129
|
+
// First child is the bullet text (section heading)
|
|
130
|
+
const firstChild = listItem.children[0];
|
|
131
|
+
if (!firstChild)
|
|
132
|
+
return sections;
|
|
133
|
+
const rawText = toString(firstChild).trim();
|
|
134
|
+
const lines = rawText.split('\n');
|
|
135
|
+
const heading = lines[0]?.trim() || '';
|
|
136
|
+
const sameNodeContent = lines.slice(1).join('\n').trim();
|
|
137
|
+
// Clean heading: remove trailing colon if present
|
|
138
|
+
const cleanHeading = heading.replace(/:$/, '');
|
|
139
|
+
// Rest of the children are the content
|
|
140
|
+
const contentNodes = listItem.children.slice(1);
|
|
141
|
+
let content;
|
|
142
|
+
if (contentNodes.length === 0) {
|
|
143
|
+
// No extra nodes, but maybe same-node content?
|
|
144
|
+
content = sameNodeContent;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
// If we have sameNodeContent, we should prepend it to the text content?
|
|
148
|
+
// This gets complicated if contentNodes are mixed.
|
|
149
|
+
// Simplified: If sameNodeContent exists, assume it's part of the text.
|
|
150
|
+
// Check for nested list
|
|
151
|
+
const nestedList = contentNodes.find((node) => node.type === 'list');
|
|
152
|
+
if (nestedList && contentNodes.length === 1) {
|
|
153
|
+
// ONLY a nested list - convert to array
|
|
154
|
+
content = this.listToArray(nestedList);
|
|
155
|
+
}
|
|
156
|
+
else if (nestedList) {
|
|
157
|
+
// Mixed content: paragraphs + nested list
|
|
158
|
+
// For now, convert nested list to array and combine
|
|
159
|
+
const paragraphs = contentNodes
|
|
160
|
+
.filter((node) => node.type !== 'list')
|
|
161
|
+
.map((node) => toString(node))
|
|
162
|
+
.join('\n\n')
|
|
163
|
+
.trim();
|
|
164
|
+
const fullText = sameNodeContent ? sameNodeContent + '\n\n' + paragraphs : paragraphs;
|
|
165
|
+
const nestedArray = this.listToArray(nestedList);
|
|
166
|
+
// Combine: return object with text and items
|
|
167
|
+
content = {
|
|
168
|
+
text: fullText,
|
|
169
|
+
items: nestedArray
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// Only paragraphs/text content
|
|
174
|
+
const nodeText = contentNodes
|
|
175
|
+
.map((node) => toString(node))
|
|
176
|
+
.join('\n\n')
|
|
177
|
+
.trim();
|
|
178
|
+
content = sameNodeContent ? sameNodeContent + '\n\n' + nodeText : nodeText;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
sections.push({
|
|
182
|
+
heading: cleanHeading,
|
|
183
|
+
content,
|
|
184
|
+
level: 1,
|
|
185
|
+
format: 'bullet'
|
|
186
|
+
});
|
|
187
|
+
return sections;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Convert list to simple array of strings (Mode 1: ARRAY)
|
|
191
|
+
*/
|
|
192
|
+
listToArray(listNode) {
|
|
193
|
+
return listNode.children.map((item) => {
|
|
194
|
+
// Get just the first paragraph/text, ignore nested content
|
|
195
|
+
const firstChild = item.children[0];
|
|
196
|
+
return toString(firstChild).trim();
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Convert table to array of objects
|
|
201
|
+
*/
|
|
66
202
|
tableToArray(tableNode) {
|
|
67
|
-
const
|
|
68
|
-
|
|
203
|
+
const rows = tableNode.children;
|
|
204
|
+
if (rows.length === 0)
|
|
205
|
+
return [];
|
|
206
|
+
// First row = headers
|
|
207
|
+
const headers = rows[0].children.map((cell) => toCamelCase(toString(cell).trim()));
|
|
208
|
+
// Remaining rows = data
|
|
209
|
+
return rows.slice(1).map((row) => {
|
|
69
210
|
const obj = {};
|
|
70
211
|
row.children.forEach((cell, i) => {
|
|
71
212
|
const key = headers[i] || `column${i}`;
|
|
@@ -74,5 +215,42 @@ export class RemarkParser {
|
|
|
74
215
|
return obj;
|
|
75
216
|
});
|
|
76
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Convert sections to object (utility method)
|
|
220
|
+
*/
|
|
221
|
+
sectionsToObject(sections) {
|
|
222
|
+
const result = {};
|
|
223
|
+
for (const section of sections) {
|
|
224
|
+
const key = toCamelCase(section.heading);
|
|
225
|
+
result[key] = section.content;
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
mergeAndPushSection(sections, section, nodes, bulletMode) {
|
|
230
|
+
// If the section is already in the list (because we pushed it in the loop but kept a reference),
|
|
231
|
+
// we shouldn't push it again?
|
|
232
|
+
// Wait, my logic implementation in loop:
|
|
233
|
+
// "newSections.push(...); if (newSections.length > 0) { ... loop push n-1 ... currentSection = nth }"
|
|
234
|
+
// So currentSection is NOT in sections yet.
|
|
235
|
+
// It's safe to push.
|
|
236
|
+
const newContent = this.processContent(nodes, bulletMode);
|
|
237
|
+
if (newContent) {
|
|
238
|
+
if (!section.content) {
|
|
239
|
+
section.content = newContent;
|
|
240
|
+
}
|
|
241
|
+
else if (typeof section.content === 'string' && typeof newContent === 'string') {
|
|
242
|
+
section.content += '\n\n' + newContent;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
if (Array.isArray(section.content)) {
|
|
246
|
+
section.content.push(newContent);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
section.content = [section.content, newContent];
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
sections.push(section);
|
|
254
|
+
}
|
|
77
255
|
}
|
|
78
256
|
//# sourceMappingURL=parser.js.map
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAmB,UAAU,EAAiB,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM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CAAC;YACb,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,OAAO,GAAG,UAAU,CAAC;YACjC,CAAC;iBAAM,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;gBAC/E,OAAO,CAAC,OAAO,IAAI,MAAM,GAAG,UAAU,CAAC;YAC3C,CAAC;iBAAM,CAAC;gBACJ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;oBACjC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBACrC,CAAC;qBAAM,CAAC;oBACJ,OAAO,CAAC,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;gBACpD,CAAC;YACL,CAAC;QACL,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bullet-sections.d.ts","sourceRoot":"","sources":["../../src/plugins/bullet-sections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bullet-sections.d.ts","sourceRoot":"","sources":["../../src/plugins/bullet-sections.ts"],"names":[],"mappings":"AAgBA,wBAAgB,oBAAoB,KAC1B,MAAM,GAAG,UAqBjB"}
|
|
@@ -1,79 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remark plugin to handle bullet-style sections
|
|
3
|
+
* Converts bullets that look like sections into heading nodes
|
|
4
|
+
*/
|
|
5
|
+
import { visit } from 'unist-util-visit';
|
|
1
6
|
import { toString } from 'mdast-util-to-string';
|
|
7
|
+
const SECTION_KEYWORDS = [
|
|
8
|
+
'answer', 'summary', 'introduction', 'conclusion', 'overview',
|
|
9
|
+
'assumptions', 'unknowns', 'evidence', 'notes', 'details',
|
|
10
|
+
'description', 'background', 'analysis', 'findings', 'recommendations',
|
|
11
|
+
'data', 'identity', 'network', 'security', 'monitoring', 'governance',
|
|
12
|
+
'availability', 'backup', 'patch', 'operational', 'provider'
|
|
13
|
+
];
|
|
2
14
|
export function remarkBulletSections() {
|
|
3
15
|
return (tree) => {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const newRootNodes = [];
|
|
14
|
-
let currentListItems = [];
|
|
15
|
-
items.forEach((item, idx) => {
|
|
16
|
-
const firstChild = item.children[0];
|
|
17
|
-
const text = firstChild ? toString(firstChild) : '';
|
|
18
|
-
const lines = text.trim().split('\n');
|
|
19
|
-
const firstLine = lines[0]?.trim() || '';
|
|
20
|
-
const isShort = firstLine.length > 0 && firstLine.length < 150;
|
|
21
|
-
const hasMoreContent = lines.length > 1 || item.children.length > 1;
|
|
22
|
-
// Section detection:
|
|
23
|
-
// 1. It's short and has more content.
|
|
24
|
-
// 2. OR it's short and is followed by a non-short item? (Hard to check here)
|
|
25
|
-
// 3. OR it's one of the "known" section keywords.
|
|
26
|
-
const keywords = ['answer', 'assumptions', 'unknowns', 'evidence', 'protection', 'control', 'management', 'design', 'logging', 'monitoring', 'backups', 'compliance', 'governance', 'modeling', 'incident', 'vendor', 'changes'];
|
|
27
|
-
const isSectionKeyword = keywords.some(k => firstLine.toLowerCase().includes(k));
|
|
28
|
-
if (isShort && (hasMoreContent || isSectionKeyword)) {
|
|
29
|
-
// Flush existing list items if any
|
|
30
|
-
if (currentListItems.length > 0) {
|
|
31
|
-
newRootNodes.push({
|
|
32
|
-
type: 'list',
|
|
33
|
-
ordered: false,
|
|
34
|
-
children: [...currentListItems]
|
|
35
|
-
});
|
|
36
|
-
currentListItems = [];
|
|
37
|
-
}
|
|
38
|
-
// Add as heading
|
|
39
|
-
newRootNodes.push({
|
|
40
|
-
type: 'heading',
|
|
41
|
-
depth: 2,
|
|
42
|
-
children: [{ type: 'text', value: firstLine }]
|
|
43
|
-
});
|
|
44
|
-
// Add content
|
|
45
|
-
if (lines.length > 1) {
|
|
46
|
-
newRootNodes.push({
|
|
47
|
-
type: 'paragraph',
|
|
48
|
-
children: [{ type: 'text', value: lines.slice(1).join('\n').trim() }]
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (item.children.length > 1) {
|
|
52
|
-
newRootNodes.push(...item.children.slice(1));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
currentListItems.push(item);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
// Flush remaining
|
|
60
|
-
if (currentListItems.length > 0) {
|
|
61
|
-
newRootNodes.push({
|
|
62
|
-
type: 'list',
|
|
63
|
-
ordered: false,
|
|
64
|
-
children: [...currentListItems]
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (newRootNodes.length > 0) {
|
|
68
|
-
// If we performed any transformation (i.e., we found at least one heading)
|
|
69
|
-
const hasHeadings = newRootNodes.some(n => n.type === 'heading');
|
|
70
|
-
if (hasHeadings) {
|
|
71
|
-
children.splice(i, 1, ...newRootNodes);
|
|
72
|
-
i += newRootNodes.length - 1;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
16
|
+
const transformations = [];
|
|
17
|
+
// First pass: identify bullets that should become headings
|
|
18
|
+
visit(tree, 'list', (node, index, parent) => {
|
|
19
|
+
if (!parent || node.ordered)
|
|
20
|
+
return; // Only unordered lists
|
|
21
|
+
// Don't transform if there are no section bullets
|
|
22
|
+
// This preserves normal list behavior
|
|
23
|
+
if (transformations.length === 0) {
|
|
24
|
+
return tree;
|
|
75
25
|
}
|
|
76
|
-
|
|
26
|
+
// For now, just mark them for detection
|
|
27
|
+
// The actual transformation happens in the parser
|
|
28
|
+
return tree;
|
|
29
|
+
});
|
|
77
30
|
};
|
|
78
31
|
}
|
|
32
|
+
function isSectionBullet(listItem) {
|
|
33
|
+
if (!listItem.children || listItem.children.length === 0) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const firstChild = listItem.children[0];
|
|
37
|
+
const text = toString(firstChild).toLowerCase();
|
|
38
|
+
// Check for section indicators
|
|
39
|
+
const hasKeyword = SECTION_KEYWORDS.some(kw => text.includes(kw));
|
|
40
|
+
const hasColon = text.includes(':');
|
|
41
|
+
const hasContent = listItem.children.length > 1;
|
|
42
|
+
const isCapitalized = /^[A-Z]/.test(text);
|
|
43
|
+
const isLong = text.length > 30;
|
|
44
|
+
// It's likely a section if it has multiple indicators
|
|
45
|
+
const indicators = [hasKeyword, hasColon, hasContent, isCapitalized, isLong];
|
|
46
|
+
const score = indicators.filter(Boolean).length;
|
|
47
|
+
return score >= 2;
|
|
48
|
+
}
|
|
79
49
|
//# sourceMappingURL=bullet-sections.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bullet-sections.js","sourceRoot":"","sources":["../../src/plugins/bullet-sections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bullet-sections.js","sourceRoot":"","sources":["../../src/plugins/bullet-sections.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,MAAM,gBAAgB,GAAG;IACvB,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU;IAC7D,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS;IACzD,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB;IACtE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY;IACrE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU;CAC7D,CAAC;AAEF,MAAM,UAAU,oBAAoB;IAClC,OAAO,CAAC,IAAS,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QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;IAC7E,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAEhD,OAAO,KAAK,IAAI,CAAC,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-bullet-mode.d.ts","sourceRoot":"","sources":["../../src/plugins/detect-bullet-mode.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAUD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,gBAAgB,CA4I5D"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect if bullets should be treated as array items or sections
|
|
3
|
+
*/
|
|
4
|
+
import { visit } from 'unist-util-visit';
|
|
5
|
+
import { toString } from 'mdast-util-to-string';
|
|
6
|
+
const SECTION_KEYWORDS = [
|
|
7
|
+
'answer', 'summary', 'introduction', 'conclusion', 'overview',
|
|
8
|
+
'assumptions', 'unknowns', 'evidence', 'notes', 'details',
|
|
9
|
+
'description', 'background', 'analysis', 'findings', 'recommendations',
|
|
10
|
+
'data', 'identity', 'network', 'security', 'monitoring', 'governance',
|
|
11
|
+
'availability', 'backup', 'patch', 'operational', 'provider'
|
|
12
|
+
];
|
|
13
|
+
export function detectBulletMode(tree) {
|
|
14
|
+
const reasons = [];
|
|
15
|
+
let sectionScore = 0;
|
|
16
|
+
let arrayScore = 0;
|
|
17
|
+
let bulletCount = 0;
|
|
18
|
+
let bulletsWithContent = 0;
|
|
19
|
+
let bulletsWithColons = 0;
|
|
20
|
+
let bulletsWithNestedLists = 0;
|
|
21
|
+
let bulletsWithKeywords = 0;
|
|
22
|
+
let totalBulletLength = 0;
|
|
23
|
+
let rootLevelBullets = 0;
|
|
24
|
+
// Analyze the tree structure
|
|
25
|
+
visit(tree, 'list', (listNode, index, parent) => {
|
|
26
|
+
// Only analyze root-level lists or lists directly under root
|
|
27
|
+
const isRootLevel = parent?.type === 'root';
|
|
28
|
+
if (!isRootLevel)
|
|
29
|
+
return;
|
|
30
|
+
rootLevelBullets += listNode.children.length;
|
|
31
|
+
for (const listItem of listNode.children) {
|
|
32
|
+
bulletCount++;
|
|
33
|
+
// Get the text of this list item (first paragraph/text only)
|
|
34
|
+
const firstChild = listItem.children[0];
|
|
35
|
+
const itemText = firstChild ? toString(firstChild) : '';
|
|
36
|
+
totalBulletLength += itemText.length;
|
|
37
|
+
// 1. Check for colons (title pattern: "Short answer:" or "Data protection:")
|
|
38
|
+
if (itemText.includes(':')) {
|
|
39
|
+
bulletsWithColons++;
|
|
40
|
+
}
|
|
41
|
+
// 2. Check for content after the bullet (paragraphs, nested items)
|
|
42
|
+
if (listItem.children.length > 1) {
|
|
43
|
+
bulletsWithContent++;
|
|
44
|
+
}
|
|
45
|
+
// 3. Check for nested lists
|
|
46
|
+
const hasNestedList = listItem.children.some((child) => child.type === 'list');
|
|
47
|
+
if (hasNestedList) {
|
|
48
|
+
bulletsWithNestedLists++;
|
|
49
|
+
}
|
|
50
|
+
// 4. Check for section keywords
|
|
51
|
+
const lowerText = itemText.toLowerCase();
|
|
52
|
+
if (SECTION_KEYWORDS.some(kw => lowerText.includes(kw))) {
|
|
53
|
+
bulletsWithKeywords++;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (bulletCount === 0) {
|
|
58
|
+
return {
|
|
59
|
+
mode: 'array',
|
|
60
|
+
confidence: 0,
|
|
61
|
+
reasons: ['No bullets found']
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const avgLength = totalBulletLength / bulletCount;
|
|
65
|
+
// === SCORING FOR SECTIONS MODE ===
|
|
66
|
+
if (bulletsWithColons > 0) {
|
|
67
|
+
const percent = (bulletsWithColons / bulletCount * 100).toFixed(0);
|
|
68
|
+
sectionScore += 3;
|
|
69
|
+
reasons.push(`${bulletsWithColons}/${bulletCount} bullets have colons (${percent}%) - strong section indicator`);
|
|
70
|
+
}
|
|
71
|
+
if (bulletsWithContent > 0) {
|
|
72
|
+
const percent = (bulletsWithContent / bulletCount * 100).toFixed(0);
|
|
73
|
+
sectionScore += 3;
|
|
74
|
+
reasons.push(`${bulletsWithContent}/${bulletCount} bullets have content below (${percent}%) - strong section indicator`);
|
|
75
|
+
}
|
|
76
|
+
if (bulletsWithNestedLists > 0) {
|
|
77
|
+
sectionScore += 2;
|
|
78
|
+
reasons.push(`${bulletsWithNestedLists} bullets have nested lists - section indicator`);
|
|
79
|
+
}
|
|
80
|
+
if (bulletsWithKeywords > 0) {
|
|
81
|
+
sectionScore += 2;
|
|
82
|
+
reasons.push(`${bulletsWithKeywords} bullets contain section keywords`);
|
|
83
|
+
}
|
|
84
|
+
if (avgLength > 30) {
|
|
85
|
+
sectionScore += 1;
|
|
86
|
+
reasons.push(`Long bullet text (avg ${avgLength.toFixed(0)} chars) - suggests titles`);
|
|
87
|
+
}
|
|
88
|
+
if (bulletCount <= 5 && (bulletsWithContent > 0 || bulletsWithColons > 0)) {
|
|
89
|
+
sectionScore += 1;
|
|
90
|
+
reasons.push('Few bullets with rich content suggests sections');
|
|
91
|
+
}
|
|
92
|
+
// === SCORING FOR ARRAY MODE ===
|
|
93
|
+
if (bulletsWithColons === 0 && bulletsWithContent === 0 && bulletsWithNestedLists === 0) {
|
|
94
|
+
arrayScore += 4;
|
|
95
|
+
reasons.push('No bullets have content, colons, or nesting - pure list indicator');
|
|
96
|
+
}
|
|
97
|
+
if (avgLength < 30) {
|
|
98
|
+
arrayScore += 2;
|
|
99
|
+
reasons.push(`Short bullet text (avg ${avgLength.toFixed(0)} chars) - suggests list items`);
|
|
100
|
+
}
|
|
101
|
+
if (bulletCount >= 3 && bulletsWithContent === 0) {
|
|
102
|
+
arrayScore += 2;
|
|
103
|
+
reasons.push(`${bulletCount} simple bullets without content - array pattern`);
|
|
104
|
+
}
|
|
105
|
+
if (bulletsWithKeywords === 0) {
|
|
106
|
+
arrayScore += 1;
|
|
107
|
+
reasons.push('No section keywords found');
|
|
108
|
+
}
|
|
109
|
+
// Edge case: all bullets are very short and no special features
|
|
110
|
+
if (avgLength < 20 && bulletsWithContent === 0 && bulletsWithColons === 0) {
|
|
111
|
+
arrayScore += 2;
|
|
112
|
+
reasons.push('Very short bullets with no features - definitely array');
|
|
113
|
+
}
|
|
114
|
+
// === DECISION ===
|
|
115
|
+
const totalScore = sectionScore + arrayScore;
|
|
116
|
+
const mode = sectionScore > arrayScore ? 'sections' : 'array';
|
|
117
|
+
const confidence = totalScore > 0 ? Math.abs(sectionScore - arrayScore) / totalScore : 0;
|
|
118
|
+
// Format reasons (top 5)
|
|
119
|
+
const topReasons = reasons.slice(0, 5);
|
|
120
|
+
return {
|
|
121
|
+
mode,
|
|
122
|
+
confidence,
|
|
123
|
+
reasons: topReasons
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=detect-bullet-mode.js.map
|