Вопрос

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?

Это было полезно?

Решение

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;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top