-
-
Save jeromeetienne/6257420 to your computer and use it in GitHub Desktop.
var multilineString = (function(){ /* | |
this | |
is | |
a | |
multiline | |
string. | |
*/}).toString().split('\n').slice(1, -1).join('\n'); | |
console.log(multilineString); |
hmm it has issue with javascript minifier unfortunatly... they will likely remove this comment to reduce the file size. mrdoob/three.js#3768 (comment)
i tried with @preserve. it is a jsdoc tag which preserve the comment. it is used to preserve comment which contains license text. nevertheless i tried and failed.
this significantly reduce the potential of the snippets :(
At least this was useful to me in some way :) I didn't know that using the method toString from a function will return its internal comments. Interesting...
Thanks a lot for this snippet. It allows me to deal with unknown multi lines texts.
It does not work if inside the comment has the <script></script> tag
For me it worked good. I want it to have PGN chess games into a javascript variable. For sure having html tags, javascript, or php inside the string will cause problems, at least that you add the logic to escape them. For everything rest, this is good. Thanks for sharing.
in three.js the following is usually used. and this is the one im trying to modify.
As the options you suggested, it add extra characters in the multiline string. It makes it harder to edit when you work on them. The first option i presented seem to fix this requirement.