Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm getting some html from node-request and I want to place that html into my javascript code as strings:

<div id='frontpage'><div set-href="'/user/' + (user | encodeURIComponent)">userlink</div></div>

The goal is to get an output like this for angularjs:

var createCache = function (path, template) {
  return "\n  $templateCache.put('" + path + "',\n    '" +template + "'\n  );\n";
}

This code is too naive, there are issues with quotes and other potential problems. How could it be done correctly? Is there a way to get the string from node-request itself? Thanks.

share|improve this question
1  
As for issues with quotes, have you tried using the escape() method? –  Nick Dugger May 8 at 14:29
    
@NickDugger that's not what I want. I need escaping like this: \' not %27 –  Harry May 8 at 14:31
    
Well, you could do some simple .replace(/"/g, "\"") or some regex, which I never wrapped my head around, myself. –  Nick Dugger May 8 at 14:32
    
@NickDugger thanks man, but i'd rather not. regexes on html is rarely a great idea –  Harry May 8 at 14:34
    
Understandable. –  Nick Dugger May 8 at 14:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.