11ty / eleventy-plugin-syntaxhighlight

A pack of Eleventy plugins for syntax highlighting in Markdown, Liquid, and Nunjucks templates.
https://www.11ty.dev/docs/plugins/syntaxhighlight/
MIT License
129 stars 32 forks source link

How do I add support for typescript syntax highlighting? #19

Closed martinfjant closed 4 years ago

martinfjant commented 4 years ago

So, I really do not get how I am supposed to extend the languages Prism can highlight. Where and how do I add say typescript if I want it to be able to highlight that?

zachleat commented 4 years ago

https://prismjs.com/#languages-list

Language examples are documented here for Markdown, Liquid, and Nunjucks: https://www.11ty.dev/docs/plugins/syntaxhighlight/#markdown-highlighter Most of the examples use js but you can use typescript or ts per the prism doc link above.

martinfjant commented 4 years ago

The problem is, that ts is not instanciated per default (only markup, javascript and clike are). So, when I try to add it as per the documentation, and use it but using ts rather than js in my code fences , I get errors:

[eleventy:default] Language does not exist ts
[eleventy:default] Problem writing Eleventy templates: (more in DEBUG output)
[eleventy:default] > Having trouble rendering liquid (and markdown) template ./src/blog/track.md (TemplateContentRenderError)
[eleventy:default] > Cannot read property 'rest' of undefined (TypeError):
martinfjant commented 4 years ago

Okay, so I changed it to say typescript rather than ts, and it worked. I'm not sure this is a bug with Prism (that lists both ts and typescript as supported) or the plugin. Sorry for taking up time, but this might help someone else in the future perhaps! Thanks for the really fast feedback, by the way! ❤️

zachleat commented 4 years ago

Ah hmm, I believe you did uncover a bug here. I don’t think aliases are quite resolving correctly with the Prism loader

Related: https://github.com/PrismJS/prism/issues/593 https://github.com/PrismJS/prism/issues/768 https://github.com/PrismJS/prism/issues/972

zachleat commented 4 years ago

Pushed a fix to this, it’ll go up with 3.0.1