find-conditional-comments
v0.0.6
Published
Finds all conditional comments in a string
Downloads
1,350
Maintainers
Readme
find-conditional-comments
Finds all conditional comments in a string
Install
$ npm install find-conditional-comments
Usage
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" } ]
API
findConditionalComments(html)
Returns an Array of Objects for each comment with the following properties:
isComment
boolean
Whether the comment is an HTML comment. This might be false
for certain items when downlevel
is revealed
.
open
String
Opening portion of the conditional comment.
close
String
Closing portion of the conditional comment.
bubble
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]-->
downlevel
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]>
range
Array
A range array containing the start and end indices of the comment.