Andrew Nurse

Andrew Nurse bobmcsmith

Niner since 2007

I work on the ASP.Net on the Razor parser!


  • Andrew Nurse: Inside "Razor"

    1. We discussed a number of options and ended up feeling that "@" was cleaner.  In the end, every character has its downside from an escaping perspective, so there's no perfect character to choose


    2. Right now, Razor is similar to ASPX in that it basically looks like option A.  This is something we've thought a bit about, but it's not likely to improve in v1.  The primary issue is that the markup indentation is something the parser would have to capture and pass on to the code somehow.

  • Andrew Nurse: Inside "Razor"

    Hey reinux, it's always cool to meet a fellow SFUer Smiley.  Razor has a system for plugging in new code languages that we haven't quite finished working out yet, but in the next releases I expect to be able to add better support for creating new code languages without having to totally rewrite the parser.  Obviously, as a code language developer, you'd have to implement the logic to parse blocks of the new language, but you'd still get quite a bit for free.  Once that's cleaned-up a bit, one could absolutely add F# support Smiley

  • Andrew Nurse: Inside "Razor"

    Looks like I was slow on the up-shot for the earlier reply and Erik beat me to it Tongue Out.  Btw, this is Andrew in case anyone is wondering, glad to hear your feedback on the Razor syntax and parser!


    The issue here the HTML encoding that is auto-applied when printing variables like "@i".  The contents of the <text> tag are considered HTML markup, and they can include HTML tags, we just don't render the outer <text> tag.  So there's no need for a separate tag for markup, since markup is allowed within <text>.

  • Andrew Nurse: Inside "Razor"

    If you have a string with XML tags in it and pass it through "@", it will be HTML encoded.  This is what I meant in the video when I mentioned that "@p" is like "<%: p %>" rather than "<%= p %>".


    However, if you pass an IHtmlString through "@", it won't be HTML encoded.  Right now, the easiest way to do this is:


    @(new HtmlString("<p>Some text</p>"))


    We are considering a helper method, something like "Literal" which would do this wrapping for you, meaning you could write:



    @{ var foo = "<p>Some text and markup</p>" } @Literal(foo)


    Just like in MVC, all of our helpers will output IHtmlString so you won't have to worry about them.  When writing your own markup helpers, you should ensure they return some type that implements IHtmlString (I recommend System.Web.HtmlString Smiley ) so they don't get encoded.