Hello,
I am trying to design and develop a custom HTML to JavaScript converter so as to save time and increase effiency as opposed to having to write out every single line of html.
I refer to this website:
http://www.neuetech.com/tools.php?function=8
I am trying to do something similar, but since i'd like more control of writting it dynamically because I will insert if statements later but, how can the code be modified such that the output would be as follows
Desired result:
Code:
var html = ''
html += '<html>\n'
html += '<head>\n'
ect.
and not:
Code:
var html = '<html>\n' +
'<html>\n' +
'<head>\n' +
Here is my current code which does not work to begin with, I can't seem to figure it out, by my eye all should be fine and dandy.
Code:
<html>
<head>
<script type="text/javascript">
function test() {
var oldtext = document.getElementById('oldtext').value
oldtext = RegExReplace(oldtext, '\'', '\\\'');
oldtext = RegExReplace(oldtext, '^\\s+', '');
oldtext = RegExReplace(oldtext, '\n\\s+', '\n');
oldtext = RegExReplace(oldtext, '\r', '');
oldtext = RegExReplace(oldtext, '\n', '\\n\' +\n \'');
oldtext = RegExReplace(oldtext, '</', '<\\/');
oldtext = 'html = \'' + oldtext + '\';';
alert(oldtext);
}
</script>
</head>
<body>
<textarea id="oldtext"></textarea>
<br><br>
<textarea id="newtext"></textarea>
<br><br>
<input type="submit" value="Convert" onclick="test()">
</body>
</html>