I don't believe there's a built-in solution, but here's a function that should do the trick. It uses the getElementsByClassName
method so I don't think it works on IE8 or below. Use your favorite DOM query library if you wish.
/**
* Returns the number of lines in a SyntaxHighlighter code block.
*
* @param {Element} node The top-level DOM element containing the code block.
* @return {Number} The number of code lines, or 0 if not found.
*/
function getLineCount(node) {
var codeNode;
var containerNode;
if (node && typeof node.getElementsByClassName === 'function') {
codeNode = node.getElementsByClassName('code');
if (codeNode.length) {
containerNode = codeNode[0].getElementsByClassName('container');
if (containerNode.length) {
return containerNode[0].children.length;
}
}
}
return 0;
}
jQuery version, because apparently that's a thing.
function getLineCount(node) {
return $(node).find('.code .container').children().length;
}