Skip to content

Instantly share code, notes, and snippets.

@soldair
Created May 24, 2014 15:53
Show Gist options
  • Save soldair/06e8612b36f9c77afbe5 to your computer and use it in GitHub Desktop.
Save soldair/06e8612b36f9c77afbe5 to your computer and use it in GitHub Desktop.
multiline strings with includes via function block comments
var foot = function(){
/*
<div>footer</div>
*/
}
var index = function fn(){
/*
<!DOCTYPE html>
<html>
<head></head>
<body>
*/foot+''/*
</body>
</html>
*/
}
function t(s){
s = s+'';
var d = '/*',i,code
var out = "",offset = 0;
while((i = s.indexOf(d)) > -1){
if(d == '*/') {
out += s.substr(0,i);
s = s.substr(i);
d = '/*'
} else {
code = s.substr(offset,i-offset);
s = s.substr(i+2);
if(code.length && offset > 0){
s = t(eval(code))+s;
}
d = '*/';
offset = 2;
}
}
return out;
}
console.log(t(index));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment