13

Im working with some legacy code that generates a given message on a webpage but surrounds it with a <pre> tag - I was hoping to put a link (anchor tags) within it like this:

<pre>User created successfully - <a href='/View/User/17'>click here</a> to view the users profile</pre>

But I think because its a <pre> tag it ignores tags within it. Is there any way around this?

APOLOGIES

Im really sorry to have wasted everyone's time - the reason why it was happening was due to the fact that I was using ModelState.AddModelError (in ASP.NET MVC) to set the error message, which automatically HTML encodes the message you give it (I used Chrome's element inspector which shows the HTML decoded version, hence the confusion)

Jimbo
  • 22,379
  • 42
  • 117
  • 159
  • 3
    Works for me: http://jsfiddle.net/QcaV6/1/ (The content model of a [PRE](http://www.w3.org/TR/html-markup/pre.html#pre) element is "phrasing content" which includes stuff like A, and SPAN elements.) – Šime Vidas Dec 12 '12 at 14:00
  • what do you mean ignores tags? http://jsfiddle.net/FzSwk/ – Dziad Borowy Dec 12 '12 at 14:01
  • I see the JSFiddle examples work perfectly :( Must be something else making it happen - I will post screenshots! – Jimbo Dec 12 '12 at 14:04
  • "it ignores tags within it" — No, `
    ` does not do that, `` does that (`<xmp>` is evil), `CDATA` does that (`CDATA` is not supported by browsers in text/html documents).
    – Quentin Dec 12 '12 at 14:04
  • @jonhopkins: First, this document is ancient. Second, could you quote the passage where it says "ignores inner elements" or something similar? – Zeta Dec 12 '12 at 14:10
  • @Zeta yea, it is pretty old.. But I haven't noticed any changes to the pre tag in the last few years. Quoted from the document: "You should NOT use elements that define paragraph formatting within the PRE element. This means you should not use

    ,

    , and so on...You can use Anchor."
    – jonhopkins Dec 12 '12 at 14:14
  • @jonhopkins: Oops, accidentally read "can't do that", I'm sorry. – Zeta Dec 12 '12 at 14:19

1 Answers1

13

Phrasing content (such as <a>) is allowed in <pre>.

References:

Community
  • 1
  • 1
Zeta
  • 103,620
  • 13
  • 194
  • 236