luminaxster / syntax-highlighter

An extensible library to highlight (and comment) JSX syntax in the Monaco Editor using Babel. It exposes its AST, so you can add your own syntax-based or custom highlights.
https://luminaxster.github.io/syntax-highlighter/
MIT License
30 stars 4 forks source link

Request | Support TSX format highlighting #22

Closed HaimCandiTech closed 5 months ago

HaimCandiTech commented 6 months ago

Right now the library doesn't work well if there is any type in the code.

An easy way to fix it is by adjusting makeBabelParse -

export const makeBabelParse = (parse, enableTsxHighlight) => {
   return (code, options = {}) => {
      return parse(
         code,
         {
            ...options,
            sourceType: "module",
            plugins: ["jsx", ...(enableTsxHighlight ? ['typescript'] : [])],
            errorRecovery: true
         });

   };
};

I could create a PR but I can't open branches for this repo :(

Please address it so I will be able to use your library and not a forked copy

luminaxster commented 6 months ago

=) , I will handle with #23