From a6dd2d51a2bdd10bbcd42ef368d5ab3367a66e64 Mon Sep 17 00:00:00 2001 From: Einar Lielmanis Date: Thu, 23 Feb 2012 01:24:05 +0200 Subject: [PATCH] jsbeautifier.org html w/leading whitespace Input (. means leading space) ...
foo
was: ...< div > foo < div > is:
foo
--- index.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index c66a6325f..6a99b8f9b 100644 --- a/index.html +++ b/index.html @@ -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, @@ -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) ); @@ -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) {