Repository: nagaozen/markdown-it-toc-done-right Branch: master Commit: 0a9fe6d2a025 Files: 19 Total size: 326.2 KB Directory structure: gitextract_7ufm1b_1/ ├── .eslintignore ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── __test__/ │ └── test.js ├── demo.html ├── dist/ │ ├── markdownItTocDoneRight.js │ ├── markdownItTocDoneRight.mjs │ ├── markdownItTocDoneRight.modern.js │ └── markdownItTocDoneRight.umd.js ├── index.js ├── package.json ├── runkit.js ├── tdd.helper.html ├── types/ │ └── index.d.ts └── uslug.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintignore ================================================ node_modules coverage dist lib ================================================ FILE: .gitignore ================================================ node_modules coverage ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - "12" - "14" after_success: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" cache: directories: - "node_modules" ================================================ FILE: CHANGELOG.md ================================================ # Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [4.2.0] - 2020-11-19 ### Added - implemented `uniqueSlugStartIndex` ## [4.1.0] - 2019-10-17 ### Added - accept options in the placeholder [#16](https://github.com/nagaozen/markdown-it-toc-done-right/issues/16) - `callback` option [#18](https://github.com/nagaozen/markdown-it-toc-done-right/issues/18) ### Changed - fixed [#20](https://github.com/nagaozen/markdown-it-toc-done-right/issues/20) - fixed [#22](https://github.com/nagaozen/markdown-it-toc-done-right/issues/22) - `test.js` to match the changes from `markdown-it-anchor` - `headings2ast` removed options dependency (will generate a tree with all headings) - `ast2html` modified to hold and apply almost all options, making `inlineOptions` possible ## [4.0.2] - 2019-07-11 ### Changed - fixed [#14](https://github.com/nagaozen/markdown-it-toc-done-right/issues/14) - updated dependencies, especially microbundle. Fix [#12](https://github.com/nagaozen/markdown-it-toc-done-right/issues/12)? - executed `npm audit fix --force` to fix dependencies vunerabilities ## [4.0.1] - 2019-06-03 ### Changed - executed `npm audit fix --force` to fix dependencies vunerabilities ## [4.0.0] - 2019-05-19 ### Changed - browser global changed from `markdownitTocDoneRight` to `markdownItTocDoneRight` - filename changed from `markdown-it-toc-made-right.min.js` to `markdownItTocDoneRight.umd.js` ### Removed - `babel` - `babelify` - `browserify` - `eslint` - `uglify` ### Added - `microbundle` - `standard` ## [3.0.0] - 2019-03-18 ### Added - `listClass`, `itemClass` and `linkClass` options. ### Changed - placeholder as a regular expression pattern ## [2.1.0] - 2019-02-23 ### Added - `level` option. Default is 1 - test for using `level` option ### Changed - update `demo.html` to test the new level option ## [2.0.3] - 2018-06-19 ### Changed - update to keep compat with `markdown-it-anchor` `v5.0.2` ## [2.0.2] - 2018-06-15 ### Changed - tests cover 100% ## [2.0.0] - 2018-06-14 ### Changed - dropped package `string` as dependency ## [1.0.5] - 2018-06-12 ### Added - `markdown-it` as `peerDependencies` ### Changed - better `headings_ast(tokens)` with support for skipping heading ranks ## [1.0.4] - 2018-06-11 ### Fixed - tests ## [1.0.3] - 2018-06-08 ### Changed - **WAI-ARIA** `role='navigation'` isn't required ## [1.0.2] - 2018-06-04 ### Added - travis ## [1.0.1] - 2018-06-04 ### Added - linting - testing - runkit - unicode support example [Unreleased]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v4.1.0...HEAD [4.1.0]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v4.0.2...v4.1.0 [4.0.2]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v4.0.1...v4.0.2 [4.0.1]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v4.0.0...v4.0.1 [4.0.0]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v3.0.0...v4.0.0 [3.0.0]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v2.1.0...v3.0.0 [2.1.0]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v2.0.3...v2.1.0 [2.0.3]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v2.0.2...v2.0.3 [2.0.2]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v2.0.0...v2.0.2 [2.0.0]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v1.0.5...v2.0.0 [1.0.5]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v1.0.4...v1.0.5 [1.0.4]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v1.0.3...v1.0.4 [1.0.3]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v1.0.2...v1.0.3 [1.0.2]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v1.0.1...v1.0.2 [1.0.1]: https://github.com/nagaozen/markdown-it-toc-done-right/compare/v1.0.0...v1.0.1 ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2018 Fabio Zendhi Nagao 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: Makefile ================================================ NPM_PACKAGE := $(shell node -e 'process.stdout.write(require("./package.json").name)') NPM_VERSION := $(shell node -e 'process.stdout.write(require("./package.json").version)') GITHUB_PROJ := https://github.com//nagaozen/${NPM_PACKAGE} build: rm -rf ./dist mkdir dist # Browserify ( printf "/*! ${NPM_PACKAGE} ${NPM_VERSION} ${GITHUB_PROJ} @license MIT */" ; \ npx browserify -s markdownitTocDoneRight -t babelify --presets [ "@babel/preset-env" ] . \ ) > dist/markdown-it-toc-made-right.js # Minify npx uglifyjs dist/markdown-it-toc-made-right.js -c -m \ --preamble "/*! ${NPM_PACKAGE} ${NPM_VERSION} ${GITHUB_PROJ} @license MIT */" \ > dist/markdown-it-toc-made-right.min.js upddemo: rm -rf ./lib mkdir lib curl -o lib/markdown-it-anchor.js https://wzrd.in/standalone/markdown-it-anchor@latest curl -o lib/uslug.js https://wzrd.in/standalone/uslug@latest ================================================ FILE: README.md ================================================ # markdown-it-toc-done-right A table of contents (TOC) plugin for [Markdown-it](https://github.com/markdown-it/markdown-it) with focus on semantic and security. Made to work gracefully with [markdown-it-anchor](https://github.com/valeriangalliat/markdown-it-anchor). [![Build Status](https://img.shields.io/travis/nagaozen/markdown-it-toc-done-right/master.svg?style=flat)](https://travis-ci.org/nagaozen/markdown-it-toc-done-right) [![Coverage Status](https://coveralls.io/repos/github/nagaozen/markdown-it-toc-done-right/badge.svg?branch=master)](https://coveralls.io/github/nagaozen/markdown-it-toc-done-right?branch=master) [![NPM version](https://img.shields.io/npm/v/markdown-it-toc-done-right.svg?style=flat)](vhttps://www.npmjs.org/package/markdown-it-toc-done-right) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![Try markdown-it-toc-done-right on RunKit](https://badge.runkitcdn.com/markdown-it-toc-done-right.svg)](https://npm.runkit.com/markdown-it-toc-done-right) ## tl;dr If you are drowning in table of contents plugins options, just pick this one. It delivers an **accessible**, **semantic**, **SEO friendly** and **safe** TOC. Place one of: `${toc}`, `[[toc]]`, `[toc]`, `[[_toc_]]` in your markdown and, BOOM, the `"},r.renderer.rules.tocBody=function(e,r){var i=Object.assign({},t);e&&r>=0&&(i=Object.assign(i,e[r].inlineOptions));var s,a={},c=Array.isArray(i.level)?(s=i.level,function(e){return s.includes(e)}):function(e){return function(n){return n>=e}}(i.level);return function e(r){var l=i.listClass?' class="'+n(i.listClass)+'"':"",s=i.itemClass?' class="'+n(i.itemClass)+'"':"",o=i.linkClass?' class="'+n(i.linkClass)+'"':"";if(0===r.c.length)return"";var u="";return(0===r.l||c(r.l))&&(u+="<"+(n(i.listType)+l)+">"),r.c.forEach(function(r){c(r.l)?u+="'+("function"==typeof i.format?i.format(r.n,n):n(r.n))+""+e(r)+"":u+=e(r)}),(0===r.l||c(r.l))&&(u+=""),u}(l)},r.core.ruler.push("generateTocAst",function(e){l=function(e){for(var n={l:0,n:"",c:[]},r=[n],t=0,l=e.length;tr[0].l)r[0].c.push(a),r.unshift(a);else if(a.l===r[0].l)r[1].c.push(a),r[0]=a;else{for(;a.l<=r[0].l;)r.shift();r[0].c.push(a),r.unshift(a)}}}return n}(e.tokens),"function"==typeof t.callback&&t.callback(r.renderer.rules.tocOpen()+r.renderer.rules.tocBody()+r.renderer.rules.tocClose(),l)}),r.block.ruler.before("heading","toc",function(e,n,r,t){var l,s=e.src.slice(e.bMarks[n]+e.tShift[n],e.eMarks[n]).split(" ")[0];if(!i.test(s))return!1;if(t)return!0;var a=i.exec(s),c={};if(null!==a&&3===a.length)try{c=JSON.parse(a[2])}catch(e){}return e.line=n+1,(l=e.push("tocOpen","nav",1)).markup="",l.map=[n,e.line],l.inlineOptions=c,(l=e.push("tocBody","",0)).markup="",l.map=[n,e.line],l.inlineOptions=c,l.children=[],(l=e.push("tocClose","nav",-1)).markup="",!0},{alt:["paragraph","reference","blockquote"]})} //# sourceMappingURL=markdownItTocDoneRight.mjs.map ================================================ FILE: dist/markdownItTocDoneRight.modern.js ================================================ function e(e){return encodeURIComponent(String(e).trim().toLowerCase().replace(/\s+/g,"-"))}function n(e){return String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">")}export default function(t,l){let r;l=Object.assign({},{placeholder:"(\\$\\{toc\\}|\\[\\[?_?toc_?\\]?\\]|\\$\\)",slugify:e,uniqueSlugStartIndex:1,containerClass:"table-of-contents",containerId:void 0,listClass:void 0,itemClass:void 0,linkClass:void 0,level:1,listType:"ol",format:void 0,callback:void 0},l);const s=new RegExp("^"+l.placeholder+"$","i");t.renderer.rules.tocOpen=function(e,t){let r=Object.assign({},l);return e&&t>=0&&(r=Object.assign(r,e[t].inlineOptions)),``},t.renderer.rules.tocClose=function(){return""},t.renderer.rules.tocBody=function(e,t){let s=Object.assign({},l);e&&t>=0&&(s=Object.assign(s,e[t].inlineOptions));const c={},i=Array.isArray(s.level)?(o=s.level,e=>o.includes(e)):(e=>n=>n>=e)(s.level);var o;return function e(t){const r=s.listClass?` class="${n(s.listClass)}"`:"",o=s.itemClass?` class="${n(s.itemClass)}"`:"",a=s.linkClass?` class="${n(s.linkClass)}"`:"";if(0===t.c.length)return"";let u="";return(0===t.l||i(t.l))&&(u+=`<${n(s.listType)+r}>`),t.c.forEach(t=>{i(t.l)?u+=`${"function"==typeof s.format?s.format(t.n,n):n(t.n)}${e(t)}`:u+=e(t)}),(0===t.l||i(t.l))&&(u+=``),u}(r)},t.core.ruler.push("generateTocAst",function(e){r=function(e){const n={l:0,n:"",c:[]},t=[n];for(let n=0,l=e.length;nt[0].l)t[0].c.push(s),t.unshift(s);else if(s.l===t[0].l)t[1].c.push(s),t[0]=s;else{for(;s.l<=t[0].l;)t.shift();t[0].c.push(s),t.unshift(s)}}}return n}(e.tokens),"function"==typeof l.callback&&l.callback(t.renderer.rules.tocOpen()+t.renderer.rules.tocBody()+t.renderer.rules.tocClose(),r)}),t.block.ruler.before("heading","toc",function(e,n,t,l){let r;const c=e.src.slice(e.bMarks[n]+e.tShift[n],e.eMarks[n]).split(" ")[0];if(!s.test(c))return!1;if(l)return!0;const i=s.exec(c);let o={};if(null!==i&&3===i.length)try{o=JSON.parse(i[2])}catch(e){}return e.line=n+1,r=e.push("tocOpen","nav",1),r.markup="",r.map=[n,e.line],r.inlineOptions=o,r=e.push("tocBody","",0),r.markup="",r.map=[n,e.line],r.inlineOptions=o,r.children=[],r=e.push("tocClose","nav",-1),r.markup="",!0},{alt:["paragraph","reference","blockquote"]})} //# sourceMappingURL=markdownItTocDoneRight.modern.js.map ================================================ FILE: dist/markdownItTocDoneRight.umd.js ================================================ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).markdownItTocDoneRight=n()}(this,function(){function e(e){return encodeURIComponent(String(e).trim().toLowerCase().replace(/\s+/g,"-"))}function n(e){return String(e).replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">")}return function(t,r){var l;r=Object.assign({},{placeholder:"(\\$\\{toc\\}|\\[\\[?_?toc_?\\]?\\]|\\$\\)",slugify:e,uniqueSlugStartIndex:1,containerClass:"table-of-contents",containerId:void 0,listClass:void 0,itemClass:void 0,linkClass:void 0,level:1,listType:"ol",format:void 0,callback:void 0},r);var i=new RegExp("^"+r.placeholder+"$","i");t.renderer.rules.tocOpen=function(e,t){var l=Object.assign({},r);return e&&t>=0&&(l=Object.assign(l,e[t].inlineOptions)),"'},t.renderer.rules.tocClose=function(){return""},t.renderer.rules.tocBody=function(e,t){var i=Object.assign({},r);e&&t>=0&&(i=Object.assign(i,e[t].inlineOptions));var o,s={},c=Array.isArray(i.level)?(o=i.level,function(e){return o.includes(e)}):function(e){return function(n){return n>=e}}(i.level);return function e(t){var l=i.listClass?' class="'+n(i.listClass)+'"':"",o=i.itemClass?' class="'+n(i.itemClass)+'"':"",a=i.linkClass?' class="'+n(i.linkClass)+'"':"";if(0===t.c.length)return"";var u="";return(0===t.l||c(t.l))&&(u+="<"+(n(i.listType)+l)+">"),t.c.forEach(function(t){c(t.l)?u+="'+("function"==typeof i.format?i.format(t.n,n):n(t.n))+""+e(t)+"":u+=e(t)}),(0===t.l||c(t.l))&&(u+=""),u}(l)},t.core.ruler.push("generateTocAst",function(e){l=function(e){for(var n={l:0,n:"",c:[]},t=[n],r=0,l=e.length;rt[0].l)t[0].c.push(s),t.unshift(s);else if(s.l===t[0].l)t[1].c.push(s),t[0]=s;else{for(;s.l<=t[0].l;)t.shift();t[0].c.push(s),t.unshift(s)}}}return n}(e.tokens),"function"==typeof r.callback&&r.callback(t.renderer.rules.tocOpen()+t.renderer.rules.tocBody()+t.renderer.rules.tocClose(),l)}),t.block.ruler.before("heading","toc",function(e,n,t,r){var l,o=e.src.slice(e.bMarks[n]+e.tShift[n],e.eMarks[n]).split(" ")[0];if(!i.test(o))return!1;if(r)return!0;var s=i.exec(o),c={};if(null!==s&&3===s.length)try{c=JSON.parse(s[2])}catch(e){}return e.line=n+1,(l=e.push("tocOpen","nav",1)).markup="",l.map=[n,e.line],l.inlineOptions=c,(l=e.push("tocBody","",0)).markup="",l.map=[n,e.line],l.inlineOptions=c,l.children=[],(l=e.push("tocClose","nav",-1)).markup="",!0},{alt:["paragraph","reference","blockquote"]})}}); //# sourceMappingURL=markdownItTocDoneRight.umd.js.map ================================================ FILE: index.js ================================================ 'use strict' function slugify (x) { return encodeURIComponent(String(x).trim().toLowerCase().replace(/\s+/g, '-')) } function htmlencode (x) { /* // safest, delegate task to native -- IMPORTANT: enabling this breaks both jest and runkit, but with browserify it's fine if (document && document.createElement) { const el = document.createElement("div") el.innerText = x return el.innerHTML } */ return String(x) .replace(/&/g, '&') .replace(/"/g, '"') .replace(/'/g, ''') .replace(//g, '>') } function tocPlugin (md, options) { options = Object.assign({}, { placeholder: '(\\$\\{toc\\}|\\[\\[?_?toc_?\\]?\\]|\\$\\)', slugify: slugify, uniqueSlugStartIndex: 1, containerClass: 'table-of-contents', containerId: undefined, listClass: undefined, itemClass: undefined, linkClass: undefined, level: 1, listType: 'ol', format: undefined, callback: undefined/* function(html, ast) {} */ }, options) let ast const pattern = new RegExp('^' + options.placeholder + '$', 'i') function toc (state, startLine, endLine, silent) { let token const pos = state.bMarks[startLine] + state.tShift[startLine] const max = state.eMarks[startLine] // use whitespace as a line tokenizer and extract the first token // to test against the placeholder anchored pattern, rejecting if false const lineFirstToken = state.src.slice(pos, max).split(' ')[0] if (!pattern.test(lineFirstToken)) return false if (silent) return true const matches = pattern.exec(lineFirstToken) let inlineOptions = {} if (matches !== null && matches.length === 3) { try { inlineOptions = JSON.parse(matches[2]) } catch (ex) { // silently ignore inline options } } state.line = startLine + 1 token = state.push('tocOpen', 'nav', 1) token.markup = '' token.map = [startLine, state.line] token.inlineOptions = inlineOptions token = state.push('tocBody', '', 0) token.markup = '' token.map = [startLine, state.line] token.inlineOptions = inlineOptions token.children = [] token = state.push('tocClose', 'nav', -1) token.markup = '' return true } md.renderer.rules.tocOpen = function (tokens, idx/* , options, env, renderer */) { let _options = Object.assign({}, options) if (tokens && idx >= 0) { const token = tokens[idx] _options = Object.assign(_options, token.inlineOptions) } const id = _options.containerId ? ` id="${htmlencode(_options.containerId)}"` : '' return `` } md.renderer.rules.tocClose = function (/* tokens, idx, options, env, renderer */) { return '' } md.renderer.rules.tocBody = function (tokens, idx/* , options, env, renderer */) { let _options = Object.assign({}, options) if (tokens && idx >= 0) { const token = tokens[idx] _options = Object.assign(_options, token.inlineOptions) } const uniques = {} function unique (s) { let u = s let i = _options.uniqueSlugStartIndex while (Object.prototype.hasOwnProperty.call(uniques, u)) u = `${s}-${i++}` uniques[u] = true return u } const isLevelSelectedNumber = selection => level => level >= selection const isLevelSelectedArray = selection => level => selection.includes(level) const isLevelSelected = Array.isArray(_options.level) ? isLevelSelectedArray(_options.level) : isLevelSelectedNumber(_options.level) function ast2html (tree) { const listClass = _options.listClass ? ` class="${htmlencode(_options.listClass)}"` : '' const itemClass = _options.itemClass ? ` class="${htmlencode(_options.itemClass)}"` : '' const linkClass = _options.linkClass ? ` class="${htmlencode(_options.linkClass)}"` : '' if (tree.c.length === 0) return '' let buffer = '' if (tree.l === 0 || isLevelSelected(tree.l)) { buffer += (`<${htmlencode(_options.listType) + listClass}>`) } tree.c.forEach(node => { if (isLevelSelected(node.l)) { buffer += (`${typeof _options.format === 'function' ? _options.format(node.n, htmlencode) : htmlencode(node.n)}${ast2html(node)}`) } else { buffer += ast2html(node) } }) if (tree.l === 0 || isLevelSelected(tree.l)) { buffer += (``) } return buffer } return ast2html(ast) } function headings2ast (tokens) { const ast = { l: 0, n: '', c: [] } const stack = [ast] for (let i = 0, iK = tokens.length; i < iK; i++) { const token = tokens[i] if (token.type === 'heading_open') { const key = ( tokens[i + 1] .children .filter(function (token) { return token.type === 'text' || token.type === 'code_inline' }) .reduce(function (s, t) { return s + t.content }, '') ) const node = { l: parseInt(token.tag.substr(1), 10), n: key, c: [] } if (node.l > stack[0].l) { stack[0].c.push(node) stack.unshift(node) } else if (node.l === stack[0].l) { stack[1].c.push(node) stack[0] = node } else { while (node.l <= stack[0].l) stack.shift() stack[0].c.push(node) stack.unshift(node) } } } return ast } md.core.ruler.push('generateTocAst', function (state) { const tokens = state.tokens ast = headings2ast(tokens) if (typeof options.callback === 'function') { options.callback( md.renderer.rules.tocOpen() + md.renderer.rules.tocBody() + md.renderer.rules.tocClose(), ast ) } }) md.block.ruler.before('heading', 'toc', toc, { alt: ['paragraph', 'reference', 'blockquote'] }) } export default tocPlugin ================================================ FILE: package.json ================================================ { "name": "markdown-it-toc-done-right", "version": "4.2.0", "description": "Table of contents (TOC) for markdown-it markdown parser with focus on semantic and security.", "source": "index.js", "main": "dist/markdownItTocDoneRight.js", "module": "dist/markdownItTocDoneRight.mjs", "unpkg": "dist/markdownItTocDoneRight.umd.js", "scripts": { "build": "microbundle", "dev": "microbundle watch", "lint": "standard --verbose index.js __test__/test.js | snazzy", "test": "jest --coverage" }, "repository": { "type": "git", "url": "git+https://github.com/nagaozen/markdown-it-toc-done-right.git" }, "keywords": [ "markdown-it-plugin", "markdown-it", "markdown", "toc", "table of contents" ], "author": "Fabio Zendhi Nagao ", "license": "MIT", "files": [ "README.md", "LICENSE", "dist/*", "runkit.js", "types/*" ], "types": "types/index.d.ts", "bugs": { "url": "https://github.com/nagaozen/markdown-it-toc-done-right/issues" }, "homepage": "https://github.com/nagaozen/markdown-it-toc-done-right#readme", "jest": { "verbose": true }, "runkitExampleFilename": "runkit.js", "dependencies": {}, "devDependencies": { "@types/markdown-it": "^10.0.0", "coveralls": "^3.0.7", "jest": "^26.6.3", "markdown-it": "^10.0.0", "markdown-it-anchor": "^6.0.0", "microbundle": "^0.12.4", "snazzy": "^8.0.0", "standard": "^13.1.0", "uslug": "^1.0.4" } } ================================================ FILE: runkit.js ================================================ const uslug = require('uslug') function uslugify (x) { return uslug(x) } const umd = require('markdown-it')({ html: false, xhtmlOut: true, typographer: true }).use(require('markdown-it-anchor'), { permalink: true, permalinkBefore: true, permalinkSymbol: '§', slugify: uslugify }) .use(require('markdown-it-toc-done-right'), { slugify: uslugify }) console.log(umd.render('${toc}\n\n# こんにちは RunKit')) ================================================ FILE: tdd.helper.html ================================================ markdown-it-toc-done-right ================================================ FILE: types/index.d.ts ================================================ declare module 'markdown-it-toc-done-right' { import { PluginWithOptions } from 'markdown-it'; export interface TocOptions { placeholder: string slugify: (s: string) => string uniqueSlugStartIndex: number containerClass: string containerId: string listClass: string itemClass: string linkClass: string level: number | number[] listType: 'ol' | 'ul' format: (s: string) => string callback: (tocCode: string, ast: TocAst) => void } export interface TocAst { l: number n: string c: TocAst[] } const markdownItTocDoneRight: PluginWithOptions> export default markdownItTocDoneRight } ================================================ FILE: uslug.js ================================================ !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.uslug=t()}}(function(){var t;return function t(e,r,n){function i(u,s){if(!r[u]){if(!e[u]){var f="function"==typeof require&&require;if(!s&&f)return f(u,!0);if(o)return o(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var h=r[u]={exports:{}};e[u][0].call(h.exports,function(t){var r=e[u][1][t];return i(r?r:t)},h,h.exports,t,e,r,n)}return r[u].exports}for(var o="function"==typeof require&&require,u=0;u>8&255]>p&&(F[e]=n)),n}function i(t,e,r){var n=65280&e,i=N.udata[n]||{},o=i[e];return o?new N(e,o):new N(e,l)}function o(t,e,r){return r?t(e,r):new N(e,null)}function u(t,e,r){var n;if(e=55296&&t<=56319},N.isLowSurrogate=function(t){return t>=56320&&t<=57343},N.prototype.prepFeature=function(){this.feature||(this.feature=N.fromCharCode(this.codepoint,!0).feature)},N.prototype.toString=function(){if(this.codepoint<65536)return String.fromCharCode(this.codepoint);var t=this.codepoint-65536;return String.fromCharCode(Math.floor(t/1024)+55296,t%1024+56320)},N.prototype.getDecomp=function(){return this.prepFeature(),this.feature[0]||null},N.prototype.isCompatibility=function(){return this.prepFeature(),!!this.feature[1]&&256&this.feature[1]},N.prototype.isExclude=function(){return this.prepFeature(),!!this.feature[1]&&512&this.feature[1]},N.prototype.getCanonicalClass=function(){return this.prepFeature(),this.feature[1]?255&this.feature[1]:0},N.prototype.getComposite=function(t){if(this.prepFeature(),!this.feature[2])return null;var e=this.feature[2][t.codepoint];return e?N.fromCharCode(e):null};var M=function(t){this.str=t,this.cursor=0};M.prototype.next=function(){if(this.str&&this.cursor0;--r){var n=this.resBuf[r-1],i=n.getCanonicalClass();if(i<=t)break}this.resBuf.splice(r,0,e)}while(0!==t);return this.resBuf.shift()};var k=function(t){this.it=t,this.procBuf=[],this.resBuf=[],this.lastClass=null};k.prototype.next=function(){for(;0===this.resBuf.length;){var t=this.it.next();if(!t){this.resBuf=this.procBuf,this.procBuf=[];break}if(0===this.procBuf.length)this.lastClass=t.getCanonicalClass(),this.procBuf.push(t);else{var e=this.procBuf[0],r=e.getComposite(t),n=t.getCanonicalClass();r&&(this.lastClass