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
130 stars 32 forks source link

Upgrade to use Torchlight? #74

Closed aaronstezycki closed 1 year ago

aaronstezycki commented 1 year ago

Comes with a wide array of functionality (seems to come up alot in the issues, i.e. line numbers, diffs) baked in. Also comes with focusing, collapsible sections and much more.

Would probably need to use the CLI version of Torchlight, but should work well. Torchlight.dev

Snapstromegon commented 1 year ago

I strongly oppose "upgrading" to Torchlight with their current licensing model and the fact that their clients interact with an API.

This might be okay to integrate as an optional feature with big warning signs (or even better, a seperate plugin), but switching over completely would make this plugin inaccessible to many projects and 11ty users.

Although Tochlight definetly has some really nice features.

zachleat commented 1 year ago

Ah yeah, show up super late here to say that Torchlight can absolutely live as a separate plugin! All of the hooks should be available!

aaronstezycki commented 1 year ago

Noted! Hadn't thought of any issues facing the licensing model. Most (just assuming) are using for a personal/open source project, but that's fair to point out.

@zachleat Out of interest and off the top of my head, and example of implementing this would be to use eleventy.after and compiling the output with Torchlight?

module.exports = function (eleventyConfig) {
  // Async-friendly in 1.0+
  eleventyConfig.on('eleventy.after', async () => {
    // Run me after the build ends
  });
};
Snapstromegon commented 1 year ago

I would personally do this as a shortcode instead of an after, because with eleventy.after you'd need to extract the code to highlight yourself, which can be hard to impossible. For markdown highlighting there exists an eleventyConfig.addMarkdownHighlighter(), but I think it's undocumented.

If I were to implement it, I'd probably keep it close to this plugin.

aaronstezycki commented 1 year ago

I guess the only reason I mentioned the eleventy.after is that one of Torchlights build processes is from standalone CLI, so thought that would be an easy route to use the CLI to process the html after 11ty has built it. I'm unaware of any Torchlight integration directly into a js/11ty pipeline that would work, but I'm not very experienced with Torchlight.

Thanks for the direction though, will try to learn and take a look into it. :)

Snapstromegon commented 1 year ago

Ahh, looking at the docs, I see what you mean. It would probably be viable to use the CLI that way, but it would also force the user to use torchlight for all syntax highlighting (in a file) instead of for specific code blocks (e.g. when comparing syntax highlighters).

You could use their API directly, as you just need to post an object to https://api.torchlight.dev/highlight, but if you do that for each code block, you might hit rate limits fairly soon.

In general I would personally right now avoid this tool (except for experimentation), because rate limits are really low (for the commercial option) or unknown and the docs seem nice, but lack some information or are outdated (like the link to the remark plugin).