docs:更新文档

This commit is contained in:
张益铭
2021-03-01 15:06:11 +08:00
parent 1542135ab0
commit 9064b372e8
5835 changed files with 904126 additions and 161722 deletions

22
node_modules/markdown-it-table-of-contents/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Oktavilla
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.

89
node_modules/markdown-it-table-of-contents/README.md generated vendored Normal file
View File

@@ -0,0 +1,89 @@
# markdown-it-table-of-contents
A table of contents plugin for Markdown-it. Simple, customizable and with a default slugifier that matches that of https://www.npmjs.com/package/markdown-it-anchor (>5.0.0).
## Usage
``` javascript
var MarkdownIt = require("markdown-it");
var md = new MarkdownIt();
md.use(require("markdown-it-anchor")); // Optional, but makes sense as you really want to link to something
md.use(require("markdown-it-table-of-contents"));
```
Then add `[[toc]]` where you want the table of contents to be added in your markdown.
## Example markdown
This markdown:
``` markdown
# Heading
[[toc]]
## Sub heading 1
Some nice text
## Sub heading 2
Some even nicer text
```
... would render this HTML using the default options specified in "usage" above:
``` html
<h1 id="heading">Heading</h1>
<div class="table-of-contents">
<ul>
<li><a href="#heading">Heading</a>
<ul>
<li><a href="#sub-heading-1">Sub heading 1</a></li>
<li><a href="#sub-heading-2">Sub heading 2</a></li>
</ul>
</li>
</ul>
</div>
<h2 id="sub-heading-1">Sub heading 1</h2>
<p>Some nice text</p>
<h2 id="sub-heading-2">Sub heading 2</h2>
<p>Some even nicer text</p>
```
## Options
You may specify options when `use`ing the plugin. like so:
``` javascript
md.use(require("markdown-it-table-of-contents"), options);
```
These options are available:
Name | Description | Default
-----------------------|-------------------------------------------------------------------------------------|------------------------------------
"includeLevel" | Headings levels to use (2 for h2:s etc) | [1, 2]
"containerClass" | The class for the container DIV | "table-of-contents"
"slugify" | A custom slugification function | `encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, '-'))`
"markerPattern" | Regex pattern of the marker to be replaced with TOC | `/^\[\[toc\]\]/im`
"listType" | Type of list (`ul` for unordered, `ol` for ordered) | `ul`
"format" | A function for formatting headings (see below) | `undefined`
"forceFullToc" | If true, renders all the headers in TOC, even if the headers are in incorrect order | false
"containerHeaderHtml" | Optional HTML string for container header | `<div class="toc-container-header">Contents</div>`
"containerFooterHtml" | Optional HTML string for container footer | `<div class="toc-container-footer">Footer</div>`
"transformLink" | A function for transforming the TOC links | `undefined`
`format` is an optional function for changing how the headings are displayed in the TOC.
```js
function format(headingAsString) {
// manipulate the headings as you like here.
return manipulatedHeadingString;
}
```
`transformLink` is an optional function for transform the link as you like.
```js
function transformLink(link) {
// transform the link as you like here.
return transformedLink;
}
```

168
node_modules/markdown-it-table-of-contents/index.js generated vendored Normal file
View File

@@ -0,0 +1,168 @@
'use strict';
const slugify = (s) => encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, '-'));
const defaults = {
includeLevel: [ 1, 2 ],
containerClass: 'table-of-contents',
slugify,
markerPattern: /^\[\[toc\]\]/im,
listType: 'ul',
format: undefined,
forceFullToc: false,
containerHeaderHtml: undefined,
containerFooterHtml: undefined,
transformLink: undefined,
};
module.exports = (md, o) => {
const options = Object.assign({}, defaults, o);
const tocRegexp = options.markerPattern;
let gstate;
function toc(state, silent) {
var token;
var match;
// Reject if the token does not start with [
if (state.src.charCodeAt(state.pos) !== 0x5B /* [ */ ) {
return false;
}
// Don't run any pairs in validation mode
if (silent) {
return false;
}
// Detect TOC markdown
match = tocRegexp.exec(state.src.substr(state.pos));
match = !match ? [] : match.filter(function(m) { return m; });
if (match.length < 1) {
return false;
}
// Build content
token = state.push('toc_open', 'toc', 1);
token.markup = '[[toc]]';
token = state.push('toc_body', '', 0);
token = state.push('toc_close', 'toc', -1);
// Update pos so the parser can continue
var newline = state.src.indexOf('\n', state.pos);
if (newline !== -1) {
state.pos = newline;
} else {
state.pos = state.pos + state.posMax + 1;
}
return true;
}
md.renderer.rules.toc_open = function(tokens, index) {
var tocOpenHtml = `<div class="${options.containerClass}">`;
if (options.containerHeaderHtml) {
tocOpenHtml += options.containerHeaderHtml;
}
return tocOpenHtml;
};
md.renderer.rules.toc_close = function(tokens, index) {
var tocFooterHtml = '';
if (options.containerFooterHtml) {
tocFooterHtml = options.containerFooterHtml;
}
return tocFooterHtml + `</div>`;
};
md.renderer.rules.toc_body = function(tokens, index) {
if (options.forceFullToc) {
/*
Renders full TOC even if the hierarchy of headers contains
a header greater than the first appearing header
## heading 2
### heading 3
# heading 1
Result TOC:
- heading 2
- heading 3
- heading 1
*/
var tocBody = '';
var pos = 0;
var tokenLength = gstate && gstate.tokens && gstate.tokens.length;
while (pos < tokenLength) {
var tocHierarchy = renderChildsTokens(pos, gstate.tokens);
pos = tocHierarchy[0];
tocBody += tocHierarchy[1];
}
return tocBody;
} else {
return renderChildsTokens(0, gstate.tokens)[1];
}
};
function renderChildsTokens(pos, tokens) {
var headings = [],
buffer = '',
currentLevel,
subHeadings,
size = tokens.length,
i = pos;
while(i < size) {
var token = tokens[i];
var heading = tokens[i - 1];
var level = token.tag && parseInt(token.tag.substr(1, 1));
if (token.type !== 'heading_close' || options.includeLevel.indexOf(level) == -1 || heading.type !== 'inline') {
i++; continue; // Skip if not matching criteria
}
if (!currentLevel) {
currentLevel = level;// We init with the first found level
} else {
if (level > currentLevel) {
subHeadings = renderChildsTokens(i, tokens);
buffer += subHeadings[1];
i = subHeadings[0];
continue;
}
if (level < currentLevel) {
// Finishing the sub headings
buffer += `</li>`;
headings.push(buffer);
return [i, `<${options.listType}>${headings.join('')}</${options.listType}>`];
}
if (level == currentLevel) {
// Finishing the sub headings
buffer += `</li>`;
headings.push(buffer);
}
}
var slugifiedContent = options.slugify(heading.content);
var link = "#"+slugifiedContent;
if (options.transformLink) {
link = options.transformLink(link);
}
buffer = `<li><a href="${link}">`;
buffer += typeof options.format === 'function' ? options.format(heading.content) : heading.content;
buffer += `</a>`;
i++;
}
buffer += buffer === '' ? '' : `</li>`;
headings.push(buffer);
return [i, `<${options.listType}>${headings.join('')}</${options.listType}>`];
}
// Catch all the tokens for iteration later
md.core.ruler.push('grab_state', function(state) {
gstate = state;
});
// Insert TOC
md.inline.ruler.after('emphasis', 'toc', toc);
};

View File

@@ -0,0 +1,67 @@
{
"_args": [
[
"markdown-it-table-of-contents@0.4.4",
"J:\\Github\\CURD-TS"
]
],
"_development": true,
"_from": "markdown-it-table-of-contents@0.4.4",
"_id": "markdown-it-table-of-contents@0.4.4",
"_inBundle": false,
"_integrity": "sha1-PcfOi4/BflmBx3zDmNF4Ixnzf7w=",
"_location": "/markdown-it-table-of-contents",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "markdown-it-table-of-contents@0.4.4",
"name": "markdown-it-table-of-contents",
"escapedName": "markdown-it-table-of-contents",
"rawSpec": "0.4.4",
"saveSpec": null,
"fetchSpec": "0.4.4"
},
"_requiredBy": [
"/vitepress"
],
"_resolved": "http://192.168.250.101:4873/markdown-it-table-of-contents/-/markdown-it-table-of-contents-0.4.4.tgz",
"_spec": "0.4.4",
"_where": "J:\\Github\\CURD-TS",
"author": {
"name": "Oktavilla",
"email": "https://github.com/Oktavilla"
},
"bugs": {
"url": "https://github.com/Oktavilla/markdown-it-table-of-contents/issues"
},
"contributors": "Listed at <https://github.com/Oktavilla/markdown-it-table-of-contents/contributors>",
"description": "A Markdown-it plugin for adding a table of contents to markdown documents",
"devDependencies": {
"markdown-it": "~8.1.0",
"markdown-it-anchor": "~5.0.1",
"mocha": "~5.2.0"
},
"engines": {
"node": ">6.4.0"
},
"homepage": "https://github.com/Oktavilla/markdown-it-table-of-contents",
"keywords": [
"markdown",
"markdown-it",
"toc",
"table of contents",
"markdown-it-plugin"
],
"license": "MIT",
"main": "index.js",
"name": "markdown-it-table-of-contents",
"repository": {
"type": "git",
"url": "git+https://github.com/Oktavilla/markdown-it-table-of-contents.git"
},
"scripts": {
"test": "export NODE_ENV=test; mocha test --recursive"
},
"version": "0.4.4"
}

