The markdown source text to parse
Configuration object defining how to parse and create tokens
Markdown lexer for parsing nested content
Parsed result with hierarchical items, or undefined if no matches
const result = parseIndentedBlocks(src, {
itemPattern: /^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,
extractItemData: (match) => ({
indentLevel: match[1].length,
mainContent: match[4],
checked: match[3].toLowerCase() === 'x'
}),
createToken: (data, nestedTokens) => ({
type: 'taskItem',
checked: data.checked,
text: data.mainContent,
nestedTokens
})
}, lexer)
Parses markdown text into hierarchical indented blocks with proper nesting.
This utility handles:
The key difference from flat parsing is that this maintains the hierarchical structure where nested items become
nestedTokensof their parent items, rather than being flattened into a single array.