-
Notifications
You must be signed in to change notification settings - Fork 2
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
Error when trying to import remark-torchlight #1
Comments
👍 Am getting the exact same issue import remarkTorchlight from "remark-torchlight";
|
This pr fixes torchlight-api#1 by converting the package to an esm only package.
Same issue here |
Also preventing me using in NextJS ( |
Ok yall, thanks for your patience. I just updated the underlying library and this library to ESM, but now the test is failing. It worked with the old node_modules versions I had installed locally, but when I pushed to GH it failed. I've spent a couple hours digging and trying to figure out what changed, but the whole remark/rehype/unified/hast ecosystem stuff is not super straightforward to me. Can anyone tell if something has changed and I need to update the shape of the nodes coming out of this plugin? |
Ok I finally figured it out. Between remark-html 14.0.0 and 14.0.1 they changed a default param. https://github.com/torchlight-api/remark-torchlight/actions/runs/2506264156 The test now works, but I don't feel great that it relies on sanitize false. Should this be a rehype plugin instead? |
Amazing @aarondfrancis thank you! Will have a go with this later on. RE: RE: Rehype - in short, yes, I think you could be right. While it wasn't possible to use this library yesterday I ended up doing some digging of my own and integrating The full pipeline felt like it made the most sense as a chain via unified. A import {readFileSync} from 'fs'
import {unified} from 'unified'
import highlight from 'rehype-highlight'
import parse from 'remark-parse'
import rehype from 'remark-rehype'
import stringify from 'rehype-stringify'
import matter from 'gray-matter'
const markdown = matter(readFileSync(`./path/to/your/markdown.md`), 'utf8'))
const rendered = (await unified()
.use(parse)
.use(rehype)
.use(highlight)
.use(stringify)
.process(markdown.content))
.toString()
...yep 🤯 - my takeaway was: remark for raw markdown content to HTML and rehype for processing HTML. They're all built on top of |
@aarondfrancis it seems the last release that fixes this (0.0.3) is not published to NPM: https://www.npmjs.com/package/remark-torchlight?activeTab=versions Any way to publish it to NPM? Thanks! |
v0.0.3 might be unpublished because it requires a workaround that removes remark-html's sanitize option (creating an XSS attack vulnerabillity). As a temporary solution, downloading v0.0.3 and providing it to package.json as a local module (i.e. in package.json reference the package via the syntax Stale research:For a long-term solution:
(instead of the current v0.0.3 way):
|
Stale researchUpdate: I have some working versions, and details about sanitization. Conclusion: remark-torchlight does not need to be re-written as a rehype plugin. remark = markdown Currently, Plugin chainBoth of chain configurations work. The important new plugin is .use(rehypeSanitize): Edit: there is a 3rd simpler option that allows passing the schema object to the sanitize prop in remark-html (see final comment below) await unified()await Unified():
await remark()
Schema challenges of
|
The `remark-html` plugin allows passing a **schema object into the sanitize prop**. E.g.
It works like an 'allowlist' for HTML attributes and their values. I.e. classNames and styles. Example extended schemaThere are numerous quirks with this.But it allows most of the default torchlight theme.
To create a robust torchlight schema likely requires exporting some dictionaries from the core torchlight library (or from it's underlying shiki processor). For example, a map of all supported language keys. |
I get this error when trying to import
remark-torchlight
:I reproduced the error in this CodeSandbox
The text was updated successfully, but these errors were encountered: