├── .editorconfig ├── .eslintrc.yml ├── .gitattributes ├── .github └── workflows │ └── CI-CD.yaml ├── .gitignore ├── .mocharc.yml ├── .nycrc.yml ├── .vscode ├── launch.json └── tasks.json ├── 404.md ├── CHANGELOG.md ├── LICENSE ├── README.md ├── _config.yml ├── dist ├── index.d.ts ├── index.js └── package.json ├── package-lock.json ├── package.json ├── src ├── create-toc.ts ├── customization-hooks.ts ├── fiind-headings.ts ├── find-main-node.ts ├── get-inner-text.ts ├── index.ts ├── insert-toc.ts ├── options.ts ├── rehype-toc.ts ├── type-guards.ts └── types.ts ├── test ├── specs │ ├── css-classes.spec.js │ ├── customize-toc-item.spec.js │ ├── customize-toc.spec.js │ ├── defaults.spec.js │ ├── empty.spec.js │ ├── exports.spec.js │ ├── headings.spec.js │ ├── nav.spec.js │ ├── position.spec.js │ └── special.spec.js └── utils │ ├── compare.js │ └── process.js └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor config 2 | # http://EditorConfig.org 3 | 4 | # This EditorConfig overrides any parent EditorConfigs 5 | root = true 6 | 7 | # Default rules applied to all file types 8 | [*] 9 | 10 | # No trailing spaces, newline at EOF 11 | charset = utf-8 12 | trim_trailing_whitespace = true 13 | insert_final_newline = true 14 | end_of_line = lf 15 | 16 | # 2 space indentation 17 | indent_style = space 18 | indent_size = 2 19 | 20 | # JavaScript-specific settings 21 | [*.{js,ts}] 22 | quote_type = double 23 | continuation_indent_size = 2 24 | curly_bracket_next_line = false 25 | indent_brace_style = BSD 26 | spaces_around_operators = true 27 | spaces_around_brackets = none 28 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | # ESLint config 2 | # http://eslint.org/docs/user-guide/configuring 3 | # https://jstools.dev/eslint-config/ 4 | 5 | root: true 6 | extends: "@jsdevtools" 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Git attributes 2 | # https://git-scm.com/docs/gitattributes 3 | # https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes 4 | 5 | # Normalize line endings for all files that git determines to be text. 6 | # https://git-scm.com/docs/gitattributes#gitattributes-Settostringvalueauto 7 | * text=auto 8 | 9 | # Normalize line endings to LF on checkin, and do NOT convert to CRLF when checking-out on Windows. 10 | # https://git-scm.com/docs/gitattributes#gitattributes-Settostringvaluelf 11 | *.txt text eol=lf 12 | *.html text eol=lf 13 | *.md text eol=lf 14 | *.css text eol=lf 15 | *.scss text eol=lf 16 | *.map text eol=lf 17 | *.js text eol=lf 18 | *.jsx text eol=lf 19 | *.ts text eol=lf 20 | *.tsx text eol=lf 21 | *.json text eol=lf 22 | *.yml text eol=lf 23 | *.yaml text eol=lf 24 | *.xml text eol=lf 25 | *.svg text eol=lf 26 | -------------------------------------------------------------------------------- /.github/workflows/CI-CD.yaml: -------------------------------------------------------------------------------- 1 | # GitHub Actions workflow 2 | # https://help.github.com/en/actions/automating-your-workflow-with-github-actions 3 | # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions 4 | # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions 5 | 6 | name: CI-CD 7 | 8 | on: 9 | push: 10 | branches: 11 | - "*" 12 | tags-ignore: 13 | - "*" 14 | 15 | schedule: 16 | - cron: "0 0 1 * *" 17 | 18 | jobs: 19 | test: 20 | name: Node ${{ matrix.node }} on ${{ matrix.os }} 21 | runs-on: ${{ matrix.os }} 22 | timeout-minutes: 10 23 | strategy: 24 | fail-fast: true 25 | matrix: 26 | os: 27 | - ubuntu-latest 28 | - macos-latest 29 | - windows-latest 30 | node: 31 | - 10 32 | - 12 33 | 34 | steps: 35 | - name: Checkout source 36 | uses: actions/checkout@v2 37 | 38 | - name: Install Node ${{ matrix.node }} 39 | uses: actions/setup-node@v1 40 | with: 41 | node-version: ${{ matrix.node }} 42 | 43 | - name: Install dependencies 44 | run: npm ci 45 | 46 | - name: Run linters 47 | run: npm run lint 48 | 49 | - name: Build the code 50 | run: npm run build 51 | 52 | - name: Run tests 53 | run: npm run coverage 54 | 55 | - name: Send code coverage results to Coveralls 56 | uses: coverallsapp/github-action@v1.1.0 57 | with: 58 | github-token: ${{ secrets.GITHUB_TOKEN }} 59 | parallel: true 60 | 61 | coverage: 62 | name: Code Coverage 63 | runs-on: ubuntu-latest 64 | timeout-minutes: 10 65 | needs: test 66 | steps: 67 | - name: Let Coveralls know that all tests have finished 68 | uses: coverallsapp/github-action@v1.1.0 69 | with: 70 | github-token: ${{ secrets.GITHUB_TOKEN }} 71 | parallel-finished: true 72 | 73 | deploy: 74 | name: Publish to NPM 75 | if: github.ref == 'refs/heads/master' 76 | runs-on: ubuntu-latest 77 | timeout-minutes: 10 78 | needs: test 79 | 80 | steps: 81 | - name: Checkout source 82 | uses: actions/checkout@v2 83 | 84 | - name: Install Node 85 | uses: actions/setup-node@v1 86 | 87 | - name: Install dependencies 88 | run: npm ci 89 | 90 | - name: Build the code 91 | run: npm run build 92 | 93 | - name: Publish to NPM 94 | uses: JS-DevTools/npm-publish@v1 95 | with: 96 | token: ${{ secrets.NPM_TOKEN }} 97 | 98 | - name: Prepare the non-scoped packaged 99 | run: | 100 | cp LICENSE *.md dist 101 | VERSION=$(node -e "console.log(require('./package.json').version)") 102 | sed -i "s/X.X.X/${VERSION}/g" dist/package.json 103 | 104 | - name: Publish the non-scoped package to NPM 105 | uses: JS-DevTools/npm-publish@v1 106 | with: 107 | token: ${{ secrets.NPM_TOKEN }} 108 | package: dist/package.json 109 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Git ignore 2 | # https://git-scm.com/docs/gitignore 3 | 4 | # Miscellaneous 5 | *~ 6 | *# 7 | .DS_STORE 8 | Thumbs.db 9 | .netbeans 10 | nbproject 11 | .node_history 12 | 13 | # IDEs & Text Editors 14 | .idea 15 | .sublime-* 16 | .vscode/settings.json 17 | .netbeans 18 | nbproject 19 | 20 | # Temporary files 21 | .tmp 22 | .temp 23 | .grunt 24 | .lock-wscript 25 | 26 | # Logs 27 | /logs 28 | *.log 29 | 30 | # Runtime data 31 | pids 32 | *.pid 33 | *.seed 34 | 35 | # Dependencies 36 | node_modules 37 | 38 | # Build output 39 | /lib 40 | 41 | # Test output 42 | /.nyc_output 43 | /coverage 44 | -------------------------------------------------------------------------------- /.mocharc.yml: -------------------------------------------------------------------------------- 1 | # Mocha options 2 | # https://mochajs.org/#configuring-mocha-nodejs 3 | # https://github.com/mochajs/mocha/blob/master/example/config/.mocharc.yml 4 | 5 | spec: test/specs/**/*.spec.js 6 | 7 | bail: true 8 | recursive: true 9 | -------------------------------------------------------------------------------- /.nycrc.yml: -------------------------------------------------------------------------------- 1 | # NYC config 2 | # https://github.com/istanbuljs/nyc#configuration-files 3 | 4 | extension: 5 | - .js 6 | - .ts 7 | 8 | reporter: 9 | - text 10 | - lcov 11 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // VSCode Launch Configuration 2 | // https://code.visualstudio.com/docs/editor/debugging#_launch-configurations 3 | 4 | // Available variables which can be used inside of strings. 5 | // ${workspaceRoot}: the root folder of the team 6 | // ${file}: the current opened file 7 | // ${fileBasename}: the current opened file's basename 8 | // ${fileDirname}: the current opened file's dirname 9 | // ${fileExtname}: the current opened file's extension 10 | // ${cwd}: the current working directory of the spawned process 11 | 12 | { 13 | "version": "0.2.0", 14 | "configurations": [ 15 | { 16 | "type": "node", 17 | "request": "launch", 18 | "name": "Run Mocha", 19 | "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", 20 | "args": [ 21 | "--timeout=60000", 22 | "--retries=0", 23 | ], 24 | "outFiles": [ 25 | "${workspaceFolder}/lib/**/*.js" 26 | ], 27 | "smartStep": true, 28 | "skipFiles": [ 29 | "/**/*.js" 30 | ], 31 | }, 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // VSCode Tasks 2 | // https://code.visualstudio.com/docs/editor/tasks 3 | 4 | // Available variables which can be used inside of strings. 5 | // ${workspaceRoot}: the root folder of the team 6 | // ${file}: the current opened file 7 | // ${fileBasename}: the current opened file's basename 8 | // ${fileDirname}: the current opened file's dirname 9 | // ${fileExtname}: the current opened file's extension 10 | // ${cwd}: the current working directory of the spawned process 11 | 12 | { 13 | "version": "2.0.0", 14 | "command": "npm", 15 | "tasks": [ 16 | { 17 | "type": "npm", 18 | "script": "build", 19 | "group": { 20 | "kind": "build", 21 | "isDefault": true 22 | }, 23 | "problemMatcher": "$tsc" 24 | }, 25 | 26 | 27 | { 28 | "type": "npm", 29 | "script": "test", 30 | "group": { 31 | "kind": "test", 32 | "isDefault": true 33 | }, 34 | }, 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /404.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: 404 3 | --- 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ==================================================================================================== 3 | All notable changes will be documented in this file. 4 | Rehype TOC adheres to [Semantic Versioning](http://semver.org/). 5 | 6 | 7 | [v3.0.0](https://github.com/JS-DevTools/rehype-toc/tree/v3.0.0) (2020-02-17) 8 | ---------------------------------------------------------------------------------------------------- 9 | 10 | - Moved Rehype TOC to the [@JSDevTools scope](https://www.npmjs.com/org/jsdevtools) on NPM 11 | 12 | - The "rehype-toc" NPM package is now just a wrapper around the scoped "@jsdevtools/rehype-toc" package 13 | 14 | [Full Changelog](https://github.com/JS-DevTools/rehype-toc/compare/v2.1.0...v3.0.0) 15 | 16 | 17 | [v2.2.0](https://github.com/JS-DevTools/rehype-toc/tree/v2.2.0) (2019-07-31) 18 | ---------------------------------------------------------------------------------------------------- 19 | 20 | - Added a new `customizeTOCItem` option that allows you to customize each item in the table-of-contents before it's added to the page 21 | 22 | [Full Changelog](https://github.com/JS-DevTools/rehype-toc/compare/v2.1.0...v2.2.0) 23 | 24 | 25 | [v2.1.0](https://github.com/JS-DevTools/rehype-toc/tree/v2.1.0) (2019-07-11) 26 | ---------------------------------------------------------------------------------------------------- 27 | 28 | - Added a new `position` option that allows control over where the table-of-contents is inserted into the document 29 | 30 | [Full Changelog](https://github.com/JS-DevTools/rehype-toc/compare/v2.0.0...v2.1.0) 31 | 32 | 33 | [v2.0.0](https://github.com/JS-DevTools/rehype-toc/tree/v2.0.0) (2019-07-10) 34 | ---------------------------------------------------------------------------------------------------- 35 | 36 | ### Breaking Changes 37 | 38 | - The table of contents is now wrapped in a `