diff --git a/lib/highlight.js b/lib/highlight.js
index 132004d3..b267fbaa 100644
--- a/lib/highlight.js
+++ b/lib/highlight.js
@@ -85,15 +85,7 @@ function formatLine(line, lineno, marked, options, wrap) {
}
function replaceTabs(str, tab) {
- return str.replace(/^\t+/, match => {
- let result = '';
-
- for (let i = 0, len = match.length; i < len; i++) {
- result += tab;
- }
-
- return result;
- });
+ return str.replace(/\t+/, match => tab.repeat(match.length));
}
function highlight(str, options) {
diff --git a/lib/prism.js b/lib/prism.js
index 7201f2ca..c6ed45ce 100644
--- a/lib/prism.js
+++ b/lib/prism.js
@@ -41,15 +41,7 @@ function lineNumberUtil(code) {
}
function replaceTabs(str, tab) {
- return str.replace(/^\t+/gm, match => {
- let result = '';
-
- for (let i = 0, len = match.length; i < len; i++) {
- result += tab;
- }
-
- return result;
- });
+ return str.replace(/^\t+/gm, match => tab.repeat(match.length));
}
function PrismUtil(str, options = {}) {
diff --git a/test/highlight.spec.js b/test/highlight.spec.js
index 86442389..6e215c0e 100644
--- a/test/highlight.spec.js
+++ b/test/highlight.spec.js
@@ -145,7 +145,7 @@ describe('highlight', () => {
'
',
hljs.highlight(testString, {
language: 'json'
- }).value.replace('{', '{'),
+ }).value.replace('{', '{'),
'
'
].join(''));
validateHtmlAsync(result, done);
@@ -290,12 +290,21 @@ describe('highlight', () => {
result.should.eql([
'',
gutter(1, 1),
- code('<node><?php echo "foo"; ?></node>', null),
+ code('<node><?php echo "foo"; ?></node>', null),
end
].join(''));
validateHtmlAsync(result, done);
});
+ // https://github.com/hexojs/hexo/issues/4726
+ it('highlight sublanguages with tab', done => {
+ const spaces = ' ';
+ const str = '';
+ const result = highlight(str, { tab: spaces, autoDetect: true });
+ result.should.not.include('\t');
+ validateHtmlAsync(result, done);
+ });
+
it('parse multi-line strings correctly', done => {
const str = [
'var string = `',
@@ -383,7 +392,7 @@ describe('highlight', () => {
result.should.include(gutterStart);
result.should.include(codeStart);
result.should.include('code class="hljs javascript"');
- result.should.include('class="hljs-function"');
+ result.should.include('class="hljs-keyword"');
result.should.include(gutter(1, 5));
validateHtmlAsync(result, done);
});
@@ -400,7 +409,7 @@ describe('highlight', () => {
result.should.not.include(gutterStart);
result.should.not.include(codeStart);
result.should.include('code class="hljs javascript"');
- result.should.include('class="hljs-function"');
+ result.should.include('class="hljs-keyword"');
validateHtmlAsync(result, done);
});
@@ -416,7 +425,7 @@ describe('highlight', () => {
result.should.not.include(gutterStart);
result.should.include(codeStart);
result.should.include('code class="hljs javascript"');
- result.should.include('class="hljs-function"');
+ result.should.include('class="hljs-keyword"');
validateHtmlAsync(result, done);
});
});