mso-conditional-parser
Parser and translator for MSO (Outlook) conditional comments in HTML email.
Parses all real-world MSO comment patterns, validates conditions against known Outlook versions and operators, and translates them into human-readable English.
Used as the core engine by eslint-plugin-mso-conditionals and the MSO Conditional Comments VS Code extension.
Installation
npm install mso-conditional-parser
Requires Node.js 18+. ES module only ("type": "module").
API
Parses an MSO conditional comment opener.
Returns a result object or null if the input is not a recognised MSO opener.
import { parseMsoComment } from 'mso-conditional-parser';
parseMsoComment('<!--[if gte mso 16]>');
parseMsoComment('<!--[if mos]>');
Supported opener patterns:
<!--[if mso]> | downlevel-hidden |
<!--[if gte mso 16]> | downlevel-hidden |
<!--[if !mso]><!-- | downlevel-revealed |
<![if !mso]> | downlevel-revealed (non-standard) |
Result shape:
type | string | 'downlevel-hidden' or 'downlevel-revealed' |
condition | string | Raw condition string extracted from the comment |
translation | string | Human-readable English translation |
isValid | boolean | true if the condition is syntactically valid |
error | string | Present when isValid is false |
Parses an MSO conditional comment closer.
Returns { type, isClosing: true } or null if not recognised.
import { parseMsoEndComment } from 'mso-conditional-parser';
parseMsoEndComment('<![endif]-->');
parseMsoEndComment('<![endif]>');
translateCondition(condition)
Translates a raw condition string into English without full parsing.
import { translateCondition } from 'mso-conditional-parser';
translateCondition('gte mso 16');
translateCondition('!mso');
translateCondition('mso 12');
Returns true if the string is any MSO comment — opener or closer.
import { isMsoComment } from 'mso-conditional-parser';
isMsoComment('<!--[if mso]>');
isMsoComment('<![endif]-->');
isMsoComment('<p>hello</p>');
Supported conditions
mso | <!--[if mso]> | Any Outlook version |
!mso | <!--[if !mso]><!-- | Non-Outlook clients |
mso <version> | <!--[if mso 16]> | Exact Outlook version |
<op> mso <version> | <!--[if gte mso 14]> | Version comparison |
!mso <version> | <!--[if !mso 16]> | Not this version |
Compound & / | | <!--[if (gt mso 9)&(lte mso 11)]> | AND / OR |
Valid operators: gte, gt, lte, lt, eq
Valid Outlook versions: 9 (2000), 10 (2002), 11 (2003), 12 (2007), 14 (2010), 15 (2013), 16 (2016/2019/365)
Note: there is no MSO version 13 — Outlook skips from 12 (2007) to 14 (2010).
License
MIT