Socket
Socket
Sign inDemoInstall

rehype-format

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-format - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

112

index.js

@@ -1,25 +0,26 @@

'use strict';
'use strict'
var minify = require('rehype-minify-whitespace')({newlines: true});
var phrasing = require('hast-util-phrasing');
var sensitive = require('html-whitespace-sensitive-tag-names');
var repeat = require('repeat-string');
var visit = require('unist-util-visit-parents');
var minify = require('rehype-minify-whitespace')({newlines: true})
var phrasing = require('hast-util-phrasing')
var embedded = require('hast-util-embedded')
var sensitive = require('html-whitespace-sensitive-tag-names')
var repeat = require('repeat-string')
var visit = require('unist-util-visit-parents')
module.exports = format;
module.exports = format
/* Constants. */
var double = '\n\n';
var single = '\n';
var re = /\n/g;
var double = '\n\n'
var single = '\n'
var re = /\n/g
/* Format white-space. */
function format(options) {
var settings = options || {};
var indent = settings.indent || 2;
var indentInitial = settings.indentInitial;
var blanks = settings.blanks || [];
var settings = options || {}
var indent = settings.indent || 2
var indentInitial = settings.indentInitial
var blanks = settings.blanks || []
if (typeof indent === 'number') {
indent = repeat(' ', indent);
indent = repeat(' ', indent)
}

@@ -29,31 +30,31 @@

if (indentInitial === null || indentInitial === undefined) {
indentInitial = true;
indentInitial = true
}
return transform;
return transform
function transform(tree) {
var root = minify(tree);
var head = false;
var root = minify(tree)
var head = false
visit(root, visitor);
visit(root, visitor)
return root;
return root
function visitor(node, parents) {
var children = node.children || [];
var length = children.length;
var level = parents.length;
var index = -1;
var result;
var prev;
var child;
var newline;
var children = node.children || []
var length = children.length
var level = parents.length
var index = -1
var result
var prev
var child
var newline
if (node.type === 'element' && node.tagName === 'head') {
head = true;
head = true
}
if (head && node.type === 'element' && node.tagName === 'body') {
head = false;
head = false
}

@@ -63,7 +64,7 @@

if (!length || !padding(node, head) || ignore(parents.concat(node))) {
return;
return
}
if (!indentInitial) {
level--;
level--
}

@@ -73,20 +74,20 @@

while (++index < length) {
child = children[index];
child = children[index]
if (child.type === 'text') {
if (child.value.indexOf('\n') !== -1) {
newline = true;
newline = true
}
child.value = child.value.replace(re, '$&' + repeat(indent, level));
child.value = child.value.replace(re, '$&' + repeat(indent, level))
}
}
result = [];
index = -1;
result = []
index = -1
node.children = result;
node.children = result
while (++index < length) {
child = children[index];
child = children[index]

@@ -96,9 +97,10 @@ if (padding(child, head) || (newline && index === 0)) {

type: 'text',
value: ((prev && blank(prev) && blank(child)) ? double : single) +
value:
(prev && blank(prev) && blank(child) ? double : single) +
repeat(indent, level)
});
})
}
prev = child;
result.push(child);
prev = child
result.push(child)
}

@@ -110,3 +112,3 @@

value: single + repeat(indent, level - 1)
});
})
}

@@ -117,5 +119,7 @@ }

function blank(node) {
return node.type === 'element' &&
return (
node.type === 'element' &&
blanks.length !== 0 &&
blanks.indexOf(node.tagName) !== -1;
blanks.indexOf(node.tagName) !== -1
)
}

@@ -126,22 +130,24 @@ }

if (node.type === 'root') {
return true;
return true
}
if (node.type === 'element') {
return node.tagName === 'script' || !phrasing(node) || head;
return (
head || node.tagName === 'script' || embedded(node) || !phrasing(node)
)
}
return false;
return false
}
function ignore(nodes) {
var index = nodes.length;
var index = nodes.length
while (index--) {
if (sensitive.indexOf(nodes[index].tagName) !== -1) {
return true;
return true
}
}
return false;
return false
}
{
"name": "rehype-format",
"version": "2.2.0",
"version": "2.3.0",
"description": "Format HTML with rehype",

@@ -13,4 +13,4 @@ "license": "MIT",

],
"repository": "https://github.com/wooorm/rehype-format",
"bugs": "https://github.com/wooorm/rehype-format/issues",
"repository": "rehypejs/rehype-format",
"bugs": "https://github.com/rehypejs/rehype-format/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",

@@ -24,2 +24,3 @@ "contributors": [

"dependencies": {
"hast-util-embedded": "^1.0.1",
"hast-util-phrasing": "^1.0.0",

@@ -33,23 +34,23 @@ "html-whitespace-sensitive-tag-names": "^1.0.0",

"bail": "^1.0.1",
"browserify": "^14.1.0",
"esmangle": "^1.0.0",
"browserify": "^16.0.0",
"is-hidden": "^1.0.1",
"negate": "^1.0.0",
"nyc": "^11.0.0",
"rehype": "^5.0.0",
"remark-cli": "^3.0.0",
"remark-preset-wooorm": "^3.0.0",
"nyc": "^12.0.0",
"prettier": "^1.13.7",
"rehype": "^6.0.0",
"remark-cli": "^5.0.0",
"remark-preset-wooorm": "^4.0.0",
"tape": "^4.0.0",
"to-vfile": "^2.1.1",
"xo": "^0.18.0"
"tinyify": "^2.4.3",
"to-vfile": "^5.0.0",
"xo": "^0.21.0"
},
"scripts": {
"build-md": "remark . -qfo",
"build-bundle": "browserify index.js --bare -s rehypeFormat > rehype-format.js",
"build-mangle": "esmangle rehype-format.js > rehype-format.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"test-api": "node test/index.js",
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
"build-bundle": "browserify index.js -s rehypeFormat > rehype-format.js",
"build-mangle": "browserify index.js -s rehypeFormat -p tinyify > rehype-format.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test": "npm run build && npm run lint && npm run test-coverage"
"test": "npm run format && npm run build && npm run test-coverage"
},

@@ -62,5 +63,16 @@ "nyc": {

},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"space": true,
"prettier": true,
"esnext": false,
"rules": {
"complexity": "off"
},
"ignores": [

@@ -71,4 +83,6 @@ "rehype-format.js"

"remarkConfig": {
"plugins": ["preset-wooorm"]
"plugins": [
"preset-wooorm"
]
}
}

@@ -47,3 +47,3 @@ # rehype-format [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]

index.html: no issues found
<!DOCTYPE html>
<!doctype html>
<html>

@@ -100,5 +100,13 @@ <head>

* [`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`][contribute] 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

@@ -110,9 +118,9 @@

[travis-badge]: https://img.shields.io/travis/wooorm/rehype-format.svg
[travis-badge]: https://img.shields.io/travis/rehypejs/rehype-format.svg
[travis]: https://travis-ci.org/wooorm/rehype-format
[travis]: https://travis-ci.org/rehypejs/rehype-format
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/rehype-format.svg
[codecov-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-format.svg
[codecov]: https://codecov.io/github/wooorm/rehype-format
[codecov]: https://codecov.io/github/rehypejs/rehype-format

@@ -125,2 +133,6 @@ [npm]: https://docs.npmjs.com/cli/install

[rehype]: https://github.com/wooorm/rehype
[rehype]: https://github.com/rehypejs/rehype
[contribute]: https://github.com/rehypejs/rehype/blob/master/contributing.md
[coc]: https://github.com/rehypejs/rehype/blob/master/code-of-conduct.md
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc