123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 'use strict';
- 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) {
- var opts = extend({}, defaults, options);
- str = beautify.html(str, opts);
- if (opts.ocd === true) {
- if (opts.newlines) opts.sep = opts.newlines;
- return ocd(str, opts);
- }
- return str;
- };
- function ocd(str, options) {
-
- return condense(str, options)
-
- .replace(/^\s+/g, '')
-
- .replace(/\s+$/g, '\n')
-
- .replace(/(\s*<!--)/g, '\n$1')
-
- .replace(/>(\s*)(?=<!--\s*\/)/g, '> ');
- }
|