Comparing version 0.1.2 to 1.0.0
50
index.js
@@ -1,9 +0,49 @@ | ||
/* | ||
* pretty | ||
* https://github.com/jonschlinkert/pretty | ||
/*! | ||
* pretty <https://github.com/jonschlinkert/pretty> | ||
* | ||
* Copyright (c) 2013 Jon Schlinkert | ||
* Copyright (c) 2013-2015, Jon Schlinkert. | ||
* Licensed under the MIT license. | ||
*/ | ||
module.exports = require('./lib/pretty.js'); | ||
'use strict'; | ||
var beautify = require('js-beautify'); | ||
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'] | ||
}); | ||
return ocd(str, options); | ||
}; | ||
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') | ||
// 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 '); | ||
} |
{ | ||
"name": "pretty", | ||
"description": "Some tweaks for beautifying HTML with js-beautify according to my preferences.", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/jonschlinkert/pretty", | ||
@@ -17,23 +17,31 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/pretty/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/pretty/blob/master/LICENSE-MIT" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"main": "index.js", | ||
"scripts": { | ||
"docs": "update && license && npmignore && deps && verb", | ||
"all": "npm run docs" | ||
}, | ||
"dependencies": { | ||
"js-beautify": "~1.5.4" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
}, | ||
"keywords": [ | ||
"grunt task", | ||
"build", | ||
"handlebars helper", | ||
"underscore mixin", | ||
"site generator", | ||
"component generator", | ||
"blog generator", | ||
"handlebars", | ||
"templates" | ||
], | ||
"dependencies": { | ||
"js-beautify": "~1.4.1" | ||
} | ||
"beautify", | ||
"format", | ||
"formatter", | ||
"html", | ||
"js", | ||
"js-beautify", | ||
"prettify", | ||
"pretty" | ||
] | ||
} |
@@ -1,24 +0,66 @@ | ||
# pretty [![NPM version](https://badge.fury.io/js/pretty.png)](http://badge.fury.io/js/pretty) | ||
# pretty [![NPM version](https://badge.fury.io/js/pretty.svg)](http://badge.fury.io/js/pretty) | ||
> Sensible presets and some tweaks for beautifying HTML with js-beautify according to my preferences. | ||
> Some tweaks for beautifying HTML with js-beautify according to my preferences. | ||
## Getting Started | ||
Install the module with: `npm install pretty` | ||
## Install with [npm](npmjs.org) | ||
```javascript | ||
```bash | ||
npm i pretty --save | ||
``` | ||
## Usage | ||
```js | ||
var pretty = require('pretty'); | ||
pretty('file.html'); | ||
pretty(STRING_OF_HTML_HERE); | ||
``` | ||
Before | ||
```html | ||
<!DOCTYPE html> <html lang="en"> <head> | ||
<meta charset="UTF-8"> <title>Home</title> | ||
</head> <body> This is content. </body> </html> | ||
``` | ||
After | ||
```html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Home</title> | ||
</head> | ||
<body> | ||
This is content. | ||
</body> | ||
</html> | ||
``` | ||
## Run tests | ||
Install dev dependencies: | ||
```bash | ||
node i -d && mocha | ||
``` | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/pretty/issues) | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2013 Jon Schlinkert | ||
Licensed under the MIT license. | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
*** | ||
_This file was generated on Thu Oct 24 2013 03:05:26._ | ||
_This file was generated by [verb](https://github.com/assemble/verb) on January 04, 2015._ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
67
5183
2
5
44
+ Addedjs-beautify@1.5.10(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addednopt@3.0.6(transitive)
- Removedjs-beautify@1.4.2(transitive)
- Removedmkdirp@0.3.5(transitive)
- Removednopt@2.1.2(transitive)
Updatedjs-beautify@~1.5.4