A couple ways to think of this question. Decide for yourself which is most useful for you…
- Can javascript recreate the deprecated <xmp> tag with an "xmp" class?
- Can we mimic SO's markdown processor's escaping tags within inline code?
- (metaSO, I admit) How does SO's md processor escape tags in inline code?
- Can we escape < in markdown code blocks embedded in HTML?
The goal: a class that escapes <
, allowing that class to contain the text <html>, <body>, <head>, <script>, <style>, <body>, and any other tags that don't belong inside <body> or are processed specially, without processing them specially.
<xmp> achieved this (and actually continues to - deprecated but still browser-supported): <xmp><body></xmp>
was like <body>
. SO's markdown processor achieves this in inline code: to display <body>
just write `<body>` (which itself is \`<body>\` and cannot be included in an SO code block… I'm not the only one who could use this ;)
My solution so far ―replacing all <
with <
― takes care of the less-special HTML tags (is there a name for these within-<body> static content tags? <div>, <code>, <span>, etc), but the "special" tags still have to be started with < instead of <
Javascript: xmps = document.getElementsByClassName('xmp'); for (var i = 0; i < xmps.length; i++) { var xmp = xmp.item(i); var newhtml = xmp.innerHTML.replace(/\>/g,"\>").replace(/\</g,"\<"); xmp.innerHTML = newhtml; }
With that I can write <div class="xmp"><body></div>
.
What will allow
<div class="xmp"><body></div>
?
or how about?
<div class="xmp"> <body> &/div> </div>
The details of my project might matter: There'll be markdown in class="xmp"
so we need to be careful with line-initial >
s. There is no user input, so security isn't(?) an issue. I'm hoping for a solution that doesn't use jQuery.