remarkjs / remark-highlight.js

Deprecated plugin to highlight code — please use `rehype-highlight` or `rehype-starry-night` instead
70 stars 13 forks source link

Option to ignore unknown languages #37

Closed msmsimondean closed 3 years ago

msmsimondean commented 4 years ago

Subject of the feature

Would it be possible to add an option for unknown languages to be ignored rather than raising an error? Alternatively, could such errors be recorded in the vfile output of remark rather than throwing an error?

Problem

I am parsing a number of markdown documents that I don't have direct control of. Some of the documents contain invalid or unknown langauges in their code blocks.

Expected behavior

Input:

```unknown
Hello, World!
```

Expected behavious: when remark-highlight.js is passed an option call something like { ignoreUnknown: true } it ignores the unknown lanugage rather than throwing an exception.

Alternatives

I'm using processSync(). I've considered wrapping it in a try catch.

wooorm commented 4 years ago

(You can use more ticks around your markdown code, if you'd like to fix your examples)

I think there's such an option in lowlight, so it should be possible and relatively easy to add it here. Interested in a PR?

wooorm commented 3 years ago

@msmsimondean Friendly ping!

msmsimondean commented 3 years ago

Here's a bit of context. It seems the intellisense in IntelliJ likes to put $xslt as the language in Markdown code blocks. Consequently in the README.md documents I'm working with, lots of them contain $xslt as the language. It causes remark to throw an exception (due to remark-highlight.js) when it encounters such files.

I thought (perhaps naively) that as remark (and Unified) has this great VFile pattern for processor output, it might be worth using that for errors like this where the code language is unknown? I have no idea how difficult / feasible that would be. I've only had a brief look at the code in this module and how it interacts with lowlight. Thanks!

For the moment, I'm wrapping remark in an try catch to catch this error and presenting that back in my UI

wooorm commented 3 years ago

The option is in rehype-highlight.

As the readme for this project says: you should probably use that project.

msmsimondean commented 3 years ago

Great, thanks for the info

wooorm commented 3 years ago

Going to close this as this package will soon be deprecated and archived, to make it clearer that rehype-highlight is the suggested and preferred route