0

For what it's worth, I'm using angularjs and https://github.com/pc035860/angular-highlightjs. I want to know which language was detected and if there's any way to do this.

If this library doesn't do it, are there any that do?

Charles
  • 50,943
  • 13
  • 104
  • 142
Shamoon
  • 41,293
  • 91
  • 306
  • 570

1 Answers1

3

You could search for the hljs class with JavaScript and then find the language class associated with it (assuming the language class is the last class). Example with jQuery:

function findLanguageOfHLJSWithID(id) {
  var foundClasses = jQuery('#' + id + '.hljs').attr('class').split(' ');
  return foundClasses[foundClasses.length - 1];
}

If you want all the languages highlighted on the page, use this function:

function findAllHLJSLanguages() {
  var tempClasses = jQuery('.hljs'), foundClasses = [];
  for (var iter = 0; iter < tempClasses.length; iter++) {
    var tempClassesSplit = $(tempClasses[iter]).attr('class').split(' ');
    foundClasses.push(tempClassesSplit[tempClassesSplit.length - 1]);
  }
  return foundClasses;
}
rgajrawala
  • 2,148
  • 1
  • 22
  • 35