Finds all conditional comments in a string
$ npm install find-conditional-comments
const findConditionalComments = require('find-conditional-comments');
const html = `
<!--[if mso]>
Hello, Microsoft Outlook!
<![endif]-->
`
findConditionalComments(html);
//=> [ { open: "<!--[if mso]>", close: "<![endif]-->", range: [1, 63], downlevel: "hidden" } ]
Returns an Array of Objects for each comment with the following properties:
boolean
Whether the comment is an HTML comment. This might be false
for certain items when downlevel
is revealed
.
String
Opening portion of the conditional comment.
String
Closing portion of the conditional comment.
boolean
Whether the comment "bubbles" around the value.
When true
, the comment is visible to all platforms except those that support conditional comments.
<!--[if !mso]>-->
Hello, Not Microsoft Outlook!
<!--<![endif]-->
When false
, the comment is hidden from all platforms except those that support conditional comments.
<!--[if mso]>
Hello, Microsoft Outlook!
<![endif]-->
String
Either hidden
or revealed
.
hidden
means the comment is hidden from all platforms except those that support conditional comments.
revealed
means the comment is visible to all platforms except those that support conditional comments.
This is very similar to the bubble
property, but it's not the same.
downlevel
always be revealed
if bubble
is true
.
But bubble
can be true
even if downlevel
is hidden
when using this syntax:
<![if lt IE 8]>
<p>Please upgrade to Internet Explorer version 8.</p>
<![endif]>
Array
A range array containing the start and end indices of the comment.