WIP - add extractor, generate snippet_data
This commit is contained in:
54
node_modules/hast-util-parse-selector/index.js
generated
vendored
Normal file
54
node_modules/hast-util-parse-selector/index.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = parse
|
||||
|
||||
var numberSign = 35 // '#'
|
||||
var dot = 46 // '.'
|
||||
|
||||
// Create a hast element from a simple CSS selector.
|
||||
function parse(selector, defaultTagName) {
|
||||
var value = selector || ''
|
||||
var name = defaultTagName || 'div'
|
||||
var props = {}
|
||||
var index = -1
|
||||
var length = value.length
|
||||
var className
|
||||
var type
|
||||
var code
|
||||
var subvalue
|
||||
var lastIndex
|
||||
|
||||
while (++index <= length) {
|
||||
code = value.charCodeAt(index)
|
||||
|
||||
if (!code || code === dot || code === numberSign) {
|
||||
subvalue = value.slice(lastIndex, index)
|
||||
|
||||
if (subvalue) {
|
||||
if (type === dot) {
|
||||
// eslint-disable-next-line max-depth
|
||||
if (className) {
|
||||
className.push(subvalue)
|
||||
} else {
|
||||
className = [subvalue]
|
||||
props.className = className
|
||||
}
|
||||
} else if (type === numberSign) {
|
||||
props.id = subvalue
|
||||
} else {
|
||||
name = subvalue
|
||||
}
|
||||
}
|
||||
|
||||
lastIndex = index + 1
|
||||
type = code
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'element',
|
||||
tagName: name,
|
||||
properties: props,
|
||||
children: []
|
||||
}
|
||||
}
|
||||
22
node_modules/hast-util-parse-selector/license
generated
vendored
Normal file
22
node_modules/hast-util-parse-selector/license
generated
vendored
Normal 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.
|
||||
108
node_modules/hast-util-parse-selector/package.json
generated
vendored
Normal file
108
node_modules/hast-util-parse-selector/package.json
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
{
|
||||
"_from": "hast-util-parse-selector@^2.2.0",
|
||||
"_id": "hast-util-parse-selector@2.2.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-jIMtnzrLTjzqgVEQqPEmwEZV+ea4zHRFTP8Z2Utw0I5HuBOXHzUPPQWr6ouJdJqDKLbFU/OEiYwZ79LalZkmmw==",
|
||||
"_location": "/hast-util-parse-selector",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "hast-util-parse-selector@^2.2.0",
|
||||
"name": "hast-util-parse-selector",
|
||||
"escapedName": "hast-util-parse-selector",
|
||||
"rawSpec": "^2.2.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.2.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/hastscript"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/hast-util-parse-selector/-/hast-util-parse-selector-2.2.2.tgz",
|
||||
"_shasum": "66aabccb252c47d94975f50a281446955160380b",
|
||||
"_spec": "hast-util-parse-selector@^2.2.0",
|
||||
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/hastscript",
|
||||
"author": {
|
||||
"name": "Titus Wormer",
|
||||
"email": "tituswormer@gmail.com",
|
||||
"url": "https://wooorm.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/syntax-tree/hast-util-parse-selector/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Titus Wormer",
|
||||
"email": "tituswormer@gmail.com",
|
||||
"url": "https://wooorm.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "Parse a simple CSS selector to a HAST node",
|
||||
"devDependencies": {
|
||||
"browserify": "^16.0.0",
|
||||
"nyc": "^14.0.0",
|
||||
"prettier": "^1.0.0",
|
||||
"remark-cli": "^6.0.0",
|
||||
"remark-preset-wooorm": "^5.0.0",
|
||||
"tape": "^4.0.0",
|
||||
"tinyify": "^2.0.0",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/syntax-tree/hast-util-parse-selector#readme",
|
||||
"keywords": [
|
||||
"hast",
|
||||
"rehype",
|
||||
"selector",
|
||||
"parse",
|
||||
"css",
|
||||
"html"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "hast-util-parse-selector",
|
||||
"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-parse-selector.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build-bundle && npm run build-mangle",
|
||||
"build-bundle": "browserify . -s hastUtilParseSelector > hast-util-parse-selector.js",
|
||||
"build-mangle": "browserify . -s hastUtilParseSelector -p tinyify > hast-util-parse-selector.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.js"
|
||||
},
|
||||
"version": "2.2.2",
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"ignores": [
|
||||
"hast-util-parse-selector.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
119
node_modules/hast-util-parse-selector/readme.md
generated
vendored
Normal file
119
node_modules/hast-util-parse-selector/readme.md
generated
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
# hast-util-parse-selector
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
[**hast**][hast] utility to create an [*element*][element] from a simple CSS
|
||||
selector.
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install hast-util-parse-selector
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var parseSelector = require('hast-util-parse-selector')
|
||||
|
||||
console.log(parseSelector('.quux#bar.baz.qux'))
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```js
|
||||
{ type: 'element',
|
||||
tagName: 'div',
|
||||
properties: { id: 'bar', className: [ 'quux', 'baz', 'qux' ] },
|
||||
children: [] }
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `parseSelector([selector][, defaultTagName])`
|
||||
|
||||
Create an [*element*][element] [*node*][node] from a simple CSS selector.
|
||||
|
||||
###### `selector`
|
||||
|
||||
`string`, optional — Can contain a tag-name (`foo`), classes (`.bar`),
|
||||
and an ID (`#baz`).
|
||||
Multiple classes are allowed.
|
||||
Uses the last ID if multiple IDs are found.
|
||||
|
||||
###### `defaultTagName`
|
||||
|
||||
`string`, optional, defaults to `div` — Tag name to use if `selector` does not
|
||||
specify one.
|
||||
|
||||
###### Returns
|
||||
|
||||
[`Element`][element].
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
|
||||
started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project 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 -->
|
||||
|
||||
[build-badge]: https://img.shields.io/travis/syntax-tree/hast-util-parse-selector.svg
|
||||
|
||||
[build]: https://travis-ci.org/syntax-tree/hast-util-parse-selector
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-parse-selector.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/hast-util-parse-selector
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/hast-util-parse-selector.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/hast-util-parse-selector
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-parse-selector.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=hast-util-parse-selector
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
|
||||
|
||||
[chat]: https://spectrum.chat/unified/syntax-tree
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
|
||||
|
||||
[support]: https://github.com/syntax-tree/.github/blob/master/support.md
|
||||
|
||||
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
|
||||
|
||||
[hast]: https://github.com/syntax-tree/hast
|
||||
|
||||
[node]: https://github.com/syntax-tree/hast#nodes
|
||||
|
||||
[element]: https://github.com/syntax-tree/hast#element
|
||||
Reference in New Issue
Block a user