Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass inline code #233

Merged
merged 5 commits into from
Aug 27, 2024
Merged

Conversation

superhighfives
Copy link
Contributor

Allows bypassing inline code blocks from being transformed by rehype-pretty-code.

Config:

import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import rehypePrettyCode from "rehype-pretty-code";

async function main() {
  const file = await unified()
    .use(remarkParse)
    .use(remarkRehype)
    .use(rehypePrettyCode, {
      bypassInlineCode: true
    })
    .use(rehypeStringify)
    .process("`const numbers = [1, 2, 3]{:js}`");

  console.log(String(file));
}

main();

Input:

```js
const x = true;
```

`const x = true;{:js,bypassInlineCode:true}`

Output:

<figure data-rehype-pretty-code-figure="">
  <pre
    style="background-color: #24292e; color: #e1e4e8"
    tabindex="0"
    data-language="js"
    data-theme="github-dark"
  ><code data-language="js" data-theme="github-dark" style="display: grid;"><span data-line=""><span style="color:#F97583">const</span><span style="color:#79B8FF"> x</span><span style="color:#F97583"> =</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">;</span></span></code></pre>
</figure>
<p><code>const x = true;{:js,bypassInlineCode:true}</code></p>

Copy link

changeset-bot bot commented Jul 28, 2024

🦋 Changeset detected

Latest commit: a34e2cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
rehype-pretty-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Jul 28, 2024

commit: a34e2cf

pnpm add https://pkg.pr.new/rehype-pretty-code@233
pnpm add https://pkg.pr.new/@rehype-pretty/transformers@233

Open in Stackblitz

@o-az o-az merged commit 7b9793b into rehype-pretty:master Aug 27, 2024
3 checks passed
o-az pushed a commit that referenced this pull request Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants