Giter Club home page Giter Club logo

commonjs-html-prettyprinter's Introduction

html prettyprinter

A node port of beautify-html.js by Nochum Sossonko which is based on jsbeautifier by Einar Lielmanis

Installation

from npm (node package manager)

  npm install html

Usage (command line)

  echo "<h2><strong><a href="http://awesome.com">AwesomeCom</a></strong><span>is awesome</span></h2>" | html

returns:

  <h2>
      <strong>
          <a href=http://awesome.com>AwesomeCom</a>
      </strong>
      <span>
          is awesome
      </span>
  </h2>

html foo.html will write the prettified version to stdout.

html *.html will update in place all matching html files with their prettified versions.

Advanced usage

I find myself constantly using the 'Copy as HTML' feature of the Chrome Inspector:

Copy as HTML

The downside is that that usually the HTML that gets copied is pretty ugly:

Before pretty printing

On OS X you can use pbpaste and pbcopy to stream your clipboard in and out of unix pipes. With the ugly HTML still in your clipboard run this command:

pbpaste | html | pbcopy

Now when you paste your clipboard into an editor you will get nice, pretty printed HTML:

After pretty printing

Upgrading

grab the newest beautify-html.js from js-beautifier and drop it into lib/ as html.js. then add the following code to the bottom of html.js:

  module.exports = { prettyPrint: style_html }

BSD LICENSE

commonjs-html-prettyprinter's People

Contributors

galenandrew avatar max-mapper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

commonjs-html-prettyprinter's Issues

Licencing status

Hi,
Could you please precise under which license the code is published ?
The Readme and package mention a "BSD" license (which is a little bit ambiguous, as there is several BSD licenses) while the LICENSE file contains an MIT license.
Thanks,
Camille

Do not break lines

This is actually ugly:

<line x1="945.3" y1="-2996.0816425120775" x2="945.3" y2="-3016.0816425120775"
/>

I do not want to format Zola tags

Input example part:

{%- if page %}
{%- set resource = page %}
{%- elif section %}
{%- set resource = section %}
{%- endif %}

<!DOCTYPE html>
<html lang='en'>

<head>
  <meta charset='utf-8'>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>

html format to:

{%- if page %} {%- set resource = page %} {%- elif section %} {%- set
resource = section %} {%- endif %}
<!DOCTYPE html>
<html lang='en'>
  
  <head>
    <meta charset='utf-8'>
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>

html.prettyPrint does not do any indenting or line-breaking (Node 6.1.0)

System specs:

  • Node: 6.1.0
  • OSX: 10.11.5

I haven't had any luck with this:

var html = require('html');
var txt = '<h2><strong><a href="http://awesome.com">AwesomeCom</a></strong><span>is awesome</span></h2>';
html.prettyPrint(txt, {indent_size: 2});
// result
'<h2><strong><a href="http://awesome.com">AwesomeCom</a></strong><span>is awesome</span></h2>'

So I tried the command-line example in the README but got the same, unformatted text.

Meaningful textarea whitespace removed

Hi!

First, thanks for the lib, it's super useful ๐Ÿ‘

I've spotted a bug with the handling of <textarea> content whitespace, where it's removed by prettyPrint:

require('html').prettyPrint('<textarea>     hello    </textarea>')

Results in:

<textarea>hello</textarea>

The whitespace inside a <textarea> is semantic and removing it changes the meaning of the <textarea>.

update single file in place

Obviously, npx html index.html > index.html will yield an empty file, so how do I tell html to update a file in place?

Add a license?

Hi, could you add a license? We'd love to use this, but can't without one.

Security vulnerability in minimatch (dependency of glob); remove glob as dependency

Issue

There is a security vulnerability in [email protected] which is a dependency of glob.

$ npm ls minimatch
[email protected]
โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”€ [email protected]

Deprecation warning:

npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

This has been updated in the latest version of glob (v7.0.5).

Resolution

Simply updating to the latest version of glob should resolve this issue.
Remove glob as dependency in package.json (glob is not used)

command not available on Mac

command installed, command not found.

squirple:~ dietrich$ node --version
v0.8.18
squirple:~ dietrich$ npm --version
1.3.1
squirple:~ dietrich$ npm list | grep html
โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
squirple:~ dietrich$ html
-bash: html: command not found

What is 'rigger' used for (it's a pretty big module)

Hi. After an npm install, this module takes 7424 kB on my machine. 91% of that size is the 'rigger' module, which I can't find any reference to, except in package.json.

Is there any reason why this module is needed?

If you use it in a build step or something, maybe it could be moved from "dependencies" to "devDependencies" in package.json?

Formatting of inline HTML elements eats whitespace!

When I print some HTML markup with option unformatted : [] (to force formatting of all elements), some whitespace which should be untouched is removed.

html.prettyPrint("<h1><strong>Lorem</strong> ipsum</h1>", {unformatted:[]})

The output is:

<h1>
    <strong>Lorem</strong>ipsum</h1>

Besides the weird formatting, the main problem is the removed space before word "ipsum". Such whitespace must not be ever removed!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.