View File

@@ -0,0 +1 @@
<p><div class="table-of-contents"><ul></ul></div></p>

View File

@@ -0,0 +1,6 @@
<p>Some text with soft break before toc<br>
<div class="table-of-contents"><ul><li><a href="#heading-2">Heading 2</a></li></ul><ul><li><a href="#heading-1">Heading 1</a></li></ul></div></p>
<h2 id="heading-2">Heading 2</h2>
<p>Some nice text</p>
<h1 id="heading-1">Heading 1</h1>
<p>Some text</p>

View File

@@ -0,0 +1,8 @@
Some text with soft break before toc
[[toc]]
## Heading 2
Some nice text
# Heading 1
Some text

View File

@@ -0,0 +1,7 @@
<h1>An article</h1>
<p>some text with soft break before toc<br>
<div class="table-of-contents"><ul><li><a href="#sub-heading-%3Cspan%3E1%3C%2Fspan%3E">Sub heading <span>1</span></a></li><li><a href="#sub-heading-2">Sub heading 2</a></li></ul></div></p>
<h2>Sub heading &lt;span&gt;1&lt;/span&gt;</h2>
<p>Some nice text</p>
<h2>Sub heading 2</h2>
<p>Some even nicer text</p>

View File

@@ -0,0 +1,7 @@
<h1>An article</h1>
<p>some text with soft break before toc<br>
<div class="table-of-contents"><ul><li><a href="#an-article">An article</a><ul><li><a href="#sub-heading-%3Cspan%3E1%3C%2Fspan%3E">Sub heading <span>1</span></a></li><li><a href="#sub-heading-2">Sub heading 2</a></li></ul></li></ul></div></p>
<h2>Sub heading &lt;span&gt;1&lt;/span&gt;</h2>
<p>Some nice text</p>
<h2>Sub heading 2</h2>
<p>Some even nicer text</p>

View File

@@ -0,0 +1,7 @@
<h1 id="an-article">An article</h1>
<p>some text with soft break before toc<br>
<div class="table-of-contents"><ul><li><a href="#an-article">An article</a><ul><li><a href="#sub-heading-%3Cspan%3E1%3C%2Fspan%3E">Sub heading <span>1</span></a></li><li><a href="#sub-heading-2">Sub heading 2</a></li></ul></li></ul></div></p>
<h2 id="sub-heading-%3Cspan%3E1%3C%2Fspan%3E">Sub heading &lt;span&gt;1&lt;/span&gt;</h2>
<p>Some nice text</p>
<h2 id="sub-heading-2">Sub heading 2</h2>
<p>Some even nicer text</p>

View File

@@ -0,0 +1,7 @@
<h1 id="an-article">An article</h1>
<p>some text with soft break before toc<br>
<div class="table-of-contents"><div class="header">Contents</div><ul><li><a href="#an-article">An article</a><ul><li><a href="#sub-heading-%3Cspan%3E1%3C%2Fspan%3E">Sub heading <span>1</span></a></li><li><a href="#sub-heading-2">Sub heading 2</a></li></ul></li></ul><div class="footer">Footer</div></div></p>
<h2 id="sub-heading-%3Cspan%3E1%3C%2Fspan%3E">Sub heading &lt;span&gt;1&lt;/span&gt;</h2>
<p>Some nice text</p>
<h2 id="sub-heading-2">Sub heading 2</h2>
<p>Some even nicer text</p>

View File

@@ -0,0 +1,7 @@
<h1 id="an-article">An article</h1>
<p>some text with soft break before toc<br>
<div class="table-of-contents"><ul><li><a href="#an-article&type=test">An article</a><ul><li><a href="#sub-heading-%3Cspan%3E1%3C%2Fspan%3E&type=test">Sub heading <span>1</span></a></li><li><a href="#sub-heading-2&type=test">Sub heading 2</a></li></ul></li></ul></div></p>
<h2 id="sub-heading-%3Cspan%3E1%3C%2Fspan%3E">Sub heading &lt;span&gt;1&lt;/span&gt;</h2>
<p>Some nice text</p>
<h2 id="sub-heading-2">Sub heading 2</h2>
<p>Some even nicer text</p>

View File

@@ -0,0 +1,9 @@
# An article
some text with soft break before toc
[[toc]]
## Sub heading <span>1</span>
Some nice text
## Sub heading 2
Some even nicer text

View File

@@ -0,0 +1,127 @@
"use strict";
var assert = require("assert");
var fs = require("fs");
var MarkdownIt = require("markdown-it");
var markdownItAnchor = require("markdown-it-anchor");
var markdownItTOC = require("../../index");
// Defaults
var defaultContainerClass = "table-of-contents";
var defaultMarker = "[[toc]]";
var defaultListType = "ul";
var defaultHeading1 = "Sub heading 1";
// Fixtures
var simpleMarkdown = fs.readFileSync("test/fixtures/simple.md", "utf-8");
var simpleDefaultHTML = fs.readFileSync("test/fixtures/simple-default.html", "utf-8");
var simple1LevelHTML = fs.readFileSync("test/fixtures/simple-1-level.html", "utf-8");
var simpleWithAnchorsHTML = fs.readFileSync("test/fixtures/simple-with-anchors.html", "utf-8");
var simpleWithHeaderFooterHTML = fs.readFileSync("test/fixtures/simple-with-header-footer.html", "utf-8");
var simpleWithTransformLink = fs.readFileSync("test/fixtures/simple-with-transform-link.html", "utf-8");
var emptyMarkdown = defaultMarker;
var emptyMarkdownHtml = fs.readFileSync("test/fixtures/empty.html", "utf-8");
var fullTocSampleMarkdown = fs.readFileSync("test/fixtures/full-toc-sample.md", "utf-8");
var fullTocSampleHtml = fs.readFileSync("test/fixtures/full-toc-sample-result.html", "utf-8");
const slugify = (s) => encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, '-'));
describe("Testing Markdown rendering", function() {
var md = new MarkdownIt();
it("Parses correctly with default settings", function(done) {
md.use(markdownItTOC);
assert.equal(md.render(simpleMarkdown), simpleDefaultHTML);
done();
});
it("Parses correctly with includeLevel set", function(done) {
md.use(markdownItTOC, {
"includeLevel": [2]
});
assert.equal(md.render(simpleMarkdown), simple1LevelHTML);
done();
});
it("Parses correctly with containerClass set", function(done) {
var customContainerClass = "custom-container-class";
md.use(markdownItTOC, {
"containerClass": customContainerClass
});
assert.equal(md.render(simpleMarkdown), simpleDefaultHTML.replace(defaultContainerClass, customContainerClass));
done();
});
it("Parses correctly with markerPattern set", function(done) {
var customMarker = "[[custom-marker]]";
md.use(markdownItTOC, {
"markerPattern": /^\[\[custom-marker\]\]/im
});
assert.equal(md.render(simpleMarkdown.replace(defaultMarker, customMarker)), simpleDefaultHTML);
done();
});
it("Parses correctly with listType set", function(done) {
var customListType = "ol";
md.use(markdownItTOC, {
"listType": customListType
});
assert.equal(md.render(simpleMarkdown), simpleDefaultHTML.replace(new RegExp(defaultListType, "g"), customListType));
done();
});
it("Parses correctly with custom formatting", function(done) {
var customHeading = "Test";
md.use(markdownItTOC, {
"format": function(str) {
if (str === defaultHeading1) {
return customHeading;
}
return str;
}
});
assert.equal(md.render(simpleMarkdown), simpleDefaultHTML.replace(defaultHeading1, customHeading));
done();
});
it("Slugs matches markdown-it-anchor", function(done) {
md.use(markdownItAnchor);
md.use(markdownItTOC);
assert.equal(md.render(simpleMarkdown), simpleWithAnchorsHTML);
done();
});
it("Generates empty TOC", function(done) {
md.use(markdownItTOC);
assert.equal(md.render(emptyMarkdown), emptyMarkdownHtml);
done();
});
it("Generates full TOC, even when there is a greater header than the first header", function (done) {
md.use(markdownItTOC, { forceFullToc: true });
assert.equal(md.render(fullTocSampleMarkdown), fullTocSampleHtml);
done();
});
it("Parses correctly with container header and footer html set", function (done) {
md.use(markdownItTOC,
{
slugify,
containerHeaderHtml: `<div class="header">Contents</div>`,
containerFooterHtml: `<div class="footer">Footer</div>`,
});
assert.equal(md.render(simpleMarkdown), simpleWithHeaderFooterHTML);
done();
});
it("Generates TOC, with custom transformed link", function (done) {
md.use(markdownItTOC,
{
slugify,
transformLink: (href) => {
return href+"&type=test";
},
});
assert.equal(md.render(simpleMarkdown), simpleWithTransformLink);
done();
});
});