From 5ed395122d3862b1e5ed84784b4205d30a407849 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 7 Oct 2015 23:04:31 +0800 Subject: Support specify code block start line number --- public/js/extra.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index 3a0f006e..d6d8c029 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -471,11 +471,16 @@ function highlightRender(code, lang) { } else { var result = hljs.highlight(reallang, code); } - if (/\=$/.test(lang)) { + var showlinenumbers = /\=$|(\d+)$/.test(lang); + if (showlinenumbers) { + var startnumber = 1; + var matches = lang.match(/\=(\d+)$/); + if (matches) + startnumber = parseInt(matches[1]); var lines = result.value.split('\n'); var linenumbers = []; for (var i = 0; i < lines.length - 1; i++) { - linenumbers[i] = ""; + linenumbers[i] = ""; } var linegutter = "
" + linenumbers.join('\n') + "
"; result.value = "
" + linegutter + "
" + result.value + "
"; -- cgit v1.2.3