Full Code of bubkoo/hexo-toc for AI

master ee914c61fd69 cached
10 files
8.4 KB
2.6k tokens
1 requests
Download .txt
Repository: bubkoo/hexo-toc
Branch: master
Commit: ee914c61fd69
Files: 10
Total size: 8.4 KB

Directory structure:
gitextract_l8wzuhw_/

├── .editorconfig
├── .gitignore
├── .jshintrc
├── .npmignore
├── LICENSE
├── README.md
├── index.js
├── lib/
│   ├── filter.js
│   └── slugify.js
└── package.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .editorconfig
================================================
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true


# Set default charset
[*.js]
indent_style = space
indent_size = 2

[Makefile]
indent_style = tab
indent_size = 4

[*.md]
trim_trailing_whitespace = false


================================================
FILE: .gitignore
================================================
.idea
.DS_Store
node_modules
npm-debug.log
tmp


================================================
FILE: .jshintrc
================================================
{
  "curly": true,
  "eqeqeq": true,
  "immed": true,
  "newcap": true,
  "noarg": true,
  "sub": true,
  "undef": true,
  "boss": true,
  "eqnull": true,
  "node": true,
  "latedef": "nofunc"
}


================================================
FILE: .npmignore
================================================
.idea
.DS_Store
.editorconfig
.npmignore
.gitignore
.jshintrc
.jshintignore
Gruntfile.js
npm-debug.log
test
mock


================================================
FILE: LICENSE
================================================
The MIT License (MIT)

Copyright (c) 2015 bubkoo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



================================================
FILE: README.md
================================================
# hexo-toc

