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

An option remove console.warn from prismjs/components/index.js #2145

Closed
SukkaW opened this issue Dec 25, 2019 · 1 comment · Fixed by #2147
Closed

An option remove console.warn from prismjs/components/index.js #2145

SukkaW opened this issue Dec 25, 2019 · 1 comment · Fixed by #2147

Comments

@SukkaW
Copy link

SukkaW commented Dec 25, 2019

Motivation

I am implementing a syntax highlight plugin for Hexo which requires runnning PrismJS inside Node.js.

I have use this approach (adopted from example provided by PrismJS website) to load supported languages that are not loaded by default:

const prismLoadLanguages = require('prismjs/components/');

However, when trying to load a language that doesn't supported by PrismJS will cause a console.warn output Language does not exist [language name].

Description

A silent option for not to print error message when loading a language that hasn't been supported by PrismJS could be helpful.

Alternatives

An API to get all current supported languages, maybe something like Prism.supportedLanguages() so that I could determine whether to use loadLanguages() or not.

My current solution is:

const prismComponents = require('prismjs/components.json');
const prismSupportedLanguages = Object.keys(prismComponents.languages);
@RunDevelopment
Copy link
Member

For the time being, you could probably also just replace console.warn with a no-op function before you call loadLanguages and restore its function afterward.

(I made an issue to query supported languages (#2146).)

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

Successfully merging a pull request may close this issue.

2 participants