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

22
node_modules/hast-util-from-parse5/LICENSE generated vendored Normal file
View File

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

234
node_modules/hast-util-from-parse5/index.js generated vendored Normal file
View File

@ -0,0 +1,234 @@
'use strict'
var html = require('property-information/html')
var svg = require('property-information/svg')
var find = require('property-information/find')
var ns = require('web-namespaces')
var s = require('hastscript/svg')
var h = require('hastscript')
var xtend = require('xtend')
var count = require('ccount')
module.exports = wrapper
var own = {}.hasOwnProperty
/* Handlers. */
var map = {
'#document': root,
'#document-fragment': root,
'#text': text,
'#comment': comment,
'#documentType': doctype
}
/* Wrapper to normalise options. */
function wrapper(ast, options) {
var settings = options || {}
var file
if (settings.messages) {
file = settings
settings = {}
} else {
file = settings.file
}
return transform(ast, {
schema: settings.space === 'svg' ? svg : html,
file: file,
verbose: settings.verbose,
location: false
})
}
/* Transform a node. */
function transform(ast, config) {
var schema = config.schema
var fn = own.call(map, ast.nodeName) ? map[ast.nodeName] : element
var children
var node
var pos
if (fn === element) {
config.schema = ast.namespaceURI === ns.svg ? svg : html
}
if (ast.childNodes) {
children = nodes(ast.childNodes, config)
}
node = fn(ast, children, config)
if (ast.sourceCodeLocation && config.file) {
pos = location(node, ast.sourceCodeLocation, config)
if (pos) {
config.location = true
node.position = pos
}
}
config.schema = schema
return node
}
/* Transform children. */
function nodes(children, config) {
var length = children.length
var index = -1
var result = []
while (++index < length) {
result[index] = transform(children[index], config)
}
return result
}
/* Transform a document.
* Stores `ast.quirksMode` in `node.data.quirksMode`. */
function root(ast, children, config) {
var node = {type: 'root', children: children, data: {}}
var doc
node.data.quirksMode = ast.mode === 'quirks' || ast.mode === 'limited-quirks'
if (config.file && config.location) {
doc = String(config.file)
node.position = {
start: {line: 1, column: 1, offset: 0},
end: {
line: count(doc, '\n') + 1,
column: doc.length - doc.lastIndexOf('\n'),
offset: doc.length
}
}
}
return node
}
/* Transform a doctype. */
function doctype(ast) {
return {
type: 'doctype',
name: ast.name || '',
public: ast.publicId || null,
system: ast.systemId || null
}
}
/* Transform a text. */
function text(ast) {
return {type: 'text', value: ast.value}
}
/* Transform a comment. */
function comment(ast) {
return {type: 'comment', value: ast.data}
}
/* Transform an element. */
function element(ast, children, config) {
var fn = config.schema.space === 'svg' ? s : h
var name = ast.tagName
var attributes = ast.attrs
var length = attributes.length
var props = {}
var index = -1
var attribute
var prop
var node
var pos
var start
var end
while (++index < length) {
attribute = attributes[index]
prop = (attribute.prefix ? attribute.prefix + ':' : '') + attribute.name
props[prop] = attribute.value
}
node = fn(name, props, children)
if (name === 'template' && 'content' in ast) {
pos = ast.sourceCodeLocation
start = pos && pos.startTag && position(pos.startTag).end
end = pos && pos.endTag && position(pos.endTag).start
node.content = transform(ast.content, config)
if ((start || end) && config.file) {
node.content.position = {start: start, end: end}
}
}
return node
}
/* Create clean positional information. */
function location(node, location, config) {
var schema = config.schema
var verbose = config.verbose
var pos = position(location)
var reference
var attributes
var attribute
var props
var prop
if (node.type === 'element') {
reference = node.children[node.children.length - 1]
/* Unclosed with children (upstream: https://github.com/inikulin/parse5/issues/109) */
if (
!location.endTag &&
reference &&
reference.position &&
reference.position.end
) {
pos.end = xtend(reference.position.end)
}
if (verbose) {
attributes = location.attrs
props = {}
for (attribute in attributes) {
prop = find(schema, attribute).property
props[prop] = position(attributes[attribute])
}
node.data = {
position: {
opening: position(location.startTag),
closing: location.endTag ? position(location.endTag) : null,
properties: props
}
}
}
}
return pos
}
function position(loc) {
var start = point({
line: loc.startLine,
column: loc.startCol,
offset: loc.startOffset
})
var end = point({
line: loc.endLine,
column: loc.endCol,
offset: loc.endOffset
})
return start || end ? {start: start, end: end} : null
}
function point(point) {
return point.line && point.column ? point : null
}

