Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Example in the docs is broken #7

Open
ZaninAndrea opened this issue May 1, 2019 · 5 comments
Open

Example in the docs is broken #7

ZaninAndrea opened this issue May 1, 2019 · 5 comments

Comments

@ZaninAndrea
Copy link

Running this code sample from the docs is broken, because unified needs a compiler such as rehype-stringify to run the process method

const unified = require('unified');
const remarkParse = require('remark-parse');
const remarkRehype = require('remark-rehype');
const rehypePrism = require('rehype-prism');

unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypePrism)
  .process(/* some markdown */);

Furthermore when adding the rehype-stringify compiler the code runs correctly, but the output is not syntax highlighted, it seems that adding rehype-prism doesn't change the output.

Full code sample:

const fs = require("fs")
const html = require("rehype-stringify")
const unified = require("unified")
const remarkParse = require("remark-parse")
const remarkRehype = require("remark-rehype")
const rehypePrism = require("rehype-prism")

unified()
    .use(remarkParse)
    .use(remarkRehype)
    .use(rehypePrism)
    .use(html)
    .process(fs.readFileSync("./test.md", "utf8"), function(err, file) {
        if (err) throw err
        fs.writeFileSync("test.html", String(file))
    })
@ZaninAndrea
Copy link
Author

I fixed the second issue by using the code from the github repo instead of the npm library

@jescalan
Copy link

Thanks for the note here -- it seems like perhaps this is no longer maintained? I intend to put this into production soon for several high-visibility properties, if the maintainers are looking for some help I'd be happy to help out!

@silvenon
Copy link
Contributor

You might be installing the wrong package? The correct one is @mapbox/rehype-prism, not rehype-prism.

@jescalan
Copy link

jescalan commented May 6, 2020

That is indeed the case! Didn't even consider this 🤦🏼‍♂️

@thescientist13
Copy link

fwiw, I am observing the same issue as well, in regards to following the docs markdown usage example, e.g.

const rehypePrism = require('@mapbox/rehype-prism');
const remarkParse = require('remark-parse');
const remarkRehype = require('remark-rehype');

const processedMarkdown = await unified()
  .use(remarkParse)
  .use(remarkeRhype)
  .use(rehypePrism)
  .process(markdownContents);
Error: Cannot `process` without `Compiler`

To fix, I would need to add something like rehypeStringify as suggested in the original comment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants