forked from sashin/sashinexists
run npm install to generate a package lock
This commit is contained in:
21
node_modules/marked-gfm-heading-id/LICENSE
generated
vendored
Normal file
21
node_modules/marked-gfm-heading-id/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 @markedjs
|
||||
|
||||
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.
|
||||
70
node_modules/marked-gfm-heading-id/README.md
generated
vendored
Normal file
70
node_modules/marked-gfm-heading-id/README.md
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
# marked-gfm-heading-id
|
||||
|
||||
Add ids to headings like GitHub.
|
||||
|
||||
# Usage
|
||||
|
||||
```js
|
||||
import { marked } from "marked";
|
||||
import { gfmHeadingId } from "marked-gfm-heading-id";
|
||||
|
||||
// or UMD script
|
||||
// <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
|
||||
// <script src="https://cdn.jsdelivr.net/npm/marked-gfm-heading-id/lib/index.umd.js"></script>
|
||||
|
||||
const options = {
|
||||
prefix: "my-prefix-",
|
||||
};
|
||||
|
||||
marked.use(gfmHeadingId(options));
|
||||
|
||||
marked("# heading");
|
||||
// <h1 id="my-prefix-heading">heading</h1>
|
||||
```
|
||||
|
||||
## Get heading list
|
||||
|
||||
`getHeadingList` is a function that is exported to provide the list of headings.
|
||||
|
||||
The headings will each be an object with the following properties:
|
||||
- `text`: The rendered HTML for the heading
|
||||
- `level`: The heading level (1-7)
|
||||
- `raw`: The raw text (stripped of HTML rendering if any; this is usefull for situation like `marked("# [heading](./link)");`)
|
||||
- `id`: The id given to the heading including any prefix
|
||||
|
||||
```js
|
||||
import { marked } from "marked";
|
||||
import { gfmHeadingId, getHeadingList } from "marked-gfm-heading-id";
|
||||
|
||||
marked.use(gfmHeadingId({prefix: "my-prefix-"}), {
|
||||
hooks: {
|
||||
postprocess(html) {
|
||||
const headings = getHeadingList();
|
||||
|
||||
return `
|
||||
<ul id="table-of-contents">
|
||||
${headings.map(({id, raw, level}) => `<li><a href="#${id}" class="h${level}">${raw}</a></li>`)}
|
||||
</ul>
|
||||
${html}`;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
marked("# heading");
|
||||
// <ul id="table-of-contents">
|
||||
// <li><a href="#my-prefix-heading" class="h1">heading</a></li>
|
||||
// </ul>
|
||||
// <h1 id="my-prefix-heading">heading</h1>
|
||||
```
|
||||
|
||||
## Clear Heading List
|
||||
|
||||
`resetHeadings` is a function to purge the stored list of headings and reset the Slugger. This is only needed when the globalSlugs option ( see below) is set to true and you wish to reset the slugger and exportable Headers list.
|
||||
|
||||
## `options`
|
||||
|
||||
| option | type | default | description |
|
||||
|-------------|--------|---------|:----------------------------------------------|
|
||||
| prefix | string | `""` | A string to prepend to all ids. |
|
||||
| globalSlugs | bool | `false` | Track ids from one use of marked to the next. This ensures unique headers when parsing multiple markdown fragments and rendering the results as a single document. When set to false, the slugger and headers lists are cleared on every marked run.
|
||||
|
||||
145
node_modules/marked-gfm-heading-id/lib/index.cjs
generated
vendored
Normal file
145
node_modules/marked-gfm-heading-id/lib/index.cjs
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
151
node_modules/marked-gfm-heading-id/lib/index.umd.js
generated
vendored
Normal file
151
node_modules/marked-gfm-heading-id/lib/index.umd.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
67
node_modules/marked-gfm-heading-id/package.json
generated
vendored
Normal file
67
node_modules/marked-gfm-heading-id/package.json
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "marked-gfm-heading-id",
|
||||
"version": "4.1.0",
|
||||
"description": "marked GFM heading ids",
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./src/index.js",
|
||||
"browser": "./lib/index.umd.js",
|
||||
"type": "module",
|
||||
"types": "./src/index.d.ts",
|
||||
"files": [
|
||||
"lib/",
|
||||
"src/"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./src/index.js",
|
||||
"require": "./lib/index.cjs"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"marked",
|
||||
"extension"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "jest --verbose",
|
||||
"test:cover": "jest --coverage",
|
||||
"test:types": "tsd -f spec/index.test-d.ts -t src/index.d.ts",
|
||||
"lint": "eslint",
|
||||
"build": "rollup -c rollup.config.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/markedjs/marked-gfm-heading-id.git"
|
||||
},
|
||||
"author": "Tony Brix <Tony@Brix.ninja> (https://Tony.Brix.ninja)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/markedjs/marked-gfm-heading-id/issues"
|
||||
},
|
||||
"homepage": "https://github.com/markedjs/marked-gfm-heading-id#readme",
|
||||
"peerDependencies": {
|
||||
"marked": ">=13 <15"
|
||||
},
|
||||
"dependencies": {
|
||||
"github-slugger": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.25.2",
|
||||
"@babel/preset-env": "^7.25.3",
|
||||
"@markedjs/eslint-config": "^1.0.1",
|
||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/commit-analyzer": "^13.0.0",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@semantic-release/github": "^10.1.6",
|
||||
"@semantic-release/npm": "^12.0.1",
|
||||
"@semantic-release/release-notes-generator": "^14.0.1",
|
||||
"babel-jest": "^29.7.0",
|
||||
"eslint": "^9.9.0",
|
||||
"globals": "^15.9.0",
|
||||
"jest-cli": "^29.7.0",
|
||||
"marked": "^14.0.0",
|
||||
"rollup": "^4.21.0",
|
||||
"semantic-release": "^24.1.0",
|
||||
"tsd": "^0.31.1"
|
||||
}
|
||||
}
|
||||
39
node_modules/marked-gfm-heading-id/src/index.d.ts
generated
vendored
Normal file
39
node_modules/marked-gfm-heading-id/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
||||
import type { MarkedExtension, marked } from 'marked';
|
||||
|
||||
/** Options for configuring marked-gfm-heading-id extension */
|
||||
interface GfmHeadingIdOptions {
|
||||
/** A string to prepend to all ids. Empty by default. */
|
||||
prefix?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add `id` attribute to headings (h1, h2, h3, etc) like GitHub.
|
||||
*
|
||||
* @param options Options for the extension
|
||||
* @returns A {@link marked.MarkedExtension | MarkedExtension} to be passed
|
||||
* to {@link marked.use | `marked.use()`}
|
||||
*/
|
||||
export function gfmHeadingId(options?: GfmHeadingIdOptions): MarkedExtension;
|
||||
|
||||
/**
|
||||
* Headings information, can be used to create table of content
|
||||
*/
|
||||
export interface HeadingData {
|
||||
level: number;
|
||||
text: string;
|
||||
raw: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of headings with the ids as computed by gfmHeadingId
|
||||
*
|
||||
* @returns An array of HeadingData with level, text and id.
|
||||
*/
|
||||
export function getHeadingList(): HeadingData[];
|
||||
|
||||
/**
|
||||
* Clears the stored list of Headings as computed by gfmHeadingId
|
||||
*/
|
||||
export function resetHeadings(): void;
|
||||
59
node_modules/marked-gfm-heading-id/src/index.js
generated
vendored
Normal file
59
node_modules/marked-gfm-heading-id/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import GithubSlugger from 'github-slugger';
|
||||
let slugger = new GithubSlugger();
|
||||
|
||||
let headings = [];
|
||||
|
||||
// unescape from marked helpers
|
||||
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
|
||||
/* istanbul ignore next */
|
||||
export function unescape(html) {
|
||||
// explicitly match decimal, hex, and named HTML entities
|
||||
return html.replace(unescapeTest, (_, n) => {
|
||||
n = n.toLowerCase();
|
||||
if (n === 'colon') return ':';
|
||||
if (n.charAt(0) === '#') {
|
||||
return n.charAt(1) === 'x'
|
||||
? String.fromCharCode(parseInt(n.substring(2), 16))
|
||||
: String.fromCharCode(+n.substring(1));
|
||||
}
|
||||
return '';
|
||||
});
|
||||
}
|
||||
|
||||
export function gfmHeadingId({ prefix = '', globalSlugs = false } = {}) {
|
||||
return {
|
||||
headerIds: false, // prevent deprecation warning; remove this once headerIds option is removed
|
||||
hooks: {
|
||||
preprocess(src) {
|
||||
if (!globalSlugs) {
|
||||
resetHeadings();
|
||||
}
|
||||
return src;
|
||||
},
|
||||
},
|
||||
useNewRenderer: true,
|
||||
renderer: {
|
||||
heading({ tokens, depth }) {
|
||||
const text = this.parser.parseInline(tokens);
|
||||
const raw = unescape(this.parser.parseInline(tokens, this.parser.textRenderer))
|
||||
.trim()
|
||||
.replace(/<[!\/a-z].*?>/gi, '');
|
||||
const level = depth;
|
||||
const id = `${prefix}${slugger.slug(raw.toLowerCase())}`;
|
||||
const heading = { level, text, id, raw };
|
||||
headings.push(heading);
|
||||
|
||||
return `<h${level} id="${id}">${text}</h${level}>\n`;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function getHeadingList() {
|
||||
return headings;
|
||||
}
|
||||
|
||||
export function resetHeadings() {
|
||||
headings = [];
|
||||
slugger = new GithubSlugger();
|
||||
}
|
||||
Reference in New Issue
Block a user