GithubHelp home page GithubHelp logo

isabella232 / diffable-html Goto Github PK

View Code? Open in Web Editor NEW

This project forked from algolia/diffable-html

0.0 0.0 0.0 323 KB

Opinionated HTML formatter focused towards making HTML diffs readable.

JavaScript 84.13% Shell 15.87%

diffable-html's Introduction

Opinionated HTML formatter focused towards making HTML diffs readable.

NPM version Build Status

This formatter will normalize your HTML in a way that when you diff it, you get a clear sense of what changed.

This is a "zero-config" and opinionated HTML formatter. Default rules might change in future releases in which case we will push a major release.

Feel free to open issues to discuss better defaults.

Formatting consists of:

  • indenting every level with 2 spaces
  • align attributes
  • put every opening and closing tag on its own line
  • trimming text nodes

Be aware that this plugin is intended for making HTML diffs more readable. We took the compromise of not dealing with white-spaces like the browsers do.

Install

Add the package as a dev-dependency:

# With npm
npm install --save-dev diffable-html

# With yarn
yarn add --dev diffable-html

Example

import toDiffableHtml from 'diffable-html';

const html = `
<div id="header">
  <h1>Hello World!</h1>
  <ul id="main-list" class="list"><li><a href="#">My HTML</a></li></ul>
</div>
`

console.log(toDiffableHtml(html));

Will output:

<div id="header">
  <h1>
    Hello World!
  </h1>
  <ul
    id="main-list"
    class="list"
  >
    <li>
      <a href="#">
        My HTML
      </a>
    </li>
  </ul>
</div>

Yet another HTML formatting plugin?

This formatter was initially developed to address the lack of some features in js-beautifier:

These features are needed to improve readability of HTML diffs.

Usage with Jest

Development of this plugin was motivated by making testing of Vue.js components easier by the use of Jest with snapshot tests.

You can find a serializer for formatting your HTML here Jest serializer.

diffable-html's People

Contributors

rayrutjes avatar dependabot[bot] avatar haroenv avatar bjankord avatar edemaine avatar eunjae-lee avatar

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.