Skip to content

Code highlighting in README files breaks on multi-word code fence info strings #3438

Description

@nadaniels

Describe the bug

Package README files (and presumably any other rendered markdown files) that use code fences aren't correctly highlighting when the info string contains multiple words:

This renders syntax highlighting correctly:

```ts
const foo = 1
```

This renders as plain text:

```ts anything-else
const bar = 1
```

The CommonMark spec allows for info strings to contain arbitrary data, and by convention the first word is the language:

The first word of the info string is typically used to specify the language of the code sample, and rendered in the class attribute of the code tag. However, this spec does not mandate any particular treatment of the info string.

See also: CommonMark Example 143.

In npmx, when marked parses a markdown file, it returns the entire code fence string as lang, and that full string gets passed into shiki, which doesn't recognize it and consequently renders it as plain text.

marked's renderer, which is bypassed in this situation, explicitly splits the info string:

const langString = (lang || '').match(other.notSpaceStart)?.[0]

So a similar split to take only the first word before passing it into shiki should fix the issue.

Happy to open a PR if desired.

Activity

  1. added theissue type on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending triageNew issue waiting for initial maintainer triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions