Comparing version 1.0.0 to 2.0.0
58
index.js
/*! | ||
* pretty <https://github.com/jonschlinkert/pretty> | ||
* | ||
* Copyright (c) 2013-2015, Jon Schlinkert. | ||
* Licensed under the MIT license. | ||
* Copyright (c) 2013-2015, 2017, Jon Schlinkert. | ||
* Released under the MIT License. | ||
*/ | ||
@@ -11,40 +11,36 @@ | ||
var beautify = require('js-beautify'); | ||
var condense = require('condense-newlines'); | ||
var extend = require('extend-shallow'); | ||
var defaults = { | ||
unformatted: ['code', 'pre', 'em', 'strong', 'span'], | ||
indent_inner_html: true, | ||
indent_char: ' ', | ||
indent_size: 2, | ||
sep: '\n' | ||
}; | ||
module.exports = function pretty(str, options) { | ||
str = beautify.html(str, { | ||
indent_char: ' ', | ||
indent_size: 2, | ||
indent_inner_html: true, | ||
unformatted: ['code', 'pre', 'em', 'strong', 'span'] | ||
}); | ||
var opts = extend({}, defaults, options); | ||
str = beautify.html(str, opts); | ||
return ocd(str, options); | ||
if (opts.ocd === true) { | ||
if (opts.newlines) opts.sep = opts.newlines; | ||
return ocd(str, opts); | ||
} | ||
return str; | ||
}; | ||
function ocd(str, options) { | ||
return str | ||
// Remove any empty lines at the top of a file. | ||
.replace(/^\s*/g, '') | ||
// Normalize and condense all newlines | ||
.replace(/(\r\n|\n){2,}/g, '\n') | ||
// fix multiline, Bootstrap-style comments | ||
.replace(/(\s*)(<!--.+)\s*(===.+)/g, '$1$2$1$3') | ||
// make <li><a></li> on one line, but only when li > a | ||
.replace(/(<li>)(\s*)(<a .+)(\s*)(<\/li>)/g, '$1 $3 $5') | ||
// make <a><span></a> on one line, but only when a > span | ||
.replace(/(<a.+)(\s*)(<span .+)(\s*)(<\/a>)/g, '$1 $3 $5') | ||
// Adjust spacing for button > span | ||
.replace(/(<button.+)(<span.+)(\s*)(<\/button>)/g, '$1$3 $2$3$4') | ||
// Adjust spacing for span > input | ||
.replace(/(\s*)(<span.+)(\s*)(<input.+)(\s*)(<\/span>)/g, '$1$2$1 $4$1$6') | ||
// Add a newline for tags nested inside <h1-6> | ||
.replace(/(\s*)(<h[0-6](?:.+)?>)(.*)(<(?:small|span|strong|em)(?:.+)?)(\s*)(<\/h[0-6]>)/g, '$1$2$3$1 $4$1$6') | ||
// Normalize and condense all newlines | ||
return condense(str, options) | ||
// Remove empty whitespace the top of a file. | ||
.replace(/^\s+/g, '') | ||
// Remove extra whitespace from eof | ||
.replace(/\s+$/g, '\n') | ||
// Add a space above each comment | ||
.replace(/(\s*<!--)/g, '\n$1') | ||
// Fix conditional comments | ||
.replace(/( *)(<!--\[.+)(\s*)(.+\s*)?(.+\s*)?(<!\[endif\]-->)/g, '$1$2\n $1$4$1$5$1$6') | ||
// Bring closing comments up to the same line as closing tag. | ||
.replace(/\s*(<!--\s*\/.+)/g, '$1') | ||
// Add a space after some inline elements, since prettifying strips them sometimes | ||
.replace(/(<\/(a|small|span|strong|em)>(?:(?!,)))/g, '$1 '); | ||
.replace(/>(\s*)(?=<!--\s*\/)/g, '> '); | ||
} |
{ | ||
"name": "pretty", | ||
"description": "Some tweaks for beautifying HTML with js-beautify according to my preferences.", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/jonschlinkert/pretty", | ||
"author": { | ||
"name": "Jon Schlinkert", | ||
"url": "https://github.com/jonschlinkert" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jonschlinkert/pretty.git" | ||
}, | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"repository": "jonschlinkert/pretty", | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/pretty/issues" | ||
}, | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/pretty/blob/master/LICENSE-MIT" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"main": "index.js", | ||
"scripts": { | ||
"docs": "update && license && npmignore && deps && verb", | ||
"all": "npm run docs" | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"js-beautify": "~1.5.4" | ||
"condense-newlines": "^0.2.1", | ||
"extend-shallow": "^2.0.1", | ||
"js-beautify": "^1.6.12" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
"gulp-format-md": "^0.1.12", | ||
"mocha": "^3.2.0" | ||
}, | ||
@@ -45,3 +40,16 @@ "keywords": [ | ||
"pretty" | ||
] | ||
], | ||
"verb": { | ||
"toc": false, | ||
"layout": "default", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"lint": { | ||
"reflinks": true | ||
} | ||
} | ||
} |
@@ -1,11 +0,19 @@ | ||
# pretty [![NPM version](https://badge.fury.io/js/pretty.svg)](http://badge.fury.io/js/pretty) | ||
# pretty [![NPM version](https://img.shields.io/npm/v/pretty.svg?style=flat)](https://www.npmjs.com/package/pretty) [![NPM monthly downloads](https://img.shields.io/npm/dm/pretty.svg?style=flat)](https://npmjs.org/package/pretty) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/pretty.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/pretty) | ||
> Some tweaks for beautifying HTML with js-beautify according to my preferences. | ||
## Install with [npm](npmjs.org) | ||
## Install | ||
```bash | ||
npm i pretty --save | ||
Install with [npm](https://www.npmjs.com/): | ||
```sh | ||
$ npm install --save pretty | ||
``` | ||
Install with [yarn](https://yarnpkg.com): | ||
```sh | ||
$ yarn add pretty | ||
``` | ||
## Usage | ||
@@ -16,3 +24,3 @@ | ||
pretty(STRING_OF_HTML_HERE); | ||
pretty(STRING_OF_HTML); | ||
``` | ||
@@ -28,3 +36,3 @@ | ||
After | ||
After | ||
@@ -44,26 +52,57 @@ ```html | ||
## Run tests | ||
## Options | ||
Install dev dependencies: | ||
### ocd | ||
```bash | ||
node i -d && mocha | ||
```js | ||
pretty(STRING_OF_HTML, {ocd: true}); | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/pretty/issues) | ||
**Type**: `Boolean` | ||
## Author | ||
**Default**: `undefined` | ||
* condenses multiple newlines to a single newline | ||
* trims leading and trailing whitespace | ||
* ensures that a trailing newline is inserted | ||
* normalizes whitespace before code comments | ||
## About | ||
### Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
### Building docs | ||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ | ||
To generate the readme, run the following command: | ||
```sh | ||
$ npm install -g verbose/verb#dev verb-generate-readme && verb | ||
``` | ||
### Running tests | ||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: | ||
```sh | ||
$ npm install && npm test | ||
``` | ||
### Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
### License | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
*** | ||
_This file was generated by [verb](https://github.com/assemble/verb) on January 04, 2015._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 13, 2017._ |
Sorry, the diff of this file is not supported yet
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
5780
105
3
4
38
1
+ Addedcondense-newlines@^0.2.1
+ Addedextend-shallow@^2.0.1
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@one-ini/wasm@0.1.1(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedabbrev@2.0.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcommander@10.0.1(transitive)
+ Addedcondense-newlines@0.2.1(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addededitorconfig@1.0.4(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedextend-shallow@2.0.1(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedis-whitespace@0.3.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedjs-beautify@1.15.1(transitive)
+ Addedjs-cookie@3.0.5(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.19.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addednopt@7.2.1(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
- Removedabbrev@1.1.1(transitive)
- Removedjs-beautify@1.5.10(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednopt@3.0.6(transitive)
Updatedjs-beautify@^1.6.12