Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disableNunjucks option #166

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ marked:
enable: false
exclude: []
nofollow: false
disableNunjucks: false
```

- **gfm** - Enables [GitHub flavored markdown](https://help.github.com/articles/github-flavored-markdown)
Expand Down Expand Up @@ -72,6 +73,7 @@ marked:
- Example: `[foo](http://bar.com)` becomes `<a href="http://bar.com" target="_blank" rel="noopener">foo</a>`
* **nofollow** - Add `rel="noopener external nofollow noreferrer"` to all external links for security, privacy and SEO. [Read more](https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types). _This can be enabled regardless of `external_link.enable`_
- Example: `[foo](http://bar.com)` becomes `<a href="http://bar.com" rel="noopener external nofollow noreferrer">foo</a>`
- **disableNunjucks**: If true, Nunjucks tags `{{ }}` or `{% %}` (usually used by [tag plugins](https://hexo.io/docs/tag-plugins)) will not be rendered.

## Extras

Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ hexo.config.marked = Object.assign({
}
}, hexo.config.marked);

renderer.disableNunjucks = Boolean(hexo.config.marked.disableNunjucks);

hexo.extend.renderer.register('md', 'html', renderer, true);
hexo.extend.renderer.register('markdown', 'html', renderer, true);
hexo.extend.renderer.register('mkd', 'html', renderer, true);
Expand Down
27 changes: 27 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,4 +812,31 @@ describe('Marked renderer', () => {
].join('\n'));
});
});

describe('nunjucks', () => {
const hexo = new Hexo(__dirname, { silent: true });
const loremFn = () => { return 'ipsum'; };
const engine = 'md';

before(async () => {
await hexo.init();
hexo.extend.tag.register('lorem', loremFn);
hexo.extend.renderer.register('md', 'html', require('../lib/renderer'));
});

beforeEach(() => { hexo.config.marked = {}; });

it('default', async () => {
const result = await hexo.post.render(null, { content: '**foo** {% lorem %}', engine });
result.content.should.eql('<p><strong>foo</strong> ipsum</p>\n');
});

it('enable disableNunjucks', async () => {
const renderer = hexo.render.renderer.get('md');
renderer.disableNunjucks = true;
hexo.extend.renderer.register('md', 'html', renderer);
const result = await hexo.post.render(null, { content: '**foo** {% lorem %}', engine });
result.content.should.eql('<p><strong>foo</strong> {% lorem %}</p>\n');
});
});
});