In HTML, tags and entities aren't parsed within <script>
tags, and </
immediately ends the tag. Thus,
<script><b>fun & things</
will give you a script tag with the exact contents <b>fun & things
.
If you're including JSON and you want to include the characters </
in your script, then you can replace it with <\/
because the only place for those characters to appear is in a string, and \/
is an escape sequence that turns into a single forward slash.
However, if you're not using JavaScript, then this trick doesn't work. In my case specifically I'm trying to insert a <script type="math/tex">
into the source so that MathJax will process it. Is there a way to escape </
in the original HTML source? (I don't have a particular need for </
but I'm writing a generic tool and want to make it possible to use any text.)
(It's possible to create the script tag in JavaScript and populate its innerText
, but I'm working with the raw HTML so I can't do that.)