parseIndentedBlocks
@blockslides/core / parseIndentedBlocks
Function: parseIndentedBlocks()
parseIndentedBlocks(
src,config,lexer): {items:ParsedBlock[];raw:string; } |undefined
Defined in: blockslides/packages/core/src/utilities/markdown/parseIndentedBlocks.ts:77
Parses markdown text into hierarchical indented blocks with proper nesting.
This utility handles:
- Line-by-line parsing with pattern matching
- Hierarchical nesting based on indentation levels
- Nested content collection and parsing
- Empty line handling
- Content dedenting for nested blocks
The key difference from flat parsing is that this maintains the hierarchical
structure where nested items become nestedTokens of their parent items,
rather than being flattened into a single array.
Parameters
src
string
The markdown source text to parse
config
Configuration object defining how to parse and create tokens
lexer
Markdown lexer for parsing nested content
inlineTokens
(src) => any[]
blockTokens
(src) => any[]
Returns
{ items: ParsedBlock[]; raw: string; } | undefined
Parsed result with hierarchical items, or undefined if no matches
Example
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)