Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Twoslash code highlighter breaks when rendering hover that has a js code block in it. #403

@steveluscher

Description

@steveluscher

Consider console.log(). Its docs look like this (notice the code fence inside the docblock):

/**
 * Prints to `stdout` with newline. Multiple arguments can be passed, with the
 * first used as the primary message and all additional used as substitution
 * values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
 * (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)).
 *
 * ```js
 * const count = 5;
 * console.log('count: %d', count);
 * // Prints: count: 5, to stdout
 * console.log('count:', count);
 * // Prints: count: 5, to stdout
 * ```
 *
 * See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.
 * @since v0.1.100
 */

When Twoslash goes to render a codeblock with console.log() in it, it tries to recursively render the js code fence inside the docs for console.log(). When it does so, we get this:

./content/docs/upgrade-guide.mdx
Error evaluating Node.js code
ShikiError: upgrade-guide.mdx:ShikiError: Language `js` not found, you may need to load it first
    [at Object.getLanguage (file:///home/sol/src/kit/docs/node_modules/.pnpm/@[email protected]/node_modules/@shikijs/core/dist/index.mjs:1756:13)]
    [at codeToTokensBase (file:///home/sol/src/kit/docs/node_modules/.pnpm/@[email protected]/node_modules/@shikijs/core/dist/index.mjs:809:29)]
    [at file:///home/sol/src/kit/docs/node_modules/.pnpm/@[email protected]/node_modules/@shikijs/core/dist/index.mjs:1015:21]
    [at <anonymous>]
    [at codeToTokensWithThemes (file:///home/sol/src/kit/docs/node_modules/.pnpm/@[email protected]/node_modules/@shikijs/core/dist/index.mjs:1014:31)]
    [at codeToTokens (file:///home/sol/src/kit/docs/node_modules/.pnpm/@[email protected]/node_modules/@shikijs/core/dist/index.mjs:1109:25)]
    [at codeToHast (file:///home/sol/src/kit/docs/node_modules/.pnpm/@[email protected]/node_modules/@shikijs/core/dist/index.mjs:1168:7)]
    [at Object.codeToHast (file:///home/sol/src/kit/docs/node_modules/.pnpm/@[email protected]/node_modules/@shikijs/core/dist/index.mjs:1155:36)]
    [at code (file:///home/sol/src/kit/docs/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]__@[email protected]_9e9244c803143d69682599df624dac14/node_modules/fumadocs-twoslash/dist/index.js:118:23)]
    [at Object.one (file:///home/sol/src/kit/docs/node_modules/.pnpm/[email protected]/node_modules/mdast-util-to-hast/lib/state.js:254:14)]

Related: fuma-nama/fumadocs#1095 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions