Created
May 24, 2014 15:53
-
-
Save soldair/06e8612b36f9c77afbe5 to your computer and use it in GitHub Desktop.
multiline strings with includes via function block comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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