[![MIT License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square)](https://github.com/bubkoo/hexo-toc/blob/master/LICENSE)

[![npm:](https://img.shields.io/npm/v/hexo-toc.svg?style=flat-square)](https://www.npmjs.com/packages/hexo-toc)
[![Package Quality](http://npm.packagequality.com/shield/hexo-toc.svg)](http://packagequality.com/#?package=hexo-toc)

> Insert a markdown TOC(Table Of Content) before posts be rendered.

Unlike 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.

All you need to do is placing a placeholder(`<!-- toc -->`) in your post when and where needed.

**Note:** this plugin will not mangle your posts(markdown files), so you can use it bold.


## Install

```node
npm install hexo-toc --save
```

## Options

All the options of [markdown-toc](https://github.com/jonschlinkert/markdown-toc),
slugify function, and heading anchor options can be specified as follow in your `_config.yml`:

```yaml
toc:
  maxdepth: 3
  class: toc
  slugify: transliteration
  decodeEntities: false
  anchor:
    position: after
    symbol: '#'
    style: header-anchor
```

- `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 `#`*);
    - `style`: The CSS class for the anchor, (*Default is `header-anchor`*);

## Known issues

### [#8](https://github.com/bubkoo/hexo-toc/issues/8)

Working with [hexo-renderer-markdown-it](https://github.com/celsomiranda/hexo-renderer-markdown-it).

```yaml
# Markdown-it config
## Docs: https://github.com/celsomiranda/hexo-renderer-markdown-it/wiki
markdown:
  render:
    html: true
```

## Related
   
- [hexo-filter-fenced-code](https://github.com/bubkoo/hexo-filter-fenced-code) Extend syntax for the native fenced code block.
- [hexo-filter-flowchart](https://github.com/bubkoo/hexo-filter-flowchart) Generate flowchart diagrams for Hexo.
- [hexo-filter-sequence](https://github.com/bubkoo/hexo-filter-sequence) Generate UML sequence diagrams for Hexo.
- [hexo-filter-sub](https://github.com/bubkoo/hexo-filter-sub) Generate subscript (`<sub>`) tag for Hexo.
- [hexo-filter-sup](https://github.com/bubkoo/hexo-filter-sup) Generate superscript (`<sup>`) tag for Hexo.
- [hexo-theme-formula](https://github.com/bubkoo/hexo-theme-formula) Hexo theme base on jade and less. 

## Contributing

Pull requests and stars are highly welcome.

For bugs and feature requests, please [create an issue](https://github.com/bubkoo/hexo-toc/issues/new).


================================================
FILE: index.js
================================================
/* globals hexo: true */

var assign = require('object-assign');
var filter = require('./lib/filter');
var slugify = require('./lib/slugify');

var config = hexo.config.toc || {};
hexo.config.toc = assign({}, config, { slugify: slugify.load(config.slugify) });

hexo.extend.filter.register('before_post_render', filter.insert);
hexo.extend.filter.register('after_post_render', filter.heading);


================================================
FILE: lib/filter.js
================================================
var toc = require('markdown-toc');
var assign = require('object-assign');
var cheerio = require('cheerio');

exports.insert = function (data) {

  var options = assign({}, this.config.toc);

  // add class option
  if (options.class) {
    data.content = data.content.replace("<!-- toc -->", '<div class="' + options.class + 'Start"></div><!-- toc --><div class="' + options.class + 'End"></div>');
  }

  data.content = toc.insert(data.content, options);
  return data;
};

exports.heading = function (data) {
  var options = assign({}, this.config.toc);

  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.children('a').remove();
    $title.html( '<span id="' + id + '">' + $title.html() + '</span>' );
    $title.removeAttr('id');


    if (options.anchor) {
      var anchorOpts = assign(
        {
          position: 'after',
          symbol: '#',
          style: 'header-anchor'
        }, options.anchor);

      //  Put the anchor after the title by default, unless says otherwise
      var link = '<a href="#' + id + '" class="' + anchorOpts.style + '">' + anchorOpts.symbol + '</a>';
      if (anchorOpts.position === 'before') {
        $title.prepend(link);
      } else {
        $title.append(link);
      }
    }
  });

  data.content = $.html();

  // add class option
  if (options.class) {
    data.content = data.content.replace('<div class="' + options.class + 'Start"></div>', '<div class="' + options.class + '">').replace('<div class="' + options.class + 'End"></div>', '</div>');
  }

  return data;
};


================================================
FILE: lib/slugify.js
================================================
exports.load = function (name) {
  var slugify;
  if (name && typeof name === 'string') {
    switch (name) {
      case 'transliteration':
        slugify = require('transliteration').slugify;
        break;
      default:
        slugify = require('uslug');
        break;
    }
  } else {
    //  default is 'uslug'
    slugify = require('uslug');
  }
  return slugify;
};


================================================
FILE: package.json
================================================
{
  "name": "hexo-toc",
  "version": "1.1.0",
  "description": "Insert a markdown TOC(Table Of Content) before posts be rendered. ",
  "main": "index.js",
  "scripts": {
    "lint": "jshint index.js",
    "pretest": "npm run lint",
    "test": "echo ",
    "prepublish": "npm test"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/bubkoo/hexo-toc.git"
  },
  "keywords": [
    "hexo",
    "toc",
    "filter",
    "markdown"
  ],
  "author": {
    "name": "bubkoo.wy",
    "email": "bubkoo.wy@gmail.com"
  },
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/bubkoo/hexo-toc/issues"
  },
  "homepage": "https://github.com/bubkoo/hexo-toc",
  "dependencies": {
    "cheerio": "^0.19.0",
    "markdown-toc": "^0.12.12",
    "object-assign": "^4.0.1",
    "transliteration": "^1.1.7",
    "uslug": "^1.0.3"
  },
  "devDependencies": {
    "jshint": "^2.9.1"
  }
}
Download .txt
gitextract_l8wzuhw_/

├── .editorconfig
├── .gitignore
├── .jshintrc
├── .npmignore
├── LICENSE
├── README.md
├── index.js
├── lib/
│   ├── filter.js
│   └── slugify.js
└── package.json
Condensed preview — 10 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (9K chars).
[
  {
    "path": ".editorconfig",
    "chars": 402,
    "preview": "# EditorConfig is awesome: http://EditorConfig.org\n\n# top-most EditorConfig file\nroot = true\n\n# Unix-style newlines with"
  },
  {
    "path": ".gitignore",
    "chars": 47,
    "preview": ".idea\n.DS_Store\nnode_modules\nnpm-debug.log\ntmp\n"
  },
  {
    "path": ".jshintrc",
    "chars": 195,
    "preview": "{\n  \"curly\": true,\n  \"eqeqeq\": true,\n  \"immed\": true,\n  \"newcap\": true,\n  \"noarg\": true,\n  \"sub\": true,\n  \"undef\": true,"
  },
  {
    "path": ".npmignore",
    "chars": 113,
    "preview": ".idea\n.DS_Store\n.editorconfig\n.npmignore\n.gitignore\n.jshintrc\n.jshintignore\nGruntfile.js\nnpm-debug.log\ntest\nmock\n"
  },
  {
    "path": "LICENSE",
    "chars": 1074,
    "preview": "The MIT License (MIT)\n\nCopyright (c) 2015 bubkoo\n\nPermission is hereby granted, free of charge, to any person obtaining "
  },
  {
    "path": "README.md",
    "chars": 3283,
    "preview": "# hexo-toc\n\n[![MIT License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square)](https://githu"
  },
  {
    "path": "index.js",
    "chars": 394,
    "preview": "/* globals hexo: true */\n\nvar assign = require('object-assign');\nvar filter = require('./lib/filter');\nvar slugify = req"
  },
  {
    "path": "lib/filter.js",
    "chars": 1829,
    "preview": "var toc = require('markdown-toc');\nvar assign = require('object-assign');\nvar cheerio = require('cheerio');\n\nexports.ins"
  },
  {
    "path": "lib/slugify.js",
    "chars": 376,
    "preview": "exports.load = function (name) {\n  var slugify;\n  if (name && typeof name === 'string') {\n    switch (name) {\n      case"
  },
  {
    "path": "package.json",
    "chars": 898,
    "preview": "{\n  \"name\": \"hexo-toc\",\n  \"version\": \"1.1.0\",\n  \"description\": \"Insert a markdown TOC(Table Of Content) before posts be "
  }
]

About this extraction

This page contains the full source code of the bubkoo/hexo-toc GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 10 files (8.4 KB), approximately 2.6k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!