babeljsreactjsstatic-sitecodehighlighter

Babel & JSX Browser Code Highlighting


I use https://highlightjs.org/ for an in browser (and in a static site generator) to highlight code snippets for blogs and sites. I'm almost certain its not handling ES6, ES7, JSX, and Flow.

How can I get better highlighting for these new additions to javascript?

Please advise. Thanks :)


Solution

  • Using highlight.js you can register languages.

    <script src="/js/highlight.js" type="text/javascript"></script>
    <script src="/js/highlight-js.js" type="text/javascript"></script>
    <script src="/js/highlight-xml.js" type="text/javascript"></script>
    <script>
      hljs.registerLanguage('js', H_js);
      hljs.registerLanguage('xml', H_xml);
      hljs.initHighlightingOnLoad();
    </script>
    

    Here is a good hightlight-js.js for ES6/React.