question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Highlight.js incorporation?

See original GitHub issue

Is there a way to get highlight.js code syntax highlighting rendered in code blocks, like on Github or Discord?

For example:

```js if (foo) { console.log(bar) } ```

Would be coloured with Javascript syntax colours, as seen below, because I specified js after the first ```.

if (foo) {
    console.log(bar)
}

Please note that I am not using Node.js, but rather a js file linked to an HTML file on a Github Pages site, so I do not believe that extensions are possible for me. If I am wrong and there is a way to get extensions to load, I would appreciate you sharing it!

Thanks 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tiviecommented, Aug 30, 2018

@jacobcxdev that particular extension you linked is made exclusively for node because the author is using a non conventional way to load it.

However, it’s trivial to refactor it to make it work in the browser (see fiddle in action)

showdown.extension('highlight', function () {
  return [{
    type: "output",
    filter: function (text, converter, options) {
      var left = "<pre><code\\b[^>]*>",
          right = "</code></pre>",
          flags = "g";
      var replacement = function (wholeMatch, match, left, right) {
      	var lang = (left.match(/class=\"([^ \"]+)/) || [])[1];
        left = left.slice(0, 18) + 'hljs ' + left.slice(18);
        if (lang && hljs.getLanguage(lang)) {
          return left + hljs.highlight(lang, match).value + right;
        } else {
          return left + hljs.highlightAuto(match).value + right;
        }
      };
      return showdown.helper.replaceRecursiveRegExp(text, replacement, left, right, flags);
    }
  }];
});
0reactions
tiviecommented, Sep 15, 2018

Donate Click here to lend your support to: ShowdownJS website and testing platform and make a donation at paypal.com

As you know, ShowdownJS is a free library and it will remain free forever. However, maintaining and improving the library costs time and money. If you like our work and find our library useful, please donate through Pledgie or directly through paypal!! Your contribution will be greatly appreciated and help us continue to develop this awesome library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

highlight.js demo
Title: Block Copy Routines ;* Version: 1.1 .include "8515def.inc" rjmp RESET ;reset handle .def flashsize=r16 ;size of block to be copied ...
Read more >
highlightjs/highlight.js - GitHub
Highlight.js is a syntax highlighter written in JavaScript. It works in the browser as well as on the server. It can work with...
Read more >
Highlight.js - Trinker's R Blog
js highlights syntax in code examples on blogs, forums and, in fact, on any web page. It's very easy to use because it...
Read more >
highlight.js - Reviews, Pros & Cons - StackShare
See what developers are saying about how they use highlight.js. Check out popular companies that use highlight.js and some tools that integrate with ......
Read more >
SHJS - Syntax Highlighting in JavaScript
SHJS is a JavaScript program which highlights source code passages in HTML documents. Documents using SHJS are highlighted on the client side by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found