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

Support for language aliases #899

Open
AleksandrHovhannisyan opened this issue Aug 29, 2024 · 0 comments
Open

Support for language aliases #899

AleksandrHovhannisyan opened this issue Aug 29, 2024 · 0 comments

Comments

@AleksandrHovhannisyan
Copy link

Description

Hi there! I was thinking it would be useful to have an option to alias certain Markdown languages that are not directly supported by Prism. For example:

const LANGUAGE_ALIASES = new Map<string, string>([
  ['js', 'javascript'],
  ['ts', 'typescript'],
  ['md', 'markdown'],
  ['c++', 'cpp'],
  ['c#', 'csharp'],
  ['py', 'python'],
  ['rb', 'ruby'],
  ['yml', 'yaml'],
  ['tml', 'toml'],
]);

For example, this:

```js
```

Would be treated the same as:

```javascript
```

This is not really an issue in Node.js environments but it is in bundled (client-side) environments, where as noted in #28, Prism expects you to load the correct language grammars. The aliases listed above are technically valid in most syntax highlighters and flavors of Markdown, but they are not directly supported by Prism, so they cannot be loaded as-is.

Proposed solution

Add a mapping from aliases to actual supported languages

Possible approaches:

  1. Hard-code the mapping internally with an option to opt into aliasing
  2. Allow users to pass in their own alias map.
  3. Some combination of Approaches 1 and 2 (sensible defaults and user overrides)

What do you think?

Additional context

  1. Happy to contribute a PR upon approval

  2. I am not actually running into any problems with my current setup because I use your plugin in a static site generator, so Prism runs in an unbundled environment. Long story short, I use my markdown parser to also parse user-generated comments and render them on my blog, and it works fine for now (I don't know how Netlify bundles serverless functions but it doesn't cause any issues there 🤷‍♂️). I'm trying to migrate to Cloudflare + Cloudflare Workers, and in that environment the code will eventually be bundled by esbuild/webpack, so it errors when an unsupported language is detected.

@github-staff github-staff deleted a comment from telfaw Oct 22, 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

No branches or pull requests

1 participant