Skip to content

Commit

Permalink
Merge pull request #18 from tea3/master
Browse files Browse the repository at this point in the history
Choose entity decoding settings and Optimized h2 to h6 tag for Google Jump-links
  • Loading branch information
bubkoo authored Aug 9, 2017
2 parents 2f0c6fc + 7c9624c commit 60c6128
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ toc:
maxdepth: 3
class: toc
slugify: transliteration
decodeEntities: false
anchor:
position: after
symbol: '#'
Expand All @@ -39,6 +40,7 @@ toc:
- `maxdepth`: Use headings whose depth is at most maxdepth.
- `class`: The CSS Class for the toc. (*Default is `false`*)
- `slugify`: Choose which slugify function you want to use. Currently support [uslug](https://github.com/jeremys/uslug) (*Default*) and [transliteration](https://github.com/andyhu/node-transliteration).
- `decodeEntities`: Select whether to enable decode entities. ( *Default is `false`* and please see [#15](https://github.com/bubkoo/hexo-toc/pull/15)).
- `anchor`: Whether should have an anchor for each headings. (*Default is `false`*)
- `position`: Where should the anchor be, `before` the title, or `after` the title. (*Default is `after`*);
- `symbol`: Which symbol you want the anchor be. (*Default is `#`*);
Expand Down
8 changes: 6 additions & 2 deletions lib/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ exports.insert = function (data) {
exports.heading = function (data) {
var options = assign({}, this.config.toc);

var $ = cheerio.load(data.content, { decodeEntities: false });
var $ = cheerio.load(data.content, { decodeEntities: ( options.decodeEntities !== undefined ? options.decodeEntities : false ) });
var headings = $('h1, h2, h3, h4, h5, h6');

headings.each(function () {
var $title = $(this);
var title = $title.text();
var id = toc.slugify(title, options);
$title.attr('id', id);
// $title.attr('id', id);
$title.children('a').remove();
$title.html( '<span id="' + id + '">' + $title.html() + '</span>' );
$title.removeAttr('id');


if (options.anchor) {
var anchorOpts = assign(
Expand Down

0 comments on commit 60c6128

Please sign in to comment.