I have a HTML text with <!--[if gte mso 9]> and <![endif]--> tags. I want to remove everything that there is between those two tags.
I'm using the ruby function gsub with a Regex expression, but it won't work.
This is what I've tried:
text = "<!--[if gte mso 9]><xml>\n <w:WordDocument>\n [...] \n</style>\n<![endif]-->"
text2 = text.gsub /(?=<!\-\-\[if gte mso 9\]>)(.*?)(?<=<!\[endif\]\-\->)/, ""
What I want as an answer is:
text2 = "<!--[if gte mso 9]><![endif]-->"
Or even:
text2 = ""
I tried this based on this article
I've tried this online Regex tester and, it seems to be the right way to do it, but it won't work on my program!
Please help!
Thanks in advance!
Try this regex /(?<=<!--\[if gte mso 9\]>).*?(?=<!\[endif\]-->)/m, and do a gsub on the string. You will get <!--[if gte mso 9]><![endif]-->
(?<=<!--\[if gte mso 9\]>) is a positive look behind, which matches the <!--\[if gte mso 9\]> string, but doesn't include it in the result.
.* matches any characters 0 or more times.
(?=<!\[endif\]-->) is a positive look forward, which matches the <!\[endif\]--> but doesn't include it in the result.
the m identifier at the end means the match multiline strings. Since you declared your string with "", the \n will be interpreted as a new line.
Essentially, you are matching everything in between the two tags.
In your regex, /(?=<!\-\-\[if gte mso 9\]>)(.*?)(?<=<!\[endif\]\-\->)/, you used the positive look forward for the first tag, and positive look behind for the second tag, you need to flip them.
Positive look forward matches a group after the main expression without including it in the result.
Positive look behind matches a group before the main expression without including it in the result.
Related
As known Outlook client (Win version) doesn't use div's so I have to use tables. In order to make responsive design, I'm trying to use the hybrid design (as mentioned here https://www.litmus.com/blog/mobile-responsive-email-stacking/)
The problem is that the outlook client (outlook365 on win10) just ignores every syntax of conditional comments, and gives me the same results as if it was Gmail.
I couldn't find any answer. Could it be that Microsoft just removed this feature from their mail client? or am I doing something wrong.
I'll appreciate any idea. Thank you.
This is the HTML I've sent to myself and I got only the lines saying "this is not mso" (both conditions were ignored (the positive and the negative).
<!--[if mso]>
this is mso
<![endif]-->
<!--[if (gte mso 9)|(IE)]>
gte mso 9
<![endif]-->
<!--[if gte mso 16]>
this is mso 16
<![endif]-->
<!--[if (gte mso 9)|(IE)]>
gte mso 9
<![endif]-->
<!--[if !((gte mso 9)|(IE))]><!-- -->
This is not mso 9\ie
<!--<![endif]-->
<!--[if !mso]><!-- -->
This is not mso
<!--<![endif]-->
For emails I use conditional comments in order to make UI adjustments for Outlook '07+. When saving in TinyMCE it adds a space changing
this
<!--[if gte mso 9]>
to this
<!-- [if gte mso 9]> (with space before the [)
which doesn't get interpreted by Outlook anymore.
Any idea if there is a setting in TinyMCE to prevent this change?
--
Secondary: In case this is easy to add, I'd ideally would like comments to also not be moved to the previous line, but couldn't find a setting for this either.
Example:
Some text
<!-- Outlook hack here -->
<!--[if gte mso 9]>
<tag>
should not become
Some text <!-- Outlook hack here --> <!-- [if gte mso 9]>
<tag>
We had this problem and solved it by adding
allow_conditional_comments: true
Example below taken directly from the documentation: https://www.tiny.cloud/docs/configure/content-filtering/
tinymce.init({
selector: 'textarea', // change this value according to your HTML
allow_conditional_comments: true
});
I'm not sure how to best solve the second question.
I have an outlook specific conditional statement that I can't seem to get to render in XSL. I've tried saving them as variables and printing them, putting them in tags... All with no luck.
Below is the code:
<!--[if gte mso 9]>
... code ...
<![endif]-->
Any ideas?
I have an outlook specific conditional statement that I can't seem to get to render in XSL.
What you are showing is an XML comment (<!-- comment -->) . Therefor you may try:
<xsl:comment>[if gte mso 9]>
... code ...
<![endif]</xsl:comment>
As an alternative you can use disable-output-escaping="yes" with <![CDATA[. Try:
<xsl:text disable-output-escaping="yes">
<![CDATA[ <!--[if gte mso 9]>
... code ...
<![endif]--> ]]>
</xsl:text>
I am just about at making my website compatibility, and with IE, the old jerk, I need to use
<!--[if lte IE 8]>
<![endif]-->
However, as "lte IE8" means "equal to or less than IE8", how can IE6 even read this ?
Also, is it lt or lte ?
http://www.quirksmode.org/css/condcom.html refers both, though only lte in it's definition.
Conditional comments are forwards-compatible. IE detects the number after the "IE" token and compares it to its current version. It doesn't have a built-in whitelist "IE7, IE8" or anything. It will work.
To answer one part of your question, which no-one seemed to answer explicitly and I have been trying to figure out ...
is it lt or lte?
Without realising what lt and lte are, you might be unsure which to use, however from reading other comments, I realised that lt = less than and lte = less than or equal to (similary gt and gte are greater than and greater than or equal to), so it depends which versions of IE you want the rule to apply to as to whether you use lt, lte or a combination.
I suppose you can look at it as an expression:
<!--[if expression]> HTML <![endif]-->
Another example would also work:
<!--[if true]> HTML <![endif]-->
About conditions
I need some particular css for an html email, but only in outlook.
I'm looking for the outlook equivalent of
<!--[if IE]>body {background-color:red} <![endif]-->
<!--[if gte mso 9]
// This CSS will only be seen in Outlook 2007
![endif]-->