Skip to content

Commit

Permalink
Add option to disable headerIds
Browse files Browse the repository at this point in the history
(Enabled by default for backward compatibility)
#61
  • Loading branch information
tomap committed Aug 2, 2019
1 parent 483d99d commit 91acb1b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ hexo.config.marked = Object.assign({
smartypants: true,
modifyAnchors: '',
autolink: true,
sanitizeUrl: false
sanitizeUrl: false,
headerIds: true
}, hexo.config.marked);

hexo.extend.renderer.register('md', 'html', renderer, true);
Expand Down
4 changes: 4 additions & 0 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ require('util').inherits(Renderer, MarkedRenderer);

// Add id attribute to headings
Renderer.prototype.heading = function(text, level) {
if (!this.options.headerIds) {
return `<h${level}>${text}</h${level}>`;
}

const transformOption = this.options.modifyAnchors;
let id = anchorId(stripHTML(text), transformOption);
const headingId = this._headingId;
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ describe('Marked renderer', () => {
result.should.eql('<h1 id="中文"><a href="#中文" class="headerlink" title="中文"></a>中文</h1>');
});

it('should render headings without headerIds when disabled', () => {
const body = '## hexo-server';
ctx.config.marked.headerIds = false;

const result = r({text: body});

result.should.eql([
'<h2>hexo-server</h2>'
].join(''));
});

// Description List tests

it('should render description lists with a single space after the colon', () => {
Expand Down

0 comments on commit 91acb1b

Please sign in to comment.