jamietre / CsQuery

CsQuery is a complete CSS selector engine, HTML parser, and jQuery port for C# and .NET 4.
Other
1.16k stars 249 forks source link

Downlevel-revealed conditional comments incorrectly modified #190

Open rctyler opened 9 years ago

rctyler commented 9 years ago

I have the job of building html emails that need to look great across multiple email clients. Microsoft Outlook usually gives me a lot of trouble, but one way to get around certain caveats with that client is through conditional comments. I particularly need these downlevel-revealed comments to be in the form of <![if !mso]> and <![endif]> (see http://esd.io/blog/html-email-buttons-conditional-comments.html). I use Premailer.Net to inline my CSS styles, which uses CsQuery in turn. The problem is that those conditional comments are not valid html comments (intentionally so), and CsQuery is modifying them to <!--[if !mso]--> and <!--[endif]-->. This subtle change unfortunately breaks html emails in Outlook.com. Are there any workarounds? The piece of code in question is here: https://github.com/jamietre/CsQuery/blob/master/source/CsQuery/Output/OutputFormatterDefault.cs#L435

BenJury commented 9 years ago

Given it’s not valid HTML, it’s probably going to be easier just to post-process the HTML to find and replace the comments.

From: rctyler [mailto:notifications@github.com] Sent: 06 June 2015 02:13 To: jamietre/CsQuery Subject: [CsQuery] Downlevel-revealed conditional comments incorrectly modified (#190)

I have the job of building html emails that look great across multiple email clients. Microsoft Outlook usually gives me a lot of trouble, but one way to get around certain caveats with that client is through conditional comments. I particularly need these conditional comments to be in the form of <![if !mso]> and <![endif]> (see http://esd.io/blog/html-email-buttons-conditional-comments.html). I use Premailer.Net to inline my CSS styles, which uses CsQuery in turn. The problem is that those conditional comments are not valid html comments (intentionally so), and CsQuery is modifying them to and . This subtle change unfortunately breaks html emails in Outlook.com. Are there any workarounds?

— Reply to this email directly or view it on GitHubhttps://github.com/jamietre/CsQuery/issues/190.

[cid:image9ed4b2.GIF@03459572.478588c0]

25 Berkeley Square London | W1J 6HN

Ben Jury

Tel: +44 (0) 20 7268 7821 Email: ben.jury@amius.commailto:ben.jury@amius.com Web: www.amius.comhttp://www.amius.com


DISCLAIMER: The contents of this message and attachment(s) are intended for the addressee(s) only and are private and confidential. You should not use, copy or transmit this message if it is not intended for you. The opinions expressed in this message and/or any attachments are those of the author and not necessarily those of Amius, its subsidiaries and affiliates. Any facts stated and estimates and opinions given have been obtained from, or based upon sources believed by Amius to be reliable; however no representation or warranty, express or implied, is made nor responsibility of any kind accepted by Amius, its directors or employees either as to the accuracy or completeness of any information stated herein. Amius does not accept responsibility for changes made to this message after it was sent. For the protection of Amius and its clients and customers, and in compliance with regulatory requirements, the contents of both incoming and outgoing e-mail communications may be read by authorised persons within Amius other than the intended recipient(s). Although this e-mail and any attachments are believed to be free of any virus, or other defect which might affect any computer or system into which they are received and opened, it is the responsibility of the recipient to ensure that they are virus free and no responsibility is accepted by Amius for any loss or damage from receipt or use thereof. Amius Limited, is registered in England & Wales under registration number 3576013. Registered office: 3rd Floor, 25 Berkeley Square, London, W1J 6HN. Amius is a trading name of Amius Limited (AL). AL is authorised and regulated by the Financial Conduct Authority. Visit our website for further information: www.amius.comhttp://www.amius.com

This email has been scanned for email related threats and delivered safely by Mimecast.

For more information please visit http://www.mimecast.com

rctyler commented 9 years ago

@BenJury, thanks for the response. That is currently what I'm having to do...I don't prefer the post processing, but in my case it doesn't add to much complexity to the code base so I'm fine with it. However, it would be nice if there was a way to ignore conditional comments when enforcing validity.