flex-md 4.2.5 → 4.2.6

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.
@@ -21,7 +21,8 @@ export function extractFromMarkdown(md, spec) {
21
21
  workingContent = content;
22
22
  }
23
23
  }
24
- const parsed = parseHeadingsAndSections(workingContent);
24
+ const bulletNames = spec.sections.map(s => s.name);
25
+ const parsed = parseHeadingsAndSections(workingContent, { bulletNames });
25
26
  const sectionsByName = {};
26
27
  const tables = [];
27
28
  const specMap = new Map(spec.sections.map(s => [normalizeName(s.name), s]));
@@ -24,7 +24,10 @@ export interface ParsedSection {
24
24
  bodyEnd: number;
25
25
  body: string;
26
26
  }
27
- export declare function parseHeadingsAndSections(md: string): ParsedSection[];
27
+ export interface ParseHeadingsOptions {
28
+ bulletNames?: string[];
29
+ }
30
+ export declare function parseHeadingsAndSections(md: string, options?: ParseHeadingsOptions): ParsedSection[];
28
31
  export declare function extractBullets(body: string): string[];
29
32
  export declare function parseMarkdownTable(body: string, columns: string[]): Record<string, string>[];
30
33
  export declare function isIssuesEnvelopeCheck(md: string): IssuesEnvelope;
package/dist/md/parse.js CHANGED
@@ -28,12 +28,12 @@ export function extractFencedBlocks(text) {
28
28
  }
29
29
  return blocks;
30
30
  }
31
- export function parseHeadingsAndSections(md) {
31
+ export function parseHeadingsAndSections(md, options = {}) {
32
32
  // Standard headings #... and alternative ===key.
33
- // Use [ \t]* instead of \s for the trailing space to avoid matching newlines incorrectly with certain configurations.
34
- // Also include \r? to handle CRLF if needed, although m and g should handle ^\$ correctly.
35
- const rx = /^((?:#{1,6})[ \t]+(.+?)[ \t]*|===(.+?)[ \t]*)$/gm;
33
+ // Also optionally allow "- Section" if specified in bulletNames.
34
+ const rx = /^((?:#{1,6})[ \t]+(.+?)[ \t]*|===(.+?)[ \t]*|([-*+])[ \t]+(.+?)[ \t]*)$/gm;
36
35
  const headings = [];
36
+ const bulletNamesNormal = new Set((options.bulletNames || []).map(normalizeName));
37
37
  let m;
38
38
  while ((m = rx.exec(md)) !== null) {
39
39
  const full = m[1] ?? "";
@@ -43,6 +43,20 @@ export function parseHeadingsAndSections(md) {
43
43
  level = 1; // Treat ===key as a top-level heading
44
44
  name = (m[3] ?? "").trim();
45
45
  }
46
+ else if (m[4]) {
47
+ // It's a bullet (- / * / +)
48
+ const bulletChar = m[4];
49
+ const bulletText = (m[5] ?? "").trim();
50
+ const norm = normalizeName(bulletText);
51
+ if (bulletNamesNormal.has(norm)) {
52
+ level = 1;
53
+ name = bulletText;
54
+ }
55
+ else {
56
+ // Not a recognized section header bullet, ignore it
57
+ continue;
58
+ }
59
+ }
46
60
  else {
47
61
  const hashesMatch = full.match(/^#+/);
48
62
  const hashes = hashesMatch ? hashesMatch[0] : "";
@@ -64,7 +64,8 @@ export function transformWithOfs(md, specOrRecallId) {
64
64
  spec = specOrRecallId;
65
65
  }
66
66
  // 1. Parse sections using Flex-MD parser
67
- const parsedSections = parseHeadingsAndSections(md);
67
+ const bulletNames = spec.sections.map(s => s.name);
68
+ const parsedSections = parseHeadingsAndSections(md, { bulletNames });
68
69
  const parsedObj = {};
69
70
  // 2. Map sections to OFS and apply complex parsing (tables/lists)
70
71
  for (const sectionSpec of spec.sections) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flex-md",
3
- "version": "4.2.5",
3
+ "version": "4.2.6",
4
4
  "description": "Parse and stringify FlexMD: semi-structured Markdown with three powerful layers - Frames, Output Format Spec (OFS), and Detection/Extraction.",
5
5
  "license": "MIT",
6
6
  "author": "",