Highlight.js: Provide a class for prompt in bash

Created on 5 Apr 2017  路  3Comments  路  Source: highlightjs/highlight.js

Currently, when using highlight.js to highlight a bash script, and you use the $ or # signs to present a command prompt, it is possible to select those characters. It would be great if one could disable them (which is not hard by using some CSS).

Anyway, for this it would be extremely helpful if those two characters would be given a special CSS class, if they are on the beginning of the line. I have seen in the definition for BASIC that is pretty simple, so basically all one needs to do is to add the appropriate regular expression to the bash definition:

{
  // Match command prompt
  className: 'symbol',
  begin: '^\$ |#\ ',
  relevance: 10
},

I would like to send a PR for that, but I am unsure about a few things:

  • Are there any tests that I need to update?
  • Can I use an arbitrary class name for this (think command-prompt) or are they defined somewhere?
  • Which relevance should I choose?

Most helpful comment

Okay, we solved it differently: When you use shell, everything works as expected.

So, we use bash for actual scripts, and shell for the terminal, and we are fine with this.

All 3 comments

Okay, I have found the list of class names by myself, but this now brings up the question which class to use?

Okay, we solved it differently: When you use shell, everything works as expected.

So, we use bash for actual scripts, and shell for the terminal, and we are fine with this.

The language names/codes supported by highlight.js are now here: https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

alainbryden picture alainbryden  路  4Comments

vladshcherbin picture vladshcherbin  路  5Comments

gka picture gka  路  7Comments

zhouxy666 picture zhouxy666  路  3Comments