121
node_modules/hast-util-from-parse5/package.json generated vendored Normal file
View File

@ -0,0 +1,121 @@
{
"_from": "hast-util-from-parse5@^4.0.2",
"_id": "hast-util-from-parse5@4.0.2",
"_inBundle": false,
"_integrity": "sha512-I6dtjsGtDqz4fmGSiFClFyiXdKhj5bPceS6intta7k/VDuiKz9P61C6hO6WMiNNmEm1b/EtBH8f+juvz4o0uwQ==",
"_location": "/hast-util-from-parse5",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "hast-util-from-parse5@^4.0.2",
"name": "hast-util-from-parse5",
"escapedName": "hast-util-from-parse5",
"rawSpec": "^4.0.2",
"saveSpec": null,
"fetchSpec": "^4.0.2"
},
"_requiredBy": [
"/hast-util-raw"
],
"_resolved": "https://registry.npmjs.org/hast-util-from-parse5/-/hast-util-from-parse5-4.0.2.tgz",
"_shasum": "b7164a7ffc88da4f751dc7c2f801ff8d7c143bab",
"_spec": "hast-util-from-parse5@^4.0.2",
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/hast-util-raw",
"author": {
"name": "Titus Wormer",
"email": "tituswormer@gmail.com",
"url": "http://wooorm.com"
},
"bugs": {
"url": "https://github.com/syntax-tree/hast-util-from-parse5/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Titus Wormer",
"email": "tituswormer@gmail.com",
"url": "http://wooorm.com"
}
],
"dependencies": {
"ccount": "^1.0.3",
"hastscript": "^4.0.0",
"property-information": "^4.0.0",
"web-namespaces": "^1.1.2",
"xtend": "^4.0.1"
},
"deprecated": false,
"description": "Transform Parse5s AST to HAST",
"devDependencies": {
"browserify": "^16.0.0",
"esmangle": "^1.0.1",
"is-hidden": "^1.1.0",
"not": "^0.1.0",
"nyc": "^12.0.0",
"parse5": "^5.0.0",
"prettier": "^1.13.5",
"remark-cli": "^5.0.0",
"remark-preset-wooorm": "^4.0.0",
"tape": "^4.0.0",
"tinyify": "^2.4.3",
"to-vfile": "^5.0.0",
"unist-util-visit": "^1.1.3",
"xo": "^0.21.0"
},
"files": [
"index.js"
],
"homepage": "https://github.com/syntax-tree/hast-util-from-parse5#readme",
"keywords": [
"parse5",
"ast",
"hast",
"utility"
],
"license": "MIT",
"name": "hast-util-from-parse5",
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/syntax-tree/hast-util-from-parse5.git"
},
"scripts": {
"build": "npm run build-bundle && npm run build-mangle",
"build-bundle": "browserify index.js -s hastUtilFromParse5 > hast-util-from-parse5.js",
"build-mangle": "browserify index.js -p tinyify -s hastUtilFromParse5 > hast-util-from-parse5.min.js",
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
"test": "npm run format && npm run build && npm run test-coverage",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test"
},
"version": "4.0.2",
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"guard-for-in": "off"
},
"ignores": [
"hast-util-from-parse5.js"
]
}
}

168
node_modules/hast-util-from-parse5/readme.md generated vendored Normal file
View File

@ -0,0 +1,168 @@
# hast-util-from-parse5 [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]
Transform [HAST][] to [Parse5s AST][ast].
## Installation
[npm][]:
```bash
npm install hast-util-from-parse5
```
## Usage
Say we have the following file, `example.html`:
```html
<!doctype html><title>Hello!</title><h1 id="world">World!<!--after-->
```
And our script, `example.js`, looks as follows:
```javascript
var vfile = require('to-vfile')
var parse5 = require('parse5')
var inspect = require('unist-util-inspect')
var fromParse5 = require('hast-util-from-parse5')
var doc = vfile.readSync('example.html')
var ast = parse5.parse(String(doc), {sourceCodeLocationInfo: true})
var hast = fromParse5(ast, doc)
console.log(inspect(hast))
```
Now, running `node example` yields:
```text
root[2] (1:1-2:1, 0-70) [data={"quirksMode":false}]
├─ doctype (1:1-1:16, 0-15) [name="html"]
└─ element[2] [tagName="html"]
├─ element[1] [tagName="head"]
│ └─ element[1] (1:16-1:37, 15-36) [tagName="title"]
│ └─ text: "Hello!" (1:23-1:29, 22-28)
└─ element[1] [tagName="body"]
└─ element[3] (1:37-2:1, 36-70) [tagName="h1"][properties={"id":"world"}]
├─ text: "World!" (1:52-1:58, 51-57)
├─ comment: "after" (1:58-1:70, 57-69)
└─ text: "\n" (1:70-2:1, 69-70)
```
## API
### `fromParse5(ast[, options])`
Transform an `ASTNode` to a [HAST Node][node].
##### `options`
If `options` is a [VFile][], its treated as `{file: options}`.
###### `options.space`
Whether the root of the given tree is in the `'html'` or `'svg'` space (enum,
`'svg'` or `'html'`, default: `'html'`).
If an element in with the SVG namespace is found in `ast`, `fromParse5`
automatically switches to the SVG space when entering the element, and
switches back when leaving.
###### `options.file`
[Virtual file][vfile], used to add positional information to HAST nodes.
If given, the file should have the original HTML source as its contents.
###### `options.verbose`
Whether to add positional information about starting tags, closing tags,
and attributes to elements (`boolean`, default: `false`). Note: not used
without `file`.
For the following HTML:
```html
<img src="http://example.com/fav.ico" alt="foo" title="bar">
```
The verbose info would looks as follows:
```js
{
type: 'element',
tagName: 'img',
properties: {
src: 'http://example.com/fav.ico',
alt: 'foo',
title: 'bar'
},
children: [],
data: {
position: {
opening: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 61, offset: 60}
},
closing: null,
properties: {
src: {
start: {line: 1, column: 6, offset: 5},
end: {line: 1, column: 38, offset: 37}
},
alt: {
start: {line: 1, column: 39, offset: 38},
end: {line: 1, column: 48, offset: 47}
},
title: {
start: {line: 1, column: 49, offset: 48},
end: {line: 1, column: 60, offset: 59}
}
}
}
},
position: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 61, offset: 60}
}
}
```
## Contribute
See [`contributing.md` in `syntax-tree/hast`][contributing] for ways to get
started.
This organisation has a [Code of Conduct][coc]. By interacting with this
repository, organisation, or community you agree to abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[travis-badge]: https://img.shields.io/travis/syntax-tree/hast-util-from-parse5.svg
[travis]: https://travis-ci.org/syntax-tree/hast-util-from-parse5
[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-from-parse5.svg
[codecov]: https://codecov.io/github/syntax-tree/hast-util-from-parse5
[npm]: https://docs.npmjs.com/cli/install
[license]: LICENSE
[author]: http://wooorm.com
[hast]: https://github.com/syntax-tree/hast
[ast]: https://github.com/inikulin/parse5/wiki/Documentation
[node]: https://github.com/syntax-tree/hast#ast
[vfile]: https://github.com/vfile/vfile
[contributing]: https://github.com/syntax-tree/hast/blob/master/contributing.md
[coc]: https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md