Skip to content

Commit b5ae568

Browse files
committed
chore: first commit
0 parents  commit b5ae568

12 files changed

+344
-0
lines changed

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
lib/
3+
dist/
4+
**/*.js

.eslintrc.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
extends: [require.resolve('@umijs/fabric/dist/eslint')],
3+
rules: {
4+
'import/no-unresolved': 'off',
5+
'@typescript-eslint/camelcase': 'off',
6+
'react/no-danger': 'off',
7+
'no-unused-expressions': 'off',
8+
'class-methods-use-this': 'off',
9+
'no-alert': 'off',
10+
'no-console': 'off',
11+
'no-underscore-dangle': 'off',
12+
'import/no-extraneous-dependencies': 'off',
13+
'no-param-reassign': 'off',
14+
'prefer-destructuring': 'off',
15+
'no-plusplus': 'off',
16+
},
17+
globals: {
18+
__CLIENT__: true,
19+
},
20+
};

.fatherrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
esm: 'rollup',
3+
cjs: 'rollup',
4+
umd: {
5+
name: 'showdownToc',
6+
file: 'index',
7+
},
8+
};

.gitignore

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# TypeScript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# next.js build output
61+
.next
62+
63+
dist

.prettierrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const fabric = require('@umijs/fabric');
2+
3+
module.exports = {
4+
...fabric.prettier,
5+
};

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- '8'
5+
- '10'
6+
- '12'
7+
before_install:
8+
- npm i npminstall -g
9+
install:
10+
- npminstall
11+
script:
12+
- npm run ci
13+
after_script:
14+
- npminstall codecov && codecov

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 dxd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# showdown-toc
2+
3+
[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url]
4+
5+
[npm-image]: https://img.shields.io/npm/v/showdown-toc.svg?style=flat-square
6+
[npm-url]: https://npmjs.org/package/showdown-toc
7+
[travis-image]: https://img.shields.io/travis/ahungrynoob/showdown-toc.svg?style=flat-square
8+
[travis-url]: https://travis-ci.org/ahungrynoob/showdown-toc
9+
[codecov-image]: https://codecov.io/gh/ahungrynoob/showdown-toc/branch/master/graph/badge.svg
10+
[codecov-url]: https://codecov.io/gh/ahungrynoob/showdown-toc
11+
[download-image]: https://img.shields.io/npm/dm/showdown-toc.svg?style=flat-square
12+
[download-url]: https://npmjs.org/package/showdown-toc
13+
14+
---
15+
16+
## Install
17+
18+
```bash
19+
$ npm i showdown-toc --save
20+
```
21+
22+
## License
23+
24+
[MIT](LICENSE)

package.json

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "showdown-toc",
3+
"version": "0.1.0",
4+
"description": "A showdown extension to output toc info.",
5+
"main": "lib/index.js",
6+
"unpkg": "dist/index.js",
7+
"module": "es/index.js",
8+
"types": "types/index.d.ts",
9+
"scripts": {
10+
"build": "father build",
11+
"test": "father test",
12+
"ci": "father test --coverage",
13+
"lint-staged": "lint-staged",
14+
"lint-staged:ts": "eslint --ext .ts,.tsx",
15+
"lint:fix": "eslint --fix --cache --format=pretty **/*.ts",
16+
"lint:ts": "eslint --cache --format=pretty **/*.ts"
17+
},
18+
"files": [
19+
"dist"
20+
],
21+
"husky": {
22+
"hooks": {
23+
"pre-commit": "lint-staged"
24+
}
25+
},
26+
"lint-staged": {
27+
"**/*.{ts,md,json}": [
28+
"prettier --write",
29+
"git add"
30+
],
31+
"**/*.ts": "npm run lint-staged:ts"
32+
},
33+
"repository": {
34+
"type": "git",
35+
"url": "git+https://github.com/ahungrynoob/showdown-toc.git"
36+
},
37+
"keywords": [
38+
"showdown-extension",
39+
"showdown",
40+
"markdown",
41+
"markdown-toc"
42+
],
43+
"author": "ahungrynoob",
44+
"license": "MIT",
45+
"bugs": {
46+
"url": "https://github.com/ahungrynoob/showdown-toc/issues"
47+
},
48+
"homepage": "https://github.com/ahungrynoob/showdown-toc#readme",
49+
"devDependencies": {
50+
"@types/showdown": "^1.9.3",
51+
"@umijs/fabric": "^1.2.1",
52+
"eslint": "^6.6.0",
53+
"father": "^2.24.1",
54+
"husky": "^3.0.9",
55+
"lint-staged": "^9.0.0",
56+
"prettier": "^1.19.1",
57+
"showdown": "^1.9.1",
58+
"typescript": "^3.7.2"
59+
},
60+
"peerDependencies": {
61+
"showdown": "^1.9.1"
62+
}
63+
}

src/index.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// function showdownToc() {
2+
// return () => [
3+
// {
4+
// type: 'lang',
5+
// filter(source: string, _: any, options: any) {
6+
// const atxStyle = options.requireSpaceBeforeHeadingText
7+
// ? /^(#{1,6})[ \t]+(.+?)[ \t]*#*\n+/gm
8+
// : /^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm;
9+
// source.replace(atxStyle, (wholeMatch, m1) => '');
10+
// return source;
11+
// },
12+
// },
13+
// ];
14+
// }
15+
16+
// export default showdownToc;

src/utils.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// reference: https://github.com/showdownjs/showdown/blob/fc7ac1e1ca90d1849d120025105d1f45c9d4f8f6/src/subParsers/makehtml/headers.js#L58
2+
/* istanbul ignore next */
3+
import showdown, { ShowdownOptions } from 'showdown';
4+
5+
export function headerId(
6+
m: string,
7+
options: ShowdownOptions,
8+
hashLinkCounts: { [key: string]: number },
9+
) {
10+
let title;
11+
let prefix;
12+
13+
// It is separate from other options to allow combining prefix and customized
14+
if (options.customizedHeaderId) {
15+
const match = m.match(/\{([^{]+?)}\s*$/);
16+
if (match && match[1]) {
17+
m = match[1];
18+
}
19+
}
20+
21+
title = m;
22+
23+
// Prefix id to prevent causing inadvertent pre-existing style matches.
24+
if (showdown.helper.isString(options.prefixHeaderId)) {
25+
prefix = options.prefixHeaderId;
26+
} else if (options.prefixHeaderId === true) {
27+
prefix = 'section-';
28+
} else {
29+
prefix = '';
30+
}
31+
32+
if (!options.rawPrefixHeaderId) {
33+
title = prefix + title;
34+
}
35+
36+
if (options.ghCompatibleHeaderId) {
37+
title = title
38+
.replace(/ /g, '-')
39+
// replace previously escaped chars (&, ¨ and $)
40+
.replace(/&/g, '')
41+
.replace(/¨T/g, '')
42+
.replace(/¨D/g, '')
43+
// replace rest of the chars (&~$ are repeated as they might have been escaped)
44+
// borrowed from github's redcarpet (some they should produce similar results)
45+
.replace(/[&+$,/:;=?@"#{}|^¨~[\]`\\*)(%.!'<>]/g, '')
46+
.toLowerCase();
47+
} else if (options.rawHeaderId) {
48+
title = title
49+
.replace(/ /g, '-')
50+
// replace previously escaped chars (&, ¨ and $)
51+
.replace(/&amp;/g, '&')
52+
.replace(/¨T/g, '¨')
53+
.replace(/¨D/g, '$')
54+
// replace " and '
55+
.replace(/["']/g, '-')
56+
.toLowerCase();
57+
} else {
58+
title = title.replace(/[^\w]/g, '').toLowerCase();
59+
}
60+
61+
if (options.rawPrefixHeaderId) {
62+
title = prefix + title;
63+
}
64+
65+
if (hashLinkCounts[title]) {
66+
title = `${title}-${hashLinkCounts[title]++}`;
67+
} else {
68+
hashLinkCounts[title] = 1;
69+
}
70+
return title;
71+
}

tsconfig.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"strict": true,
5+
"outDir": "build/dist",
6+
"module": "esnext",
7+
"target": "es2016",
8+
"lib": ["es6", "dom"],
9+
"sourceMap": true,
10+
"jsx": "react",
11+
"allowSyntheticDefaultImports": true,
12+
"moduleResolution": "node",
13+
"rootDirs": ["./src", "./typings"],
14+
"forceConsistentCasingInFileNames": true,
15+
"noImplicitReturns": true,
16+
"suppressImplicitAnyIndexErrors": true,
17+
"noUnusedLocals": true,
18+
"allowJs": false,
19+
"noImplicitThis": false,
20+
"experimentalDecorators": true
21+
},
22+
"include": ["./src", "./typings/"],
23+
"typings": "./typings/index.d.ts",
24+
"exclude": [
25+
"node_modules",
26+
"build",
27+
"scripts",
28+
"acceptance-tests",
29+
"webpack",
30+
"jest",
31+
"src/setupTests.ts",
32+
"tslint:latest",
33+
"tslint-config-prettier"
34+
]
35+
}

0 commit comments

Comments
 (0)