WIP - add extractor, generate snippet_data

This commit is contained in:
Stefan Fejes
2019-08-20 15:52:05 +02:00
parent 88084d3d30
commit cc8f1d8a7a
37396 changed files with 4588842 additions and 133 deletions

24
node_modules/mdast-util-toc/LICENSE generated vendored Normal file
View File

@ -0,0 +1,24 @@
(The MIT License)
Copyright (c) 2016 Jonathan Haines <jonno.haines@gmail.com>
Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>
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.

129
node_modules/mdast-util-toc/README.md generated vendored Normal file
View File

@ -0,0 +1,129 @@
# mdast-util-toc [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status]
Generate a Table of Contents from a [**mdast**][mdast] tree.
## Installation
[npm][]:
```bash
npm install mdast-util-toc
```
**mdast-util-toc** is also available as an AMD, CommonJS, and globals
module, [uncompressed and compressed][releases].
## Usage
Dependencies:
```javascript
var remark = require('remark');
var toc = require('mdast-util-toc');
```
Parse:
```javascript
var node = remark().parse([
'# Alpha',
'',
'## Bravo',
'',
'### Charlie',
'',
'## Delta',
''
].join('\n'));
```
TOC:
```javascript
var result = toc(node);
```
Yields:
```js
{ index: null,
endIndex: null,
map:
{ type: 'list',
ordered: false,
children: [ { type: 'listItem', loose: true, children: [Object] } ] } }
```
## API
### `toc(node[, options])`
Generate a Table of Contents from a Markdown document.
* If specified, looks for the first heading containing the `heading`
option (case insensitive, supports alt/title attributes for links
and images too), and returns a table of contents for all following
headings.
* If no `heading` is specified, creates a table of contents for all
headings in `node`.
Links to headings are based on GitHubs style. Only top-level headings
(those not in blockquotes or lists), are used. The given node is not
modified.
#### `options`
* `heading` (`string?`)
— Heading to look for, wrapped in `new RegExp('^(' + value + ')$', 'i');`
* `maxDepth` (`number?`, default: `6`)
— Maximum heading depth to include in the table of contents,
This is inclusive, thus, when set to `3`, level three headings,
are included (those with three hashes, `###`);
* `tight` (`boolean?`, default: `false`)
— Whether to compile list-items tightly.
#### Returns
An object with the following properties:
* `index` (`number?`)
— Position of the `heading` in `node`. `-1` if no heading
was found, `null` if no heading was given;
* `endIndex` (`number?`)
— Position of the last node after `heading` before the TOC starts.
`-1` if no heading was found, `null` if no heading was given,
same as `index` if there are no nodes between `heading` and the
first heading in the TOC;
* `map` (`Node?`)
— List node representing the generated table of contents.
`null` if no table of contents could be created, either because
no `heading` didnt exist, or no following headings were found.
## License
[MIT][license] © [Jonathan Haines][author]
<!-- Definitions -->
[build-badge]: https://img.shields.io/travis/BarryThePenguin/mdast-util-toc.svg
[build-status]: https://travis-ci.org/BarryThePenguin/mdast-util-toc
[coverage-badge]: https://img.shields.io/codecov/c/github/BarryThePenguin/mdast-util-toc.svg
[coverage-status]: https://codecov.io/github/BarryThePenguin/mdast-util-toc
[releases]: https://github.com/BarryThePenguin/mdast-util-toc/releases
[license]: LICENSE
[author]: http://barrythepenguin.github.io
[npm]: https://docs.npmjs.com/cli/install
[mdast]: https://github.com/wooorm/mdast

41
node_modules/mdast-util-toc/history.md generated vendored Normal file
View File

@ -0,0 +1,41 @@
<!--remark setext-->
<!--lint disable no-multiple-toplevel-headings-->
2.1.0 / 2018-08-01
==================
* use existing ids ([#34](https://github.com/BarryThePenguin/mdast-util-toc/pull/34))
* update to node 10 in `.travis.yml` ([#35](https://github.com/BarryThePenguin/mdast-util-toc/pull/35))
* bump devDependencies
2.0.1 / 2016-07-23
==================
* fix tight for all heading levels ([#3](https://github.com/barrythepenguin/mdast-util-toc/issues/3))
* bump devDependencies
2.0.0 / 2016-07-23
==================
* Rewrite to not mutate given node ([#1](https://github.com/barrythepenguin/mdast-util-toc/issues/1))
1.0.1 / 2016-07-23
==================
1.0.0 / 2016-07-23
==================
0.2.0 / 2016-07-23
==================
* expose map and index in result
0.1.0 / 2016-07-18
==================
* readme example usage
* include lib in packages
* readme and license
* deploy matrix
* initial commit

12
node_modules/mdast-util-toc/index.js generated vendored Normal file
View File

@ -0,0 +1,12 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
'use strict';
/* Expose. */
module.exports = require('./lib');

66
node_modules/mdast-util-toc/lib/contents.js generated vendored Normal file
View File

@ -0,0 +1,66 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
/* Expose. */
module.exports = contents;
/* Dependencies */
var list = require('./list');
var insert = require('./insert');
/**
* Transform a list of heading objects to a markdown list.
*
* @param {Array.<Object>} map - Heading-map to insert.
* @param {boolean?} [tight] - Prefer tight list-items.
* @return {Object} - List node.
*/
function contents(map, tight) {
var minDepth = Infinity;
var index = -1;
var length = map.length;
var table;
/*
* Find minimum depth.
*/
while (++index < length) {
if (map[index].depth < minDepth) {
minDepth = map[index].depth;
}
}
/*
* Normalize depth.
*/
index = -1;
while (++index < length) {
map[index].depth -= minDepth - 1;
}
/*
* Construct the main list.
*/
table = list();
/*
* Add TOC to list.
*/
index = -1;
while (++index < length) {
insert(map[index], table, tight);
}
return table;
}

39
node_modules/mdast-util-toc/lib/index.js generated vendored Normal file
View File

@ -0,0 +1,39 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
/* Expose. */
module.exports = toc;
/* Dependencies */
var toExpression = require('./to-expression');
var search = require('./search');
var contents = require('./contents');
/**
* Get a TOC representation of `node`.
*
* @param {Mdast} node - MDAST.
* @param {Object} options - Configuration.
* @return {Array} - TOC Markdown.
*/
function toc(node, options) {
var settings = options || {};
var heading = settings.heading ? toExpression(settings.heading) : null;
var result = search(node, heading, settings.maxDepth || 6);
var map = result.map;
result.map = map.length ? contents(map, settings.tight) : null;
/* No given heading */
if (!heading) {
result.index = null;
result.endIndex = null;
}
return result;
}

108
node_modules/mdast-util-toc/lib/insert.js generated vendored Normal file
View File

@ -0,0 +1,108 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
/* Expose. */
module.exports = insert;
/* Dependencies */
var listItem = require('./list-item');
var list = require('./list');
/* Constants */
var LIST = 'list';
var LIST_ITEM = 'listItem';
var PARAGRAPH = 'paragraph';
var LINK = 'link';
var TEXT = 'text';
/**
* Insert a `node` into a `parent`.
*
* @param {Object} node - `node` to insert.
* @param {Object} parent - Parent of `node`.
* @param {boolean?} [tight] - Prefer tight list-items.
* @return {undefined}
*/
function insert(node, parent, tight) {
var children = parent.children;
var length = children.length;
var last = children[length - 1];
var isLoose = false;
var index;
var item;
if (node.depth === 1) {
item = listItem();
item.children.push({
type: PARAGRAPH,
children: [
{
type: LINK,
title: null,
url: '#' + node.id,
children: [
{
type: TEXT,
value: node.value
}
]
}
]
});
children.push(item);
} else if (last && last.type === LIST_ITEM) {
insert(node, last, tight);
} else if (last && last.type === LIST) {
node.depth--;
insert(node, last, tight);
} else if (parent.type === LIST) {
item = listItem();
insert(node, item, tight);
children.push(item);
} else {
item = list();
node.depth--;
insert(node, item, tight);
children.push(item);
}
/*
* Properly style list-items with new lines.
*/
if (parent.type === LIST_ITEM) {
parent.loose = tight ? false : children.length > 1;
} else {
if (tight) {
isLoose = false;
} else {
index = -1;
while (++index < length) {
if (children[index].loose) {
isLoose = true;
break;
}
}
}
index = -1;
while (++index < length) {
children[index].loose = isLoose;
}
}
}

24
node_modules/mdast-util-toc/lib/is-closing-heading.js generated vendored Normal file
View File

@ -0,0 +1,24 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
/* Expose. */
module.exports = isClosingHeading;
/* Constants. */
var HEADING = 'heading';
/**
* Check if `node` is the next heading.
*
* @param {Node} node - Node to check.
* @param {number} depth - Depth of opening heading.
* @return {boolean} - Whether znode is a closing heading.
*/
function isClosingHeading(node, depth) {
return depth && node && node.type === HEADING && node.depth <= depth;
}

33
node_modules/mdast-util-toc/lib/is-opening-heading.js generated vendored Normal file
View File

@ -0,0 +1,33 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
/* Expose. */
module.exports = isOpeningHeading;
/* Dependencies */
var toString = require('mdast-util-to-string');
/* Constants. */
var HEADING = 'heading';
/**
* Check if `node` is the main heading.
*
* @param {Node} node - Node to check.
* @param {number} depth - Depth to check.
* @param {RegExp} expression - Expression to check.
* @return {boolean} - Whether `node` is a main heading.
*/
function isOpeningHeading(node, depth, expression) {
return (
depth === null &&
node &&
node.type === HEADING &&
expression.test(toString(node))
);
}

26
node_modules/mdast-util-toc/lib/list-item.js generated vendored Normal file
View File

@ -0,0 +1,26 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
/* Expose. */
module.exports = listItem;
/* Constants */
var LIST_ITEM = 'listItem';
/**
* Create a list item.
*
* @return {Object} - List-item node.
*/
function listItem() {
return {
type: LIST_ITEM,
loose: false,
children: []
};
}

26
node_modules/mdast-util-toc/lib/list.js generated vendored Normal file
View File

@ -0,0 +1,26 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
/* Expose. */
module.exports = list;
/* Constants */
var LIST = 'list';
/**
* Create a list.
*
* @return {Object} - List node.
*/
function list() {
return {
type: LIST,
ordered: false,
children: []
};
}

97
node_modules/mdast-util-toc/lib/search.js generated vendored Normal file
View File

@ -0,0 +1,97 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
/* Expose. */
module.exports = search;
/* Dependencies */
var toString = require('mdast-util-to-string');
var visit = require('unist-util-visit');
var slugs = require('github-slugger')();
var isClosingHeading = require('./is-closing-heading');
var isOpeningHeading = require('./is-opening-heading');
/* Constants. */
var HEADING = 'heading';
/**
* Search a node for a location.
*
* @param {Node} root - Parent to search in.
* @param {RegExp} expression - Heading-content to search
* for.
* @param {number} maxDepth - Maximum-depth to include.
* @return {Object} - Results.
*/
function search(root, expression, maxDepth) {
var length = root.children.length;
var depth = null;
var lookingForToc = expression !== null;
var map = [];
var headingIndex;
var closingIndex;
if (!lookingForToc) {
headingIndex = -1;
}
slugs.reset();
/*
* Visit all headings in `root`.
* We `slug` all headings (to account for duplicates),
* but only create a TOC from top-level headings.
*/
visit(root, HEADING, function(child, index, parent) {
var value = toString(child);
var id =
child.data && child.data.hProperties && child.data.hProperties.id;
id = slugs.slug(id || value);
if (parent !== root) {
return;
}
if (lookingForToc) {
if (isClosingHeading(child, depth)) {
closingIndex = index;
lookingForToc = false;
}
if (isOpeningHeading(child, depth, expression)) {
headingIndex = index + 1;
depth = child.depth;
}
}
if (!lookingForToc && value && child.depth <= maxDepth) {
map.push({
depth: child.depth,
value: value,
id: id
});
}
});
if (headingIndex && !closingIndex) {
closingIndex = length + 1;
}
if (headingIndex === undefined) {
headingIndex = -1;
closingIndex = -1;
map = [];
}
return {
index: headingIndex,
endIndex: closingIndex,
map: map
};
}

20
node_modules/mdast-util-toc/lib/to-expression.js generated vendored Normal file
View File

@ -0,0 +1,20 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module mdast:toc
* @fileoverview Generate a Table of Contents (TOC) from a given Markdown file.
*/
/* Expose. */
module.exports = toExpression;
/**
* Transform a string into an applicable expression.
*
* @param {string} value - Content to expressionise.
* @return {RegExp} - Expression from `value`.
*/
function toExpression(value) {
return new RegExp('^(' + value + ')$', 'i');
}

120
node_modules/mdast-util-toc/package.json generated vendored Normal file
View File

@ -0,0 +1,120 @@
{
"_from": "mdast-util-toc@^2.0.1",
"_id": "mdast-util-toc@2.1.0",
"_inBundle": false,
"_integrity": "sha512-ove/QQWSrYOrf9G3xn2MTAjy7PKCtCmm261wpQwecoPAsUtkihkMVczxFqil7VihxgSz4ID9c8bBTsyXR30gQg==",
"_location": "/mdast-util-toc",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "mdast-util-toc@^2.0.1",
"name": "mdast-util-toc",
"escapedName": "mdast-util-toc",
"rawSpec": "^2.0.1",
"saveSpec": null,
"fetchSpec": "^2.0.1"
},
"_requiredBy": [
"/gatsby-transformer-remark"
],
"_resolved": "https://registry.npmjs.org/mdast-util-toc/-/mdast-util-toc-2.1.0.tgz",
"_shasum": "82b6b218577bb0e67b23abf5c3f7ac73a4b5389f",
"_spec": "mdast-util-toc@^2.0.1",
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/gatsby-transformer-remark",
"author": {
"name": "Titus Wormer",
"email": "tituswormer@gmail.com",
"url": "http://wooorm.com"
},
"bugs": {
"url": "https://github.com/barrythepenguin/mdast-util-toc/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Titus Wormer",
"email": "tituswormer@gmail.com",
"url": "http://wooorm.com"
},
{
"name": "Jonathan Haines",
"email": "jonno.haines@gmail.com",
"url": "http://barrythepenguin.github.io"
}
],
"dependencies": {
"github-slugger": "^1.1.1",
"mdast-util-to-string": "^1.0.2",
"unist-util-visit": "^1.1.0"
},
"deprecated": false,
"description": "Generate a Table of Contents (TOC) from a given Markdown file",
"devDependencies": {
"browserify": "^16.2.1",
"esmangle": "^1.0.1",
"istanbul": "^0.4.4",
"remark": "^9.0.0",
"remark-attr": "^0.6.2",
"remark-cli": "^5.0.0",
"remark-comment-config": "^5.0.0",
"remark-github": "^7.0.0",
"remark-preset-lint-consistent": "^2.0.0",
"remark-preset-lint-recommended": "^3.0.0",
"remark-usage": "^6.0.0",
"remark-validate-links": "^7.0.0",
"tape": "^4.6.0",
"xo": "^0.21.1"
},
"files": [
"lib",
"index.js"
],
"homepage": "https://github.com/barrythepenguin/mdast-util-toc#readme",
"keywords": [
"mdast",
"util",
"toc"
],
"license": "MIT",
"main": "index.js",
"name": "mdast-util-toc",
"repository": {
"type": "git",
"url": "git+https://github.com/barrythepenguin/mdast-util-toc.git"
},
"scripts": {
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"build-bundle": "browserify index.js --no-builtins -s mdastUtilTOC > mdast-util-toc.js",
"build-mangle": "esmangle mdast-util-toc.js > mdast-util-toc.min.js",
"build-md": "remark . --quiet --frail --output",
"lint": "xo",
"test": "npm run build && npm run lint && npm run test-coverage",
"test-api": "node test/index.js",
"test-coverage": "istanbul cover test/index.js"
},
"version": "2.1.0",
"xo": {
"space": 4,
"esnext": false,
"prettier": true,
"ignore": [
"example.js"
],
"rules": {
"valid-jsdoc": [
"error"
],
"require-jsdoc": [
"error",
{
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}
]
}
}
}