• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jcubic / 10xDevs / 18569861134

16 Oct 2025 05:39PM UTC coverage: 20.966% (-0.01%) from 20.976%
18569861134

push

github

jcubic
use Peggy parser from SNApp-notes/mobile

67 of 105 branches covered (63.81%)

Branch coverage included in aggregate %.

0 of 22 new or added lines in 3 files covered. (0.0%)

454 of 2380 relevant lines covered (19.08%)

2.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.96
/src/lib/parser/markdown-parser.ts
1
import type { Header } from '@/types/notes';
1✔
NEW
2
import { parse, type MarkdownNode, type HeaderNode } from './index';
×
3

4
/**
5
 * Extract headers from markdown content using peggy parser
6
 * This replaces the regex-based solution which breaks with headers in code blocks
7
 */
8
export function extractHeaders(content: string): Header[] {
×
9
  if (!content) return [];
×
10

NEW
11
  try {
×
NEW
12
    const nodes: MarkdownNode[] = parse(content);
×
NEW
13
    const headers: Header[] = [];
×
14

NEW
15
    nodes.forEach((node, index) => {
×
NEW
16
      if (node.type === 'header') {
×
NEW
17
        const headerNode = node as HeaderNode;
×
NEW
18
        headers.push({
×
NEW
19
          id: `header-${index}-${headerNode.level}`,
×
NEW
20
          text: headerNode.content.replace(/^#+\s*/, '').trim(),
×
NEW
21
          level: headerNode.level as 1 | 2 | 3 | 4 | 5 | 6,
×
NEW
22
          line: headerNode.loc.start.line
×
NEW
23
        });
×
NEW
24
      }
×
NEW
25
    });
×
26

NEW
27
    return headers;
×
NEW
28
  } catch (error) {
×
NEW
29
    console.error('Failed to parse markdown content:', error);
×
NEW
30
    return [];
×
NEW
31
  }
×
32
}
×
33

34
/**
35
 * Build hierarchical header tree from flat header list
36
 */
37
export function buildHeaderTree(headers: Header[]): Header[] {
×
38
  if (headers.length === 0) return [];
×
39

40
  const result: Header[] = [];
×
41
  const stack: Header[] = [];
×
42

43
  headers.forEach((header) => {
×
44
    // Remove headers from stack that are at same or deeper level
45
    while (stack.length > 0 && stack[stack.length - 1].level >= header.level) {
×
46
      stack.pop();
×
47
    }
×
48

49
    // Create a copy of the header without children first
50
    const headerCopy: Header = {
×
51
      id: header.id,
×
52
      text: header.text,
×
53
      level: header.level,
×
54
      line: header.line
×
55
    };
×
56

57
    if (stack.length === 0) {
×
58
      // Top level header
59
      result.push(headerCopy);
×
60
    } else {
×
61
      // Child header
62
      const parent = stack[stack.length - 1];
×
63
      if (!parent.children) {
×
64
        parent.children = [];
×
65
      }
×
66
      parent.children.push(headerCopy);
×
67
    }
×
68

69
    stack.push(headerCopy);
×
70
  });
×
71

72
  return result;
×
73
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc