Skip to content

Commit

Permalink
jsbeautifier.org html w/leading whitespace
Browse files Browse the repository at this point in the history
Input (. means leading space)
  ...<div>foo</div>

was:

  ...< div > foo < div >

is:

  <div>foo</div>
  • Loading branch information
einars committed Feb 22, 2012
1 parent 23fd0b7 commit a6dd2d5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.html
Expand Up @@ -300,7 +300,6 @@
var space_before_conditional = $('#space-before-conditional').attr('checked');


var comment_mark = '<-' + '-';
var opts = {
indent_size: indent_size,
indent_char: indent_char,
Expand All @@ -311,7 +310,7 @@
space_before_conditional: space_before_conditional,
indent_scripts:indent_scripts};

if (source && source[0] === '<' && source.substring(0, 4) !== comment_mark) {
if (looks_like_html(source)) {
$('#source').val(
style_html(source, opts)
);
Expand All @@ -326,6 +325,13 @@
the.beautify_in_progress = false;
}

function looks_like_html(source)
{
var trimmed = source.replace(/^[ \t\n\r]+/, '');
var comment_mark = '<-' + '-';
return (trimmed && (trimmed.substring(0, 1) === '<' || trimmed.substring(0, 4) === comment_mark));
}

$(function() {

if ($.browser.msie) {
Expand Down

0 comments on commit a6dd2d5

Please sign in to comment.