<file_sep>(function () {
  'use strict';
  /* global window */
  var beautify = (typeof require === 'function' && require('js-beautify').html) ||
    (typeof window !== 'undefined' && window.html_beautify);
  if (typeof beautify !== 'function') {
    throw new Error('missing HTML beautify function');
  }

  if (typeof module === 'object') {
    // node
    module.exports = function () {
      setConsoleHtml();
    };
  }

  function setConsoleHtml() {
    if (typeof console === 'undefined') {
      throw new Error('Weird, console object is undefined');
    }
    if (typeof console.html === 'function') {
      return;
    }

    console.html = function () {
      var args = Array.prototype.slice.call(arguments);
      args.forEach(function (k) {
        if (typeof k === 'string') {
          return console.log(beautify(k));
        }
        if (typeof k === 'object' &&
          typeof k.html === 'function') {
          return console.log(beautify(k.html()));
        }
        if (typeof k.innerHTML === 'string') {
          return console.log(beautify(k.innerHTML));
        }
      });
    };
  }

  setConsoleHtml();
}());
<file_sep>require('..');

console.assert(typeof console.html === 'function',
  'installed a function');
console.html('<body><h1>hi</h1></body>');
var foo = {
  html: function () {
    return '<foo>bar</foo>';
  }
};
console.html('several arguments', '<h1>hi again</h1>', foo);
delete console.html;
<file_sep># console.html

> Adds console.html method for convenience

[![NPM][console.html-icon] ][console.html-url]

[![Build status][console.html-ci-image] ][console.html-ci-url]
[![dependencies][console.html-dependencies-image] ][console.html-dependencies-url]
[![devdependencies][console.html-devdependencies-image] ][console.html-devdependencies-url]

Install:

```
npm install console.html --save
bower install console.html --save
```

Use in Node:

```
// call once somewhere in the beginning
require('console.html');
console.html('<body><h1>Hello, world!</h1></body>');
// prints
<body>
  <h1>Hello, world!</h1>
</body>
console.html($('#selector'));
// prints nicely formatted HTML from jQuery / D3 selectors
// that have .html() method
console.html($('#one'), $(#two));
// outputs formatted HTML for each selector,
// second selector starts on new line
```

Use in browser:

```html
<script src="bower_components/console.html/dist/console.html.js"></script>
<script>
console.html($('#divId'));
console.html(document.getElementById('divId'));
</script>
```

### Small print

Author: <NAME> &copy; 2014

* [@bahmutov](https://twitter.com/bahmutov)
* [glebbahmutov.com](http://glebbahmutov.com)
* [blog](http://bahmutov.calepin.co/)

License: MIT - do anything with the code, but don't blame me if it does not work.

Spread the word: tweet, star on github, etc.

Support: if you find any problems with this module, email / tweet /
[open issue](https://github.com/bahmutov/console.html/issues) on Github

## MIT License

Copyright (c) 2014 <NAME>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

[console.html-icon]: https://nodei.co/npm/console.html.png?downloads=true
[console.html-url]: https://npmjs.org/package/console.html
[console.html-ci-image]: https://travis-ci.org/bahmutov/console.html.png?branch=master
[console.html-ci-url]: https://travis-ci.org/bahmutov/console.html
[console.html-dependencies-image]: https://david-dm.org/bahmutov/console.html.png
[console.html-dependencies-url]: https://david-dm.org/bahmutov/console.html
[console.html-devdependencies-image]: https://david-dm.org/bahmutov/console.html/dev-status.png
[console.html-devdependencies-url]: https://david-dm.org/bahmutov/console.html#info=devDependencies
<file_sep>var expect = require('expect.js');
var sinon = require('sinon');

describe('console.html', function () {
  beforeEach(function () {
    // make sure the module is loaded without caching
    delete require.cache[require.resolve('../index')];
  });

  afterEach(function () {
    delete console.html;
  });

  it('fills missing method', function () {
    expect(console.html).to.be(undefined);
  });

  it('installs html method', function () {
    require('../index');
    expect(typeof console.html).to.be('function');
  });

  it('calls console.log ultimately', function () {
    require('../index');
    sinon.spy(console, 'log');
    var str = '<h1>hi</h1>';
    console.html(str);
    expect(console.log.callCount).to.be(1);
    expect(console.log.calledWith(str)).to.be(true);
    console.log.restore();
  });

  it('calls console.log with value of html()', function () {
    require('../index');
    sinon.spy(console, 'log');
    console.html({
      html: function () {
        return 'foo';
      }
    });
    expect(console.log.calledWith('foo')).to.be(true);
    console.log.restore();
  });

  it('calls console.log with value of innerHTML', function () {
    require('../index');
    sinon.spy(console, 'log');
    console.html({
      innerHTML: 'foo'
    });
    expect(console.log.calledWith('foo')).to.be(true);
    console.log.restore();
  });

  it('logs nothing if no html found', function () {
    require('../index');
    sinon.spy(console, 'log');
    console.html({
      other: 'foo'
    });
    expect(console.log.calledWith('foo')).to.be(false);
    expect(console.log.called).to.be(false);
    console.log.restore();
  });
});
