kakulukia/pypugjs

Inline Javascript problem

BarnabasSzabolcs opened this issue · 4 comments

  • pypugjs version: 5.7.2
  • Django version: 2.1.4
  • Python version: 3.6
  • Operating System: OSX

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

The "script." tag only works fine until it meets "</script>" because it interprets it as a closing tag,
instead of interpreting it as a string.
(This thing may look silly - my intention was to load fb async as to decrease google page load time adn js.async didn't work so I tried placing the whole script to be loaded after pageload.)

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

script.
document.addEventListener('load', function(){
"<script>" +
"(function(d, s, id) {" +
"var js, fjs = d.getElementsByTagName(s)[0];" +
"if (d.getElementById(id)) return;" +
"js = d.createElement(s); js.id = id; js.async = true;" +
"fjs.parentNode.insertBefore(js, fjs);" +
"}(document, 'script', 'facebook-jssdk'));" +
"</script>"});
resulted in

<script>document.addEventListener('load', function(){ "<script>" + "(function(d, s, id) {" + "var js, fjs = d.getElementsByTagName(s)[0];" + "if (d.getElementById(id)) return;" + "fjs.parentNode.insertBefore(js, fjs);" + "}(document, 'script', 'facebook-jssdk'));" + "</script>

});

Why are you using that script tag in the first place rather than continuing with javascript?

Can you clarify that? Otherwise im closing the ticket ..

I'm not using the script tag. I use a JS string that happens to contain "<script>" as a substring. I believe any JS string such as var s="blah<script>blahblah"; will break.

nevermind, I've found the solution. The issue is not with pug.
Here is an explanation:
https://stackoverflow.com/questions/33969544/can-i-write-a-script-tag-inside-a-script-tag
If I'm here already, a better solution is escaping the slash: var s = "<\/script>".

Sorry for bothering. Keep up the great work! It is a lot nicer to be able to write jade/pug files instead of html files.