0

I am implementing a linqpad util to get the html formatted results from a serialized object, however, it is including it's own CSS in the process when I dump the raw HTML in my view. I want to encapsulate this within an iframe to preserve all of the other CSS.

The issue I am running into is the quotation marks within the string DumpHTML

For context Writes to my model

var writer = LINQPad.Util.CreateXhtmlWriter(true);
writer.Write(objectToSerialize);
strHTML = writer.ToString();

Just dumping the results onto the page

$(function () {
        var ifrm = document.getElementById('myIframe');
        ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
        ifrm.document.open();
        ifrm.document.write('@Html.Raw(Model.DumpHTML)');
        ifrm.document.close();
    });

This is what is happening with my output:

$(function () {
        var ifrm = document.getElementById('myIframe');
        ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
        ifrm.document.open();
        ifrm.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <meta name="Generator" content="LINQ to XML, baby!" />
  <style type='text/css'>
body
{
    margin: 0.3em 0.3em 0.4em 0.5em;
    font-family: Verdana;
    font-size: 80%;
    ....

Is there any way around this? Ultimately the issue is all of the auto generated styles are overriding the css on the page.

Zach M.
  • 1,188
  • 7
  • 22
  • 46
  • Have you tried removing the style tag from the string – Lokesh Suthar Mar 06 '14 at 20:40
  • I need the style tag to format the auto generated table sadly. So i'm in the position of having to maintain the styling while not inhibiting the styling of the rest of my page. – Zach M. Mar 06 '14 at 20:56
  • I am assuming, the styling for table is constant? You can extract that and remove style tag. – Lokesh Suthar Mar 06 '14 at 20:58
  • I cannot guarantee that the styling is always constant as I have only just started working with this. I suppose that could be an option and I'll have to preserve the styling elsewhere. Being able to just push this to the iframe was the quick solution. If it turns out that I cannot do it then I will go the other route. – Zach M. Mar 06 '14 at 21:01
  • 1
    I just ended up navigating to a new page. – Zach M. Mar 07 '14 at 19:17
  • You said you were having problems with quotes, did you try escaping the quotes before passing it in `HTML.Raw()` – Lokesh Suthar Mar 07 '14 at 19:20
  • That would have required me to loop through the string and escape all the quotes programmatically. I didn't want to do all that. – Zach M. Mar 07 '14 at 19:35
  • You could use regex. It's significantly faster. – Lokesh Suthar Mar 07 '14 at 19:37
  • Here I found [this](http://stackoverflow.com/questions/249791/regex-for-quoted-string-with-escaping-quotes) – Lokesh Suthar Mar 07 '14 at 19:39
  • This is true, However I already solved my problem through another means, going to close this question. – Zach M. Mar 07 '14 at 19:39

0 Answers0