Skip to content

Commit

Permalink
rename to syntax_highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Dec 13, 2022
1 parent 220819a commit 4e8acdd
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/extend/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Highlight {
exec(name, options) {
const fn = this.store[name];

if (!fn) throw new TypeError(`highlighter ${name} is not registered`);
if (!fn) throw new TypeError(`syntax highlighter ${name} is not registered`);
const ctx = options.context;
const args = options.args || [];

Expand Down
2 changes: 1 addition & 1 deletion lib/hexo/default_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
post_asset_folder: false,
relative_link: false,
future: true,
highlighter: 'highlight.js',
syntax_highlighter: 'highlight.js',
highlight: {
auto_detect: false,
line_number: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class Post {
}

const options = data.markdown || {};
if (!config.highlighter) options.highlight = null;
if (!config.syntax_highlighter) options.highlight = null;

ctx.log.debug('Rendering post: %s', magenta(source));
// Render with markdown or other renderer
Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/filter/before_post_render/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module.exports = ctx => {
return function backtickCodeBlock(data) {
const dataContent = data.content;

if ((!dataContent.includes('```') && !dataContent.includes('~~~')) || !ctx.extend.highlight.query(ctx.config.highlighter)) return;
if ((!dataContent.includes('```') && !dataContent.includes('~~~')) || !ctx.extend.highlight.query(ctx.config.syntax_highlighter)) return;

data.content = dataContent.replace(rBacktick, ($0, start, $2, _args, _content, end) => {
let content = _content.replace(/\n$/, '');

// neither highlight or prismjs is enabled, return escaped content directly.
if (!ctx.extend.highlight.query(ctx.config.highlighter)) return escapeSwigTag($0);
if (!ctx.extend.highlight.query(ctx.config.syntax_highlighter)) return escapeSwigTag($0);

// Extract language and caption of code blocks
const args = _args.split('=').shift();
Expand Down Expand Up @@ -58,7 +58,7 @@ module.exports = ctx => {
if (_args.includes('=')) {
options.firstLineNumber = _args.split('=')[1] || 1;
}
content = ctx.extend.highlight.exec(ctx.config.highlighter, {
content = ctx.extend.highlight.exec(ctx.config.syntax_highlighter, {
context: ctx,
args: [content, options]
});
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/tag/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function parseArgs(args) {
module.exports = ctx => function codeTag(args, content) {

// If neither highlight.js nor prism.js is enabled, return escaped code directly
if (!ctx.extend.highlight.query(ctx.config.highlighter)) {
if (!ctx.extend.highlight.query(ctx.config.syntax_highlighter)) {
return `<pre><code>${escapeHTML(content)}</code></pre>`;
}

Expand All @@ -140,7 +140,7 @@ module.exports = ctx => function codeTag(args, content) {

const options = parseArgs(args);
options.lines_length = content.split('\n').length;
content = ctx.extend.highlight.exec(ctx.config.highlighter, {
content = ctx.extend.highlight.exec(ctx.config.syntax_highlighter, {
context: ctx,
args: [content, options]
});
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/tag/include_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ module.exports = ctx => function includeCodeTag(args) {
const lines = code.split('\n');
code = lines.slice(from, to).join('\n').trim();

if (ctx.extend.highlight.query(ctx.config.highlighter)) {
if (ctx.extend.highlight.query(ctx.config.syntax_highlighter)) {
const options = {
lang,
caption,
lines_length: lines.length
};
return ctx.extend.highlight.exec(ctx.config.highlighter, {
return ctx.extend.highlight.exec(ctx.config.syntax_highlighter, {
context: ctx,
args: [code, options]
});
Expand Down
6 changes: 3 additions & 3 deletions test/scripts/filters/backtick_code_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Backtick code block', () => {

const data = {content};

hexo.config.highlighter = '';
hexo.config.syntax_highlighter = '';
codeBlock(data);
data.content.should.eql(content);
});
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('Backtick code block', () => {

describe('highlightjs', () => {
beforeEach(() => {
hexo.config.highlighter = 'highlight.js';
hexo.config.syntax_highlighter = 'highlight.js';
});

it('shorthand', () => {
Expand Down Expand Up @@ -507,7 +507,7 @@ describe('Backtick code block', () => {

describe('prismjs', () => {
beforeEach(() => {
hexo.config.highlighter = 'prismjs';
hexo.config.syntax_highlighter = 'prismjs';
});

it('default', () => {
Expand Down
12 changes: 6 additions & 6 deletions test/scripts/hexo/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ describe('Post', () => {
});

it('render() - shouln\'t break curly brackets', async () => {
hexo.config.highlighter = 'prismjs';
hexo.config.syntax_highlighter = 'prismjs';

const content = [
'\\begin{equation}',
Expand All @@ -930,7 +930,7 @@ describe('Post', () => {
data.content.should.include('\\begin{equation}');
data.content.should.include('\\end{equation}');

hexo.config.highlighter = 'highlight.js';
hexo.config.syntax_highlighter = 'highlight.js';
});

// #2321
Expand Down Expand Up @@ -1329,7 +1329,7 @@ describe('Post', () => {
});

it('render() - issue #4460', async () => {
hexo.config.highlighter = 'prismjs';
hexo.config.syntax_highlighter = 'prismjs';

const content = fixture.content_for_issue_4460;

Expand All @@ -1340,11 +1340,11 @@ describe('Post', () => {

data.content.should.not.include('hexoPostRenderEscape');

hexo.config.highlighter = 'highlight.js';
hexo.config.syntax_highlighter = 'highlight.js';
});

it('render() - empty tag name', async () => {
hexo.config.highlighter = 'prismjs';
hexo.config.syntax_highlighter = 'prismjs';

const content = 'Disable rendering of Nunjucks tag `{{ }}` / `{% %}`';

Expand All @@ -1356,6 +1356,6 @@ describe('Post', () => {
data.content.should.include(escapeSwigTag('{{ }}'));
data.content.should.include(escapeSwigTag('{% %}'));

hexo.config.highlighter = 'highlight.js';
hexo.config.syntax_highlighter = 'highlight.js';
});
});
10 changes: 5 additions & 5 deletions test/scripts/tags/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ describe('code', () => {
});

it('disabled', () => {
hexo.config.highlighter = '';
hexo.config.syntax_highlighter = '';

const result = code('', fixture);
result.should.eql('<pre><code>' + escapeHTML(fixture) + '</code></pre>');

hexo.config.highlighter = 'highlight.js';
hexo.config.syntax_highlighter = 'highlight.js';
});

it('first_line', () => {
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('code', () => {

describe('prismjs', () => {
beforeEach(() => {
hexo.config.highlighter = 'prismjs';
hexo.config.syntax_highlighter = 'prismjs';
});

it('default', () => {
Expand Down Expand Up @@ -246,12 +246,12 @@ describe('code', () => {
});

it('disabled', () => {
hexo.config.highlighter = '';
hexo.config.syntax_highlighter = '';

const result = code('', fixture);
result.should.eql('<pre><code>' + escapeHTML(fixture) + '</code></pre>');

hexo.config.highlighter = 'highlight.js';
hexo.config.syntax_highlighter = 'highlight.js';
});

it('first_line', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/scripts/tags/include_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('include_code', () => {

describe('highlightjs', () => {
it('default', async () => {
hexo.config.highlighter = 'highlight.js';
hexo.config.syntax_highlighter = 'highlight.js';

const expected = highlight(fixture, {
lang: 'js',
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('include_code', () => {
});

it('disabled', async () => {
hexo.config.highlighter = '';
hexo.config.syntax_highlighter = '';

const result = await code('test.js');
result.should.eql('<pre><code>' + fixture + '</code></pre>');
Expand All @@ -133,7 +133,7 @@ describe('include_code', () => {

describe('prismjs', () => {
beforeEach(() => {
hexo.config.highlighter = 'prismjs';
hexo.config.syntax_highlighter = 'prismjs';
});

it('default', async () => {
Expand Down Expand Up @@ -212,7 +212,7 @@ describe('include_code', () => {
});

it('disabled', async () => {
hexo.config.highlighter = '';
hexo.config.syntax_highlighter = '';

const result = await code('test.js');
result.should.eql('<pre><code>' + fixture + '</code></pre>');
Expand Down

0 comments on commit 4e8acdd

Please sign in to comment.