diff options
author | Wu Cheng-Han | 2015-10-07 23:04:31 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2015-10-07 23:04:31 +0800 |
commit | 5ed395122d3862b1e5ed84784b4205d30a407849 (patch) | |
tree | ca836727c8fdf40cb2ebf1f13b46bca08eefe78a /public | |
parent | 8a4ad57f6aaeccbacfd7fc296232822eb6d2ffc5 (diff) |
Support specify code block start line number
Diffstat (limited to '')
-rw-r--r-- | public/js/extra.js | 9 |
1 files changed, 7 insertions, 2 deletions
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] = "<span data-linenumber='" + (i + 1) + "'></span>"; + linenumbers[i] = "<span data-linenumber='" + (startnumber + i) + "'></span>"; } var linegutter = "<div class='gutter linenumber'>" + linenumbers.join('\n') + "</div>"; result.value = "<div class='wrapper'>" + linegutter + "<div class='code'>" + result.value + "</div></div>"; |