From f23369ea9f098cbb6ad168fe13cd53979cc5ec9c Mon Sep 17 00:00:00 2001
From: Wu Cheng-Han
Date: Thu, 22 Oct 2015 17:15:44 +0800
Subject: Support specify or continue line number in code blocks
---
public/js/extra.js | 19 +++++++++++++++----
public/js/syncscroll.js | 2 +-
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/public/js/extra.js b/public/js/extra.js
index d6d8c029..26762dde 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -210,6 +210,16 @@ function postProcess(code) {
});
//link should open in new window or tab
result.find('a:not([target])').attr('target', '_blank');
+ //update continue line numbers
+ var linenumberdivs = result.find('.gutter.linenumber').toArray();
+ for (var i = 0; i < linenumberdivs.length; i++) {
+ if ($(linenumberdivs[i]).hasClass('continue')) {
+ var startnumber = linenumberdivs[i - 1] ? parseInt($(linenumberdivs[i - 1]).find('> span').last().attr('data-linenumber')) : 0;
+ $(linenumberdivs[i]).find('> span').each(function(key, value) {
+ $(value).attr('data-linenumber', startnumber + key + 1);
+ });
+ }
+ }
return result;
}
@@ -464,14 +474,14 @@ function highlightRender(code, lang) {
} else if (lang == 'flow') {
return '
' + code + '
';
}
- var reallang = lang.replace('=', '');
+ var reallang = lang.replace(/\=$|\=\d+$|\=\+$/, '');
var languages = hljs.listLanguages();
if (languages.indexOf(reallang) == -1) {
var result = hljs.highlightAuto(code);
} else {
var result = hljs.highlight(reallang, code);
}
- var showlinenumbers = /\=$|(\d+)$/.test(lang);
+ var showlinenumbers = /\=$|\=\d+$|\=\+$/.test(lang);
if (showlinenumbers) {
var startnumber = 1;
var matches = lang.match(/\=(\d+)$/);
@@ -482,7 +492,8 @@ function highlightRender(code, lang) {
for (var i = 0; i < lines.length - 1; i++) {
linenumbers[i] = "";
}
- var linegutter = "" + linenumbers.join('\n') + "
";
+ var continuelinenumber = /\=\+$/.test(lang);
+ var linegutter = "" + linenumbers.join('\n') + "
";
result.value = "" + linegutter + "
" + result.value + "
";
}
return result.value;
@@ -541,7 +552,7 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) {
}
langName = Remarkable.utils.escapeHtml(Remarkable.utils.replaceEntities(Remarkable.utils.unescapeMd(fenceName)));
- langClass = ' class="' + langPrefix + langName.replace('=', '') + ' hljs"';
+ langClass = ' class="' + langPrefix + langName.replace(/\=$|\=\d+$|\=\+$/, '') + ' hljs"';
}
if (options.highlight) {
diff --git a/public/js/syncscroll.js b/public/js/syncscroll.js
index 8ca9f845..faa6a6a4 100644
--- a/public/js/syncscroll.js
+++ b/public/js/syncscroll.js
@@ -102,7 +102,7 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) {
}
langName = Remarkable.utils.escapeHtml(Remarkable.utils.replaceEntities(Remarkable.utils.unescapeMd(fenceName)));
- langClass = ' class="' + langPrefix + langName.replace('=', '') + ' hljs"';
+ langClass = ' class="' + langPrefix + langName.replace(/\=$|\=\d+$|\=\+$/, '') + ' hljs"';
}
if (options.highlight) {
--
cgit v1.2.3