Skip to content

mdc-element without children isn't handled correctly #17

Description

@Ni55aN

Reproduction

  1. Open https://codesandbox.io/p/devbox/sad-euler-qft5yl

  2. Make sure content/*.md has list with empty item

# Test

- a
- b
- c
- 
  1. Go to /llms-ffull.txt

Logs

 ERROR  [request error] [unhandled] [GET] http://localhost:3000/llms-full.txt

 
ℹ Error: Cannot read properties of undefined (reading '0')

 ⁃ at extractLeadingCheckbox (node_modules/hast-util-to-mdast/lib/handlers/li.js:117:29)

   112 ┃   *
   113 ┃   * @param {Readonly<Element>} node
   114 ┃   * @returns {ExtractResult}
   115 ┃   */
   116 ┃  function extractLeadingCheckbox(node) {
 ❯ 117 ┃    const head = node.children[0]
   118 ┃  
   119 ┃    if (
   120 ┃      head &&
   121 ┃      head.type === 'element' &&
   122 ┃      head.tagName === 'input' &&

 ⁃ at Object.li (node_modules/hast-util-to-mdast/lib/handlers/li.js:30:28)
 ⁃ at mdc-element (node_modules/@nuxtjs/mdc/dist/runtime/stringify/mdc-remark.js:98:42)
 ⁃ at Object.one (node_modules/hast-util-to-mdast/lib/state.js:255:40)
 ⁃ at Object.all (node_modules/hast-util-to-mdast/lib/state.js:220:14)
 ⁃ at Object.list (node_modules/hast-util-to-mdast/lib/handlers/list.js:19:50)
 ⁃ at mdc-element (node_modules/@nuxtjs/mdc/dist/runtime/stringify/mdc-remark.js:98:42)
 ⁃ at Object.one (node_modules/hast-util-to-mdast/lib/state.js:255:40)
 ⁃ at Object.all (node_modules/hast-util-to-mdast/lib/state.js:220:14)
 ⁃ at Object.root (node_modules/hast-util-to-mdast/lib/handlers/root.js:18:24)

[CAUSE]
TypeError {
  stack: "Cannot read properties of undefined (reading '0')\n" +
  'at extractLeadingCheckbox (./node_modules/hast-util-to-mdast/lib/handlers/li.js:117:29)\n' +
  'at Object.li (./node_modules/hast-util-to-mdast/lib/handlers/li.js:30:28)\n' +
  'at mdc-element (./node_modules/@nuxtjs/mdc/dist/runtime/stringify/mdc-remark.js:98:42)\n' +
  'at Object.one (./node_modules/hast-util-to-mdast/lib/state.js:255:40)\n' +
  'at Object.all (./node_modules/hast-util-to-mdast/lib/state.js:220:14)\n' +
  'at Object.list (./node_modules/hast-util-to-mdast/lib/handlers/list.js:19:50)\n' +
  'at mdc-element (./node_modules/@nuxtjs/mdc/dist/runtime/stringify/mdc-remark.js:98:42)\n' +
  'at Object.one (./node_modules/hast-util-to-mdast/lib/state.js:255:40)\n' +
  'at Object.all (/home/n'... 201 more characters,
  message: "Cannot read properties of undefined (reading '0')",
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions