How to use the js-beautify.html_beautify function in js-beautify

To help you get started, we’ve selected a few js-beautify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github styledown / styledown / index.js View on Github external
prettyprint: function (html, options) {
    var beautify = require('js-beautify').html_beautify;

    var opts = {
      indent_size: this.options.indentSize,
      wrap_line_length: 120,
      unformatted: ['pre']
    };

    // js-beautify sometimes trips when the first character isn't a <. not
    // sure... but might as well do this.
    html = html.trim();

    var output = beautify(html, extend(opts, options));

    // cheerio output tends to have a bunch of extra newlines. kill them.
    output = output.replace(/\n\n+/g, "\n\n");

    return output;
  },
github nkashyap / console.io / server / utils.js View on Github external
"preserve_newlines": true,
                    "max_preserve_newlines": 5,
                    "jslint_happy": false,
                    "brace_style": "collapse",
                    "keep_array_indentation": false,
                    "keep_function_indentation": false,
                    "space_before_conditional": true,
                    "break_chained_methods": false,
                    "eval_code": false,
                    "unescape_strings": false,
                    "wrap_line_length": 0
                });

                break;
            default:
                content = beautify.html_beautify(content, {
                    "indent_inner_html": true,
                    "indent_size": 4,
                    "indent_char": " ",
                    "brace_style": "collapse",
                    "indent_scripts": "normal",
                    "wrap_line_length": 0,
                    "preserve_newlines": true,
                    "max_preserve_newlines": 10
                });
                break;
        }

        console.log('Content beautify as ' + type);
        return content;
    },
github codice / ddf / ui / packages / catalog-ui-search / src / main / webapp / dev / component / base-guide / base-guide.view.js View on Github external
let instanceHTML
      switch (dataHTML) {
        case 'outer':
          instanceHTML = element.parentNode.querySelector('.instance').outerHTML
          break
        case '':
          instanceHTML = element.parentNode.querySelector('.instance').innerHTML
          break
        default:
          instanceHTML = this.templates[dataHTML]()
          break
      }
      renderAce({
        where: element,
        mode: 'html',
        value: beautify.html_beautify(instanceHTML, {
          unformatted: [''],
        }),
        view: this,
      })
    })
    this.$el.find('.editor[data-css]').each((index, element) => {
github Draccoz / twc / src / PolymerModule.ts View on Github external
}

    let { dir } = parse(this.path);
    let styles = meta.get("styles");
    let tpl = (({ template, type } = {}) => {
      switch (type) {
        case "link":
          return readFileSync(join(dir, template)).toString();
        case "inline":
          return template;
        default:
          return "";
      }
    })(meta.get("template"));

    return beautify([
      ...this.links.map(module => ``),
      ...this.scripts.map(module => ``),

      nonEmpty``,
      `${[
        nonEmpty`\n<template>${[
          ...styles.map(({ style, type }) =&gt; {
            switch (type) {
              case "link":
                return `${readFileSync(join(dir, style))}`;
              case "inline":
                if (!this.isES6) {
                  style = style.replace(/\\n/g, "\n").replace(/\\"/g, '"');
                }
                return `${style}`;
              case "shared":</template>
github appnexus / cmp / src / docs / components / docs / setup.jsx View on Github external
super(props);

		const config = {
			globalConsentLocation: `//${CURRENT_LOCATION}portal.html`,
			storeConsentGlobally: true,
			storePublisherData: false
		};

		const bookmarkScript = `javascript:(function(){
			${buildScript(config, `//${CURRENT_LOCATION}../cmp.bundle.js`)}
			window.__cmp('showConsentTool');
		}());`.replace(/}\n/g, '};');

		this.setState({
			bookmarklet: bookmarkScript,
			tag: beautify(``),
		});
	}
github jdf2e / jdf / lib / fileFormat.js View on Github external
function htmlFormat(filename){
	var content = f.read(filename);

	f.write(filename, beautify.html_beautify(content));
	logger.info('jdf format ['+filename+'] success');
}
github AshKyd / alchemize / src / scripts / worker.js View on Github external
prettify: function(opts, cb) {
      opts.indent_size = opts.indent_size || 4;
      opts.indent_char = opts.indent_char || " ";
      opts.wrap_line_length = opts.wrap_line_length || 0;
      opts.preserve_newlines = opts.preserve_newlines || false;

      var pretty = beautify.html_beautify(opts.input, opts);
      cb({
        output: pretty
      });
    }
  },