Skip to content

Commit

Permalink
feat: support renderInline (#198)
Browse files Browse the repository at this point in the history
* feat: support renderInline

* test: add render inline

---------

Co-authored-by: Zhang Visper <visper.zhang@liulishuo.com>
  • Loading branch information
coolzjy and Zhang Visper committed May 27, 2023
1 parent 7fba76c commit 243c560
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/renderer.js
Expand Up @@ -56,6 +56,12 @@ class Renderer {

render(data, options) {
this.hexo.execFilterSync('markdown-it:renderer', this.parser, { context: this });

if (options != null && options.inline === true) {
return this.parser.renderInline(data.text, {
postPath: data.path
});
}
return this.parser.render(data.text, {
postPath: data.path
});
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Expand Up @@ -110,6 +110,15 @@ describe('Hexo Renderer Markdown-it', () => {
const result = renderer.parser.render(text);
result.should.eql('<pre><code class="lang-js">example\n</code></pre>\n');
});

it('render inline', () => {
const text = 'inline text';
const renderer = new Renderer(hexo);
const resultBlock = renderer.render({ text });
const resultInline = renderer.render({ text }, { inline: true });
resultBlock.should.eql('<p>inline text</p>\n');
resultInline.should.eql('inline text');
})
});

describe('plugins', () => {
Expand Down

0 comments on commit 243c560

Please sign in to comment.