"Format and indent" command introduces javascript errors
Posted: Tue Apr 08, 2008 2:04 pm
I'm having the difficulty that the "Format and indent" command sometimes alters javascript in a way that breaks the functionality of the code.
Suppose my document is something like this:
If I then use the "format and indent" command, the result is the following:
OK, the XHTML looks great now, but what about the javascript? Well, the deHashRegex regular expression has been corrupted. Because of the whitespace introduced between some its characters, it will no longer work in browsers. Essentially, oXygen's parser has confused a regular expression for a mathematical one, and has put spaces either side of the asterisk accordingly, and has placed a space after the closing parenthesis.
Does anyone have a solution to this, other than commenting out the javascript or putting it in a CDATA block (either of which would mean I wouldn't get syntax highlighting for the javascript any more)?
Many thanks,
Sam
Suppose my document is something like this:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Foo</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
</head>
<body>
<script type="text/javascript">
deHashRegex = /([\s\S]*?)#/g;
locNoHash = deHashRegex.exec(document.location);
</script>
<p>(Main body content.)</p>
</body>
</html>
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Foo</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
</head>
<body>
<script type="text/javascript">
deHashRegex = /([\s\S] * ?) #/g;
locNoHash = deHashRegex.exec(document.location);</script>
<p>(Main body content.)</p>
</body>
</html>
Does anyone have a solution to this, other than commenting out the javascript or putting it in a CDATA block (either of which would mean I wouldn't get syntax highlighting for the javascript any more)?
Many thanks,
Sam