Skip to content

Instantly share code, notes, and snippets.

@inem
Last active October 6, 2017 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inem/602d8d2477a4c34791aa93f5c4a64553 to your computer and use it in GitHub Desktop.
Save inem/602d8d2477a4c34791aa93f5c4a64553 to your computer and use it in GitHub Desktop.
hightlighter = function(formula){
formula.split(";").forEach(function(part){
elements = part.trim().split(")");
pre_number = elements[0].trim() - 1;
line_numbers = elements[1].trim().split(",");
$.each(line_numbers, function(i, v) {
index = v - 1;
// тулза которая подсвечивает код, оборачивает все в тройной pre, отсюда такая длинная колбаса
$("pre.highlight:eq("+ pre_number +") pre:eq(1) span.line:eq("+ index +")").addClass('emphasis');
});
})
}
$(function() {
# оборачивает каждую строку внутри всех pre в "span.line"
$('pre.highlight pre').each(function(i){
pre = $(this)
var txt = pre.html().split("\n");
var output = "";
for(var x=0;x<txt.length-1;x++) {
output = output + "<span class='line'>"+txt[x]+"</span>\n";
}
pre.html(output);
});
// За скобкой номер блока с кодом на странице, через запятую номера строк для подсветки внутри этого блока
hightlighter("1) 1,2; 2) 1,2,3,6,10; 3) 4");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment