Util.RawHtml and whitespaces

edited May 2012
Hi guys,
It seems that Util.RawHtml will add formatting to the output of the provided XML.
The problem here is, that I want to display syntax highlighted code, which is contained in a <pre>. [1]
Because of the formatting, the output looks rather weird (the pre-tag will retain the whitespaces that were introduced by the XML formatting)
I would suggest to add an optional parameter to RawHtml, to tell LinqPad to use:
xml.ToString(SaveOptions.DisableFormatting)
Or simply always use SaveOptions.DisableFormatting for RawHtml.

btw, I am using the current Beta (4.42.01)

[1] If you found this thread searching for syntax highlighting in LinqPad, I am using ColorCode http://colorcode.codeplex.com/

Comments

  • Can you give an example?

    btw, are you aware that LINQPad has a built-in feature for displaying syntax-colored text?

    PanelManager.DisplaySyntaxColoredText ("var x = \"foo\"", SyntaxLanguageStyle.CSharp);

    SyntaxLanguageStyle can be one of the following:

    None, CSharp, VB, FSharp, SQL, ESQL, CSS, HTML, JavaScript, PowerShell, Python, XAML, XML
  • edited May 2012
    Hi Joe,
    You can run this query and should see some whitespace before the text:
    new{SomeProp=Util.RawHtml("<pre><span>Shouldn't have whitespace on the left</span></pre>")}
    Oh and I know about PanelManager.DisplaySyntaxColoredText, but it doesn't put the text in the ordinary HTML-based output, but into extra "tabs".
    Sometimes, I want to show some scripts in a table, and RawHtml is doing the job almost perfectly. :-)
  • OK: I'll get rid of the formatting in LINQPad's HTML output. I don't see why it's needed - it only adds bloat and people can use reformatting tools if they're interested in examining the source.
  • Cool, thx a lot! :-)
  • This is now in beta:
    www.linqpad.net/beta.aspx
  • Thx Joe,
    One tiny little problem still remains:
    The overload of RawHtml, that takes a string does not preserve whitespaces.
    When you run the following query, you should see that there is no whitespace between "blue" and "red".
    Util.RawHtml(@<pre><span style='color:Blue;'>blue</span> <span style='color:Red;'>red</span></pre>)
    When I change it to use the overload that takes an XElement (parsing it with LoadOptions.PreserveWhitespace), the output is as expected:
    Util.RawHtml(XElement.Parse(@<pre><span style='color:Blue;'>blue</span> <span style='color:Red;'>red</span></pre>, LoadOptions.PreserveWhitespace))

    I simply changed it in my utility library to use the XElement-overload, so I do not need that fix.
    It isn't really obvious, though and the fix seems to be quite straight forward.

    Thx for your work on this awesome tool.

    Cheers,
    Robert

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!