speed-highlight / core

A lightweight syntax highlighter written in JavaScript
https://speed-highlight.github.io/core/examples/
Creative Commons Zero v1.0 Universal
257 stars 14 forks source link

[FEATURE] - Expanding syntax #15

Closed bebraw closed 2 years ago

bebraw commented 2 years ago

Is your feature request related to a problem? Please describe.

I use Leanpub Markdown for authoring my books. It's a small extension on top of regular Markdown. One of the main features it supports are insertions and deletions like this:

// You might see insertions
leanpub-start-insert
const webpack = require("webpack");
leanpub-end-insert

// You might see deletions as well
leanpub-start-delete
const { MiniHtmlWebpackPlugin } = require("mini-html-webpack-plugin");
leanpub-end-delete

// Or combinations of both
leanpub-start-delete
const { MiniHtmlWebpackPlugin } = require("mini-html-webpack-plugin");
leanpub-end-delete
leanpub-start-insert
const webpack = require("webpack");
leanpub-end-insert

// If content has been omitted, then ellipsis is used
...

Note the Leanpub specific syntax that's sitting on top of the rest.

Describe the solution you'd like

It would be great to have a way to overlay an extension on top of a language in order to parse those custom sections. My current solution looks like this: https://github.com/survivejs/site/blob/master/utils/highlight.js .

Describe alternatives you've considered

As mentioned, I've implemented this in illuminate.js and thought to bring up the idea as there's value in having an API for extensions.

matubu commented 2 years ago

Hello, I have implemented the leanpub-markdown 77d93fc9b428db2266f44455da613c5fa5e6d4b2 with my understanding of leanpub-markdown, I hope this will fill up your needs. To use leanpub-markdown you just have to set the language to leanpub-md. If you want to see how it was implemented you can go checkout src/languages/leanpub-md.

Mathias

bebraw commented 2 years ago

Awesome, thanks. 👍

bebraw commented 2 years ago

Can you tag the release so I can pull it easily from deno.land? Thanks again.