@umbraco-cms/backoffice
    Preparing search index...

    Function parseIndentedBlocks

    • 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: BlockParserConfig

        Configuration object defining how to parse and create tokens

      • lexer: { blockTokens: (src: string) => any[]; inlineTokens: (src: string) => any[] }

        Markdown lexer for parsing nested content

      Returns undefined | { items: ParsedBlock[]; raw: string }

      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)