Skip to content

Commit

Permalink
formatting by xmlns attribute is added
Browse files Browse the repository at this point in the history
  • Loading branch information
vkiryukhin committed Jun 13, 2012
1 parent 261dd07 commit 0cdb899
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
12 changes: 10 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" itemscope itemtype="http://schema.org/Article">
<head>
<meta itemprop="name" content="vkBeautify">
<meta itemprop="description" content="Beautify or Minify XML JSON CSS SQL text">

<script src="jquery.1.5.0.js" type="text/javascript"></script>
<script src="vkbeautify.js"></script>
Expand All @@ -12,7 +15,11 @@
<title>vkBeautify - javascript plugin</title>

<script type="text/javascript">

(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
</head>
<body>
Expand All @@ -28,6 +35,7 @@ <h1>vkBeautify </h1>
&nbsp;|&nbsp;<li ><a href="https://github.com/vkiryukhin/vkBeautify" title="Source on GitHub" target="_blank">GitHub</a></li>&nbsp;|&nbsp;

</ul>
<div style="inline-block;position:relative;top:-41px" ><g:plusone size="small" annotation="none"></g:plusone></div>
</div> <!-- /header -->
<!-- ================= container ======================= -->

Expand Down
5 changes: 1 addition & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ function loadTemplate(name)
case 'basic':
$('#ta').width(400);
$('#leftpanel').show();
document.getElementById('ta').value = '<?xml version="1.0" encoding="UTF-8" ?>'
+ '<!DOCTYPE foo SYSTEM "Foo.dtd"><a><b>bbb</b><c/>'
+ '<d><!-- comment --></d><e><![CDATA[ <z></z> ]]>'
+ '</e><f><g> </g></f></a>';
document.getElementById('ta').value = '<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE foo SYSTEM "Foo.dtd"><a><b>bbb</b><c/><d><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></soapenv></d><e><![CDATA[ <z></z> ]]></e><f><g></g></f></a>';
$('#rightpanel').empty().load('html/basic.html');
$('#mode').html('XML');
countChars();
Expand Down
13 changes: 11 additions & 2 deletions vkbeautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ function vkbeautify(){

vkbeautify.prototype.xml = function(text,step) {

var ar = text.replace(/>\s{0,}</g,"><").replace(/</g,"~::~<").split('~::~'),
var ar = text.replace(/>\s{0,}</g,"><")
.replace(/</g,"~::~<")
.replace(/xmlns/g,"~::~xmlns:")
.split('~::~'),
len = ar.length,
inComment = false,
deep = 0,
Expand Down Expand Up @@ -132,7 +135,13 @@ vkbeautify.prototype.xml = function(text,step) {
// <? xml ... ?> //
if(ar[ix].search(/<\?/) > -1) {
str += shift[deep]+ar[ix];
} else {
} else
// xmlns: //
if(ar[ix].search(/xmlns/) > -1) {
str += shift[deep]+ar[ix];
}

else {
str += ar[ix];
}
}
Expand Down

0 comments on commit 0cdb899

Please sign in to comment.