Sunday, March 6, 2011

How to escape everything in a block in HTML

I seem to recall that there is an HTML tag that escapes absolutely everything inside it except the matching closing tag. Kind of like <plaintext> but not fundamentally broken.

From stackoverflow
  • <xmp> is the tag you are looking for:

    <xmp>some stuff <tags></tags> too</xmp>
    

    But, since it's depricated, the best you can get is <pre>.

    Software Monkey : Sweet! I've been wanting a tag like this!
    Ken Paul : is deprecated -- it should not be used. See http://www.htmlcodetutorial.com/_XMP.html. </div> </div> </li> <li class="p_ans_l"> <p>There is also the XML <a href="http://www.w3schools.com/XML/xml_cdata.asp" rel="nofollow">CDATA</a>:</p> <pre><code>&lt;![CDATA[stuff that is &lt;tag&gt;never&lt;/tag&gt; parsed]]&gt; </code></pre> <p>Whether this works in an HTML document is probably up to the browser. However, it should certainly work in an XHTML document.</p> <div class="p_comment"> <div class="p_a_com"> <span>nickf :</span> i just tried it in Firefox 3 and it didn't work. </div> </div> </li> <li class="p_ans_l"> <p>You need to use <code>&lt;pre&gt;&lt;code&gt; ... &lt;/code&gt;&lt;/pre&gt;</code>. </p> <p><code>&lt;xmp&gt;</code> is deprecated and should not be used. See <a href="http://www.htmlcodetutorial.com/_XMP.html" rel="nofollow">http://www.htmlcodetutorial.com/_XMP.html</a>.</p> <div class="p_comment"> <div class="p_a_com"> <span>Mohit Nanda :</span> Neither does <pre>, nor does <code> escapes '<' or '>' :( </div> <div class="p_a_com"> <span>BCS :</span> Ditto Mohit. just tested that with a html document in side <pre><code>, FF2 gave a blank screen </div> <div class="p_a_com"> <span>BCS :</span> http://www.htmlref.com/Reference/AppA/tag_xmp.htm seems that it works most places (and what better can you get with HTML anyway?) </div> </div> </li> </ul> </div> </div> <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'><span class='post-author vcard'> Posted by <span class='fn'>Mu Cat</span> </span> <span class='post-timestamp'> at <a class='timestamp-link' href='https://codeanswer30.blogspot.com/2011/03/how-to-escape-everything-in-block-in.html' rel='bookmark' title='permanent link'><abbr class='published' title='2011-03-06T07:29:00-08:00'>7:29&#8239;AM</abbr></a> </span> <span class='post-comment-link'> </span> <span class='post-icons'> <span class='item-control blog-admin pid-2040597186'> <a href='https://www.blogger.com/post-edit.g?blogID=5200563570836889084&postID=6326721431050764488&from=pencil' title='Edit Post'> <img alt="" class="icon-action" height="18" src="//www.blogger.com/img/icon18_edit_allbkg.gif" width="18"> </a> </span> </span> </div> <div class='post-footer-line post-footer-line-2'><span class='post-labels'> </span> </div> <div class='post-footer-line post-footer-line-3'></div> </div> </div> <div class='comments' id='comments'> <a name='comments'></a> <h4> 0 comments: </h4> <dl class='avatar-comment-indent' id='comments-block'> </dl> <p class='comment-footer'> <div class='comment-form'> <a name='comment-form'></a> <h4 id='comment-post-message'>Post a Comment</h4> <p> </p> <a href='https://www.blogger.com/comment/frame/5200563570836889084?po=6326721431050764488&hl=en' id='comment-editor-src'></a> <iframe allowtransparency='true' class='blogger-iframe-colorize blogger-comment-from-post' frameborder='0' height='410' id='comment-editor' name='comment-editor' src='' width='100%'></iframe> <!--Can't find substitution for tag [post.friendConnectJs]--> <script src='https://www.blogger.com/static/v1/jsbin/2315299244-comment_from_post_iframe.js' type='text/javascript'></script> <script type='text/javascript'> BLOG_CMT_createIframe('https://www.blogger.com/rpc_relay.html', '0'); </script> </div> </p> <div id='backlinks-container'> <div id='Blog1_backlinks-container'> </div> </div> </div> <!--Can't find substitution for tag [adEnd]--> </div> <div class='blog-pager' id='blog-pager'> <span id='blog-pager-newer-link'> <a class='blog-pager-newer-link' href='https://codeanswer30.blogspot.com/2011/03/get-generic-method-without-using.html' id='Blog1_blog-pager-newer-link' title='Newer Post'>Newer Post</a> </span> <span id='blog-pager-older-link'> <a class='blog-pager-older-link' href='https://codeanswer30.blogspot.com/2011/03/why-aren-java-generic-type-parameters.html' id='Blog1_blog-pager-older-link' title='Older Post'>Older Post</a> </span> <a class='home-link' href='https://codeanswer30.blogspot.com/'>Home</a> </div> <div class='clear'></div> <div class='post-feeds'> <div class='feed-links'> Subscribe to: <a class='feed-link' href='https://codeanswer30.blogspot.com/feeds/6326721431050764488/comments/default' target='_blank' type='application/atom+xml'>Post Comments (Atom)</a> </div> </div> </div></div> </div> <div id='sidebar1-wrapper'> <div class='sidebar no-items section' id='sidebar1'> </div> </div> </div> <div id='sidebar2-wrapper'> <div class='sidebar section' id='sidebar2'> <div class='widget BlogArchive' data-version='1' id='BlogArchive1'> <h2>Blog Archive</h2> <div class='widget-content'> <div id='ArchiveList'> <div id='BlogArchive1_ArchiveList'> <ul> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_05_06_archive.html'>May 06</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_05_05_archive.html'>May 05</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_05_03_archive.html'>May 03</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_05_01_archive.html'>May 01</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_29_archive.html'>Apr 29</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_28_archive.html'>Apr 28</a> (30) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_25_archive.html'>Apr 25</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_21_archive.html'>Apr 21</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_20_archive.html'>Apr 20</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_17_archive.html'>Apr 17</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_15_archive.html'>Apr 15</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_14_archive.html'>Apr 14</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_13_archive.html'>Apr 13</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_11_archive.html'>Apr 11</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_08_archive.html'>Apr 08</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_06_archive.html'>Apr 06</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_05_archive.html'>Apr 05</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_04_03_archive.html'>Apr 03</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_31_archive.html'>Mar 31</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_28_archive.html'>Mar 28</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_27_archive.html'>Mar 27</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_24_archive.html'>Mar 24</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_23_archive.html'>Mar 23</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_20_archive.html'>Mar 20</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_16_archive.html'>Mar 16</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_15_archive.html'>Mar 15</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_07_archive.html'>Mar 07</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_06_archive.html'>Mar 06</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_04_archive.html'>Mar 04</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_03_archive.html'>Mar 03</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_03_01_archive.html'>Mar 01</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_21_archive.html'>Feb 21</a> (32) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_19_archive.html'>Feb 19</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_17_archive.html'>Feb 17</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_13_archive.html'>Feb 13</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_12_archive.html'>Feb 12</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_11_archive.html'>Feb 11</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_10_archive.html'>Feb 10</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_09_archive.html'>Feb 09</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_08_archive.html'>Feb 08</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_07_archive.html'>Feb 07</a> (23) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_05_archive.html'>Feb 05</a> (41) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_04_archive.html'>Feb 04</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_02_03_archive.html'>Feb 03</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_29_archive.html'>Jan 29</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_28_archive.html'>Jan 28</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_27_archive.html'>Jan 27</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_26_archive.html'>Jan 26</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_25_archive.html'>Jan 25</a> (32) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_24_archive.html'>Jan 24</a> (18) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_23_archive.html'>Jan 23</a> (48) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_21_archive.html'>Jan 21</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_20_archive.html'>Jan 20</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_19_archive.html'>Jan 19</a> (32) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_18_archive.html'>Jan 18</a> (31) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_16_archive.html'>Jan 16</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_14_archive.html'>Jan 14</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_12_archive.html'>Jan 12</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_11_archive.html'>Jan 11</a> (50) </li> <li class='archivedate'> <a href='https://codeanswer30.blogspot.com/2011_01_10_archive.html'>Jan 10</a> (50) </li> </ul> </div> </div> <div class='clear'></div> </div> </div></div> </div> <!-- spacer for skins that want sidebar and main to be the same height--> <div class='clear'>&#160;</div> </div> <!-- end content-wrapper --> </div></div> <!-- end outer-wrapper --> <script type="text/javascript" src="https://www.blogger.com/static/v1/widgets/2591855913-widgets.js"></script> <script type='text/javascript'> window['__wavt'] = 'AOuZoY6degLzPh2uCv9uUk6qe0pibcWudA:1731080729232';_WidgetManager._Init('//www.blogger.com/rearrange?blogID\x3d5200563570836889084','//codeanswer30.blogspot.com/2011/03/how-to-escape-everything-in-block-in.html','5200563570836889084'); _WidgetManager._SetDataContext([{'name': 'blog', 'data': {'blogId': '5200563570836889084', 'title': 'Code Answer', 'url': 'https://codeanswer30.blogspot.com/2011/03/how-to-escape-everything-in-block-in.html', 'canonicalUrl': 'http://codeanswer30.blogspot.com/2011/03/how-to-escape-everything-in-block-in.html', 'homepageUrl': 'https://codeanswer30.blogspot.com/', 'searchUrl': 'https://codeanswer30.blogspot.com/search', 'canonicalHomepageUrl': 'http://codeanswer30.blogspot.com/', 'blogspotFaviconUrl': 'https://codeanswer30.blogspot.com/favicon.ico', 'bloggerUrl': 'https://www.blogger.com', 'hasCustomDomain': false, 'httpsEnabled': true, 'enabledCommentProfileImages': true, 'gPlusViewType': 'FILTERED_POSTMOD', 'adultContent': false, 'analyticsAccountNumber': '', 'encoding': 'UTF-8', 'locale': 'en', 'localeUnderscoreDelimited': 'en', 'languageDirection': 'ltr', 'isPrivate': false, 'isMobile': false, 'isMobileRequest': false, 'mobileClass': '', 'isPrivateBlog': false, 'isDynamicViewsAvailable': true, 'feedLinks': '\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22Code Answer - Atom\x22 href\x3d\x22https://codeanswer30.blogspot.com/feeds/posts/default\x22 /\x3e\n\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/rss+xml\x22 title\x3d\x22Code Answer - RSS\x22 href\x3d\x22https://codeanswer30.blogspot.com/feeds/posts/default?alt\x3drss\x22 /\x3e\n\x3clink rel\x3d\x22service.post\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22Code Answer - Atom\x22 href\x3d\x22https://www.blogger.com/feeds/5200563570836889084/posts/default\x22 /\x3e\n\n\x3clink rel\x3d\x22alternate\x22 type\x3d\x22application/atom+xml\x22 title\x3d\x22Code Answer - Atom\x22 href\x3d\x22https://codeanswer30.blogspot.com/feeds/6326721431050764488/comments/default\x22 /\x3e\n', 'meTag': '', 'adsenseClientId': 'ca-pub-6870522351295034', 'adsenseHostId': 'ca-host-pub-1556223355139109', 'adsenseHasAds': true, 'adsenseAutoAds': false, 'boqCommentIframeForm': true, 'loginRedirectParam': '', 'view': '', 'dynamicViewsCommentsSrc': '//www.blogblog.com/dynamicviews/4224c15c4e7c9321/js/comments.js', 'dynamicViewsScriptSrc': '//www.blogblog.com/dynamicviews/6eb7ce967db05cf0', 'plusOneApiSrc': 'https://apis.google.com/js/platform.js', 'disableGComments': true, 'interstitialAccepted': false, 'sharing': {'platforms': [{'name': 'Get link', 'key': 'link', 'shareMessage': 'Get link', 'target': ''}, {'name': 'Facebook', 'key': 'facebook', 'shareMessage': 'Share to Facebook', 'target': 'facebook'}, {'name': 'BlogThis!', 'key': 'blogThis', 'shareMessage': 'BlogThis!', 'target': 'blog'}, {'name': 'Twitter', 'key': 'twitter', 'shareMessage': 'Share to Twitter', 'target': 'twitter'}, {'name': 'Pinterest', 'key': 'pinterest', 'shareMessage': 'Share to Pinterest', 'target': 'pinterest'}, {'name': 'Email', 'key': 'email', 'shareMessage': 'Email', 'target': 'email'}], 'disableGooglePlus': true, 'googlePlusShareButtonWidth': 0, 'googlePlusBootstrap': '\x3cscript type\x3d\x22text/javascript\x22\x3ewindow.___gcfg \x3d {\x27lang\x27: \x27en\x27};\x3c/script\x3e'}, 'hasCustomJumpLinkMessage': false, 'jumpLinkMessage': 'Read more', 'pageType': 'item', 'postId': '6326721431050764488', 'pageName': 'How to escape everything in a block in HTML', 'pageTitle': 'Code Answer: How to escape everything in a block in HTML'}}, {'name': 'features', 'data': {}}, {'name': 'messages', 'data': {'edit': 'Edit', 'linkCopiedToClipboard': 'Link copied to clipboard!', 'ok': 'Ok', 'postLink': 'Post Link'}}, {'name': 'template', 'data': {'name': 'custom', 'localizedName': 'Custom', 'isResponsive': false, 'isAlternateRendering': false, 'isCustom': true}}, {'name': 'view', 'data': {'classic': {'name': 'classic', 'url': '?view\x3dclassic'}, 'flipcard': {'name': 'flipcard', 'url': '?view\x3dflipcard'}, 'magazine': {'name': 'magazine', 'url': '?view\x3dmagazine'}, 'mosaic': {'name': 'mosaic', 'url': '?view\x3dmosaic'}, 'sidebar': {'name': 'sidebar', 'url': '?view\x3dsidebar'}, 'snapshot': {'name': 'snapshot', 'url': '?view\x3dsnapshot'}, 'timeslide': {'name': 'timeslide', 'url': '?view\x3dtimeslide'}, 'isMobile': false, 'title': 'How to escape everything in a block in HTML', 'description': ' I seem to recall that there is an HTML tag that escapes absolutely everything inside it except the matching closing tag. Kind...', 'url': 'https://codeanswer30.blogspot.com/2011/03/how-to-escape-everything-in-block-in.html', 'type': 'item', 'isSingleItem': true, 'isMultipleItems': false, 'isError': false, 'isPage': false, 'isPost': true, 'isHomepage': false, 'isArchive': false, 'isLabelSearch': false, 'postId': 6326721431050764488}}]); _WidgetManager._RegisterWidget('_NavbarView', new _WidgetInfo('Navbar1', 'navbar', document.getElementById('Navbar1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_HeaderView', new _WidgetInfo('Header1', 'header', document.getElementById('Header1'), {}, 'displayModeFull')); _WidgetManager._RegisterWidget('_BlogView', new _WidgetInfo('Blog1', 'main', document.getElementById('Blog1'), {'cmtInteractionsEnabled': false, 'lightboxEnabled': true, 'lightboxModuleUrl': 'https://www.blogger.com/static/v1/jsbin/3386964323-lbx.js', 'lightboxCssUrl': 'https://www.blogger.com/static/v1/v-css/13464135-lightbox_bundle.css'}, 'displayModeFull')); _WidgetManager._RegisterWidget('_BlogArchiveView', new _WidgetInfo('BlogArchive1', 'sidebar2', document.getElementById('BlogArchive1'), {'languageDirection': 'ltr', 'loadingMessage': 'Loading\x26hellip;'}, 'displayModeFull')); </script> </body> </html>