rehype-document
Advanced tools
Comparing version 2.0.1 to 2.1.0
80
index.js
@@ -1,63 +0,75 @@ | ||
'use strict'; | ||
'use strict' | ||
var u = require('unist-builder'); | ||
var h = require('hastscript'); | ||
var doctypes = require('doctype'); | ||
var u = require('unist-builder') | ||
var h = require('hastscript') | ||
var doctypes = require('doctype') | ||
module.exports = attacher; | ||
module.exports = document | ||
function attacher(options) { | ||
var settings = options || {}; | ||
var css = settings.css || []; | ||
var js = settings.js || []; | ||
function document(options) { | ||
var settings = options || {} | ||
var meta = settings.meta || [] | ||
var css = settings.css || [] | ||
var js = settings.js || [] | ||
if (!('length' in meta)) { | ||
meta = [meta] | ||
} | ||
if (settings.responsive !== false) { | ||
meta.unshift({ | ||
name: 'viewport', | ||
content: 'width=device-width, initial-scale=1' | ||
}) | ||
} | ||
if (typeof css === 'string') { | ||
css = [css]; | ||
css = [css] | ||
} | ||
if (typeof js === 'string') { | ||
js = [js]; | ||
js = [js] | ||
} | ||
return transformer; | ||
return transformer | ||
function transformer(tree, file) { | ||
var title = settings.title || file.stem; | ||
var body = tree.children.concat(); | ||
var head = [line(), h('meta', {charset: 'utf-8'})]; | ||
var length; | ||
var index; | ||
var title = settings.title || file.stem | ||
var body = tree.children.concat() | ||
var head = [line(), h('meta', {charset: 'utf-8'})] | ||
var length | ||
var index | ||
if (body.length !== 0) { | ||
body.unshift(line()); | ||
body.unshift(line()) | ||
} | ||
if (title) { | ||
head.push(line(), h('title', [title])); | ||
head.push(line(), h('title', [title])) | ||
} | ||
if (settings.responsive !== false) { | ||
head.push(line(), h('meta', { | ||
name: 'viewport', | ||
content: 'width=device-width, initial-scale=1' | ||
})); | ||
length = meta.length | ||
index = -1 | ||
while (++index < length) { | ||
head.push(line(), h('meta', meta[index])) | ||
} | ||
length = css.length; | ||
index = -1; | ||
length = css.length | ||
index = -1 | ||
while (++index < length) { | ||
head.push(line(), h('link', {rel: 'stylesheet', href: css[index]})); | ||
head.push(line(), h('link', {rel: 'stylesheet', href: css[index]})) | ||
} | ||
head.push(line()); | ||
head.push(line()) | ||
length = js.length; | ||
index = -1; | ||
length = js.length | ||
index = -1 | ||
while (++index < length) { | ||
body.push(line(), h('script', {src: js[index]})); | ||
body.push(line(), h('script', {src: js[index]})) | ||
} | ||
body.push(line()); | ||
body.push(line()) | ||
@@ -75,3 +87,3 @@ return u('root', [ | ||
line() | ||
]); | ||
]) | ||
} | ||
@@ -81,3 +93,3 @@ } | ||
function line() { | ||
return u('text', '\n'); | ||
return u('text', '\n') | ||
} |
{ | ||
"name": "rehype-document", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Wrap a document around the syntax tree", | ||
@@ -14,4 +14,4 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/wooorm/rehype-document", | ||
"bugs": "https://github.com/wooorm/rehype-document/issues", | ||
"repository": "rehypejs/rehype-document", | ||
"bugs": "https://github.com/rehypejs/rehype-document/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
@@ -26,24 +26,24 @@ "contributors": [ | ||
"doctype": "^2.0.0", | ||
"hastscript": "^3.0.0", | ||
"hastscript": "^4.0.0", | ||
"unist-builder": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^14.1.0", | ||
"esmangle": "^1.0.1", | ||
"nyc": "^11.0.0", | ||
"rehype": "^5.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"browserify": "^16.0.0", | ||
"nyc": "^12.0.0", | ||
"prettier": "^1.13.4", | ||
"rehype": "^6.0.0", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.18.0" | ||
"tinyify": "^2.4.3", | ||
"xo": "^0.21.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . -qfo", | ||
"build-bundle": "browserify index.js --bare -s rehypeDocument > rehype-document.js", | ||
"build-mangle": "esmangle rehype-document.js > rehype-document.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"build-bundle": "browserify index.js -s rehypeDocument > rehype-document.js", | ||
"build-mangle": "browserify index.js -s rehypeDocument -p tinyify > rehype-document.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
}, | ||
@@ -56,5 +56,17 @@ "nyc": { | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
}, | ||
"ignores": [ | ||
@@ -61,0 +73,0 @@ "rehype-document.js" |
@@ -26,9 +26,9 @@ # rehype-document [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
```javascript | ||
var vfile = require('to-vfile'); | ||
var report = require('vfile-reporter'); | ||
var unified = require('unified'); | ||
var parse = require('remark-parse'); | ||
var mutate = require('remark-rehype'); | ||
var stringify = require('rehype-stringify'); | ||
var doc = require('rehype-document'); | ||
var vfile = require('to-vfile') | ||
var report = require('vfile-reporter') | ||
var unified = require('unified') | ||
var parse = require('remark-parse') | ||
var mutate = require('remark-rehype') | ||
var stringify = require('rehype-stringify') | ||
var doc = require('rehype-document') | ||
@@ -40,6 +40,6 @@ unified() | ||
.use(stringify) | ||
.process(vfile.readSync('example.md'), function (err, file) { | ||
console.error(report(err || file)); | ||
console.log(String(file)); | ||
}); | ||
.process(vfile.readSync('example.md'), function(err, file) { | ||
console.error(report(err || file)) | ||
console.log(String(file)) | ||
}) | ||
``` | ||
@@ -51,3 +51,3 @@ | ||
example.md: no issues found | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en"> | ||
@@ -94,2 +94,8 @@ <head> | ||
###### `options.meta` | ||
`Object` or `Array.<Object>`, default: `[]` — Metadata to include in `head`. | ||
Each object is passed as [`properties`][props] to [`hastscript`][h] with a `meta` | ||
element. | ||
###### `options.js` | ||
@@ -102,7 +108,15 @@ | ||
* [`rehype-format`](https://github.com/wooorm/rehype-format) | ||
* [`rehype-format`](https://github.com/rehypejs/rehype-format) | ||
— Format HTML | ||
* [`rehype-minify`](https://github.com/wooorm/rehype-minify) | ||
* [`rehype-minify`](https://github.com/rehypejs/rehype-minify) | ||
— Minify HTML | ||
## Contribute | ||
See [`contributing.md` in `rehypejs/rehype`][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 | ||
@@ -114,9 +128,9 @@ | ||
[travis-badge]: https://img.shields.io/travis/wooorm/rehype-document.svg | ||
[travis-badge]: https://img.shields.io/travis/rehypejs/rehype-document.svg | ||
[travis]: https://travis-ci.org/wooorm/rehype-document | ||
[travis]: https://travis-ci.org/rehypejs/rehype-document | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/rehype-document.svg | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-document.svg | ||
[codecov]: https://codecov.io/github/wooorm/rehype-document | ||
[codecov]: https://codecov.io/github/rehypejs/rehype-document | ||
@@ -129,4 +143,12 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[rehype]: https://github.com/wooorm/rehype | ||
[rehype]: https://github.com/rehypejs/rehype | ||
[doctype]: https://github.com/wooorm/doctype | ||
[contributing]: https://github.com/rehypejs/rehype/blob/master/contributing.md | ||
[coc]: https://github.com/rehypejs/rehype/blob/master/code-of-conduct.md | ||
[props]: https://github.com/syntax-tree/hastscript#hselector-properties-children | ||
[h]: https://github.com/syntax-tree/hastscript |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
8091
72
148
9
+ Addedhastscript@4.1.0(transitive)
+ Addedproperty-information@4.2.0(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedcamelcase@3.0.0(transitive)
- Removedhastscript@3.1.0(transitive)
- Removedproperty-information@3.2.0(transitive)
Updatedhastscript@^4.0.0