UNPKG

@condenast/flyway-schema-validator

Version:
34 lines (26 loc) 1.31 kB
// CFM spec: https://github.com/conde-nast-international/copilot-markdown/blob/master/specification/0E.md // CommonMark spec: https://spec.commonmark.org/0.27/ // Note: markdown content can also contain HTML, for example: // <a href="https://www.marksandspencer.com/de/sizeguides/?cid=sizeguidewomens-tops#Returns-Policy"> // Welcome to Marks &amp; Spencer</a> // Markdown that should not be parsed if they appear anywhere in the string // ` or [#: or [#image: const RE_MD_UNWANTED = /([^\\])([`]|(\[#\S*:))/g; // Markdown that should not be parsed if they appear at the beginning // > or # or ` or [#: or [#image: const RE_MD_UNWANTED_LEADING = /^([>#`]|(\[#\S*:))/; // Markdown unordered list markers that should not be parsed // * or - const RE_MD_UNWANTED_LISTMARKERS_UNORDERED = /^[*-]\s/; // Markdown ordered list markers that should not be parsed // 1. or 1) or 11. or 11) const RE_MD_UNWANTED_LISTMARKERS_ORDERED = /^([0-9]+)([.)]\s)/; // Escape unwanted block-level markdown entities const escapeUnwantedBlockMarkdown = str => str && str .replace(RE_MD_UNWANTED, '$1\\$2') .replace(RE_MD_UNWANTED_LEADING, '\\$1') .replace(RE_MD_UNWANTED_LISTMARKERS_UNORDERED, '\\$&') .replace(RE_MD_UNWANTED_LISTMARKERS_ORDERED, '$1\\$2'); module.exports = escapeUnwantedBlockMarkdown;