[
  {
    "path": ".editorconfig",
    "content": "# EditorConfig is awesome: http://EditorConfig.org\n\n# top-most EditorConfig file\nroot = true\n\n# Unix-style newlines with a newline ending every file\n[*]\nend_of_line = lf\ncharset = utf-8\ninsert_final_newline = true\ntrim_trailing_whitespace = true\n\n\n# Set default charset\n[*.js]\nindent_style = space\nindent_size = 2\n\n[Makefile]\nindent_style = tab\nindent_size = 4\n\n[*.md]\ntrim_trailing_whitespace = false\n"
  },
  {
    "path": ".gitignore",
    "content": ".idea\n.DS_Store\nnode_modules\nnpm-debug.log\ntmp\n"
  },
  {
    "path": ".jshintrc",
    "content": "{\n  \"curly\": true,\n  \"eqeqeq\": true,\n  \"immed\": true,\n  \"newcap\": true,\n  \"noarg\": true,\n  \"sub\": true,\n  \"undef\": true,\n  \"boss\": true,\n  \"eqnull\": true,\n  \"node\": true,\n  \"latedef\": \"nofunc\"\n}\n"
  },
  {
    "path": ".npmignore",
    "content": ".idea\n.DS_Store\n.editorconfig\n.npmignore\n.gitignore\n.jshintrc\n.jshintignore\nGruntfile.js\nnpm-debug.log\ntest\nmock\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2015 bubkoo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n"
  },
  {
    "path": "README.md",
    "content": "# hexo-toc\n\n[![MIT License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square)](https://github.com/bubkoo/hexo-toc/blob/master/LICENSE)\n\n[![npm:](https://img.shields.io/npm/v/hexo-toc.svg?style=flat-square)](https://www.npmjs.com/packages/hexo-toc)\n[![Package Quality](http://npm.packagequality.com/shield/hexo-toc.svg)](http://packagequality.com/#?package=hexo-toc)\n\n> Insert a markdown TOC(Table Of Content) before posts be rendered.\n\nUnlike the native [`toc`](http://hexo.io/docs/helpers.html#toc) helper, this plugin will inject a TOC only when a placeholder(`<!-- toc -->`) found in the raw markdown files. And the TOC will be injected after the placeholder.\n\nAll you need to do is placing a placeholder(`<!-- toc -->`) in your post when and where needed.\n\n**Note:** this plugin will not mangle your posts(markdown files), so you can use it bold.\n\n\n## Install\n\n```node\nnpm install hexo-toc --save\n```\n\n## Options\n\nAll the options of [markdown-toc](https://github.com/jonschlinkert/markdown-toc),\nslugify function, and heading anchor options can be specified as follow in your `_config.yml`:\n\n```yaml\ntoc:\n  maxdepth: 3\n  class: toc\n  slugify: transliteration\n  decodeEntities: false\n  anchor:\n    position: after\n    symbol: '#'\n    style: header-anchor\n```\n\n- `maxdepth`: Use headings whose depth is at most maxdepth.\n- `class`: The CSS Class for the toc. (*Default is `false`*)\n- `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).\n- `decodeEntities`: Select whether to enable decode entities. ( *Default is `false`* and please see [#15](https://github.com/bubkoo/hexo-toc/pull/15)).\n- `anchor`: Whether should have an anchor for each headings. (*Default is `false`*)\n    - `position`: Where should the anchor be, `before` the title, or `after` the title. (*Default is `after`*);\n    - `symbol`: Which symbol you want the anchor be. (*Default is `#`*);\n    - `style`: The CSS class for the anchor, (*Default is `header-anchor`*);\n\n## Known issues\n\n### [#8](https://github.com/bubkoo/hexo-toc/issues/8)\n\nWorking with [hexo-renderer-markdown-it](https://github.com/celsomiranda/hexo-renderer-markdown-it).\n\n```yaml\n# Markdown-it config\n## Docs: https://github.com/celsomiranda/hexo-renderer-markdown-it/wiki\nmarkdown:\n  render:\n    html: true\n```\n\n## Related\n   \n- [hexo-filter-fenced-code](https://github.com/bubkoo/hexo-filter-fenced-code) Extend syntax for the native fenced code block.\n- [hexo-filter-flowchart](https://github.com/bubkoo/hexo-filter-flowchart) Generate flowchart diagrams for Hexo.\n- [hexo-filter-sequence](https://github.com/bubkoo/hexo-filter-sequence) Generate UML sequence diagrams for Hexo.\n- [hexo-filter-sub](https://github.com/bubkoo/hexo-filter-sub) Generate subscript (`<sub>`) tag for Hexo.\n- [hexo-filter-sup](https://github.com/bubkoo/hexo-filter-sup) Generate superscript (`<sup>`) tag for Hexo.\n- [hexo-theme-formula](https://github.com/bubkoo/hexo-theme-formula) Hexo theme base on jade and less. \n\n## Contributing\n\nPull requests and stars are highly welcome.\n\nFor bugs and feature requests, please [create an issue](https://github.com/bubkoo/hexo-toc/issues/new).\n"
  },
  {
    "path": "index.js",
    "content": "/* globals hexo: true */\n\nvar assign = require('object-assign');\nvar filter = require('./lib/filter');\nvar slugify = require('./lib/slugify');\n\nvar config = hexo.config.toc || {};\nhexo.config.toc = assign({}, config, { slugify: slugify.load(config.slugify) });\n\nhexo.extend.filter.register('before_post_render', filter.insert);\nhexo.extend.filter.register('after_post_render', filter.heading);\n"
  },
  {
    "path": "lib/filter.js",
    "content": "var toc = require('markdown-toc');\nvar assign = require('object-assign');\nvar cheerio = require('cheerio');\n\nexports.insert = function (data) {\n\n  var options = assign({}, this.config.toc);\n\n  // add class option\n  if (options.class) {\n    data.content = data.content.replace(\"<!-- toc -->\", '<div class=\"' + options.class + 'Start\"></div><!-- toc --><div class=\"' + options.class + 'End\"></div>');\n  }\n\n  data.content = toc.insert(data.content, options);\n  return data;\n};\n\nexports.heading = function (data) {\n  var options = assign({}, this.config.toc);\n\n  var $ = cheerio.load(data.content, { decodeEntities: ( options.decodeEntities !== undefined ? options.decodeEntities : false ) });\n  var headings = $('h1, h2, h3, h4, h5, h6');\n\n  headings.each(function () {\n    var $title = $(this);\n    var title = $title.text();\n    var id = toc.slugify(title, options);\n    // $title.attr('id', id);\n    $title.children('a').remove();\n    $title.html( '<span id=\"' + id + '\">' + $title.html() + '</span>' );\n    $title.removeAttr('id');\n\n\n    if (options.anchor) {\n      var anchorOpts = assign(\n        {\n          position: 'after',\n          symbol: '#',\n          style: 'header-anchor'\n        }, options.anchor);\n\n      //  Put the anchor after the title by default, unless says otherwise\n      var link = '<a href=\"#' + id + '\" class=\"' + anchorOpts.style + '\">' + anchorOpts.symbol + '</a>';\n      if (anchorOpts.position === 'before') {\n        $title.prepend(link);\n      } else {\n        $title.append(link);\n      }\n    }\n  });\n\n  data.content = $.html();\n\n  // add class option\n  if (options.class) {\n    data.content = data.content.replace('<div class=\"' + options.class + 'Start\"></div>', '<div class=\"' + options.class + '\">').replace('<div class=\"' + options.class + 'End\"></div>', '</div>');\n  }\n\n  return data;\n};\n"
  },
  {
    "path": "lib/slugify.js",
    "content": "exports.load = function (name) {\n  var slugify;\n  if (name && typeof name === 'string') {\n    switch (name) {\n      case 'transliteration':\n        slugify = require('transliteration').slugify;\n        break;\n      default:\n        slugify = require('uslug');\n        break;\n    }\n  } else {\n    //  default is 'uslug'\n    slugify = require('uslug');\n  }\n  return slugify;\n};\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"hexo-toc\",\n  \"version\": \"1.1.0\",\n  \"description\": \"Insert a markdown TOC(Table Of Content) before posts be rendered. \",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"lint\": \"jshint index.js\",\n    \"pretest\": \"npm run lint\",\n    \"test\": \"echo \",\n    \"prepublish\": \"npm test\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"https://github.com/bubkoo/hexo-toc.git\"\n  },\n  \"keywords\": [\n    \"hexo\",\n    \"toc\",\n    \"filter\",\n    \"markdown\"\n  ],\n  \"author\": {\n    \"name\": \"bubkoo.wy\",\n    \"email\": \"bubkoo.wy@gmail.com\"\n  },\n  \"license\": \"MIT\",\n  \"bugs\": {\n    \"url\": \"https://github.com/bubkoo/hexo-toc/issues\"\n  },\n  \"homepage\": \"https://github.com/bubkoo/hexo-toc\",\n  \"dependencies\": {\n    \"cheerio\": \"^0.19.0\",\n    \"markdown-toc\": \"^0.12.12\",\n    \"object-assign\": \"^4.0.1\",\n    \"transliteration\": \"^1.1.7\",\n    \"uslug\": \"^1.0.3\"\n  },\n  \"devDependencies\": {\n    \"jshint\": \"^2.9.1\"\n  }\n}\n"
  }
]