(src: string, offset: number, marker: string, pending: string, rules: Rules)
| 224 | } |
| 225 | |
| 226 | export function validateEmphasize(src: string, offset: number, marker: string, pending: string, rules: Rules) { |
| 227 | if (!canOpenEmphasis(src, marker, pending)) |
| 228 | return false; |
| 229 | |
| 230 | if (!canCloseEmphasis(src, offset, marker)) |
| 231 | return false; |
| 232 | |
| 233 | /** |
| 234 | * 16.When there are two potential emphasis or strong emphasis spans with the same closing delimiter, |
| 235 | * the shorter one (the one that opens later) takes precedence. Thus, for example, **foo **bar baz** |
| 236 | * is parsed as **foo <strong>bar baz</strong> rather than <strong>foo **bar baz</strong>. |
| 237 | */ |
| 238 | const mLen = marker.length; |
| 239 | const emphasizeText = src.substring(mLen, offset - mLen); |
| 240 | const SHORTER_REG = new RegExp( |
| 241 | ` \\${marker.split('').join('\\')}[^\\${marker.charAt(0)}]`, |
| 242 | ); |
| 243 | const CLOSE_REG = new RegExp( |
| 244 | `[^\\${marker.charAt(0)}]\\${marker.split('').join('\\')}`, |
| 245 | ); |
| 246 | if (SHORTER_REG.test(emphasizeText) && !CLOSE_REG.test(emphasizeText)) |
| 247 | return false; |
| 248 | |
| 249 | /** |
| 250 | * 17.Inline code spans, links, images, and HTML tags group more tightly than emphasis. |
| 251 | * So, when there is a choice between an interpretation that contains one of these elements |
| 252 | * and one that does not, the former always wins. Thus, for example, *[foo*](bar) is parsed |
| 253 | * as *<a href="bar">foo*</a> rather than as <em>[foo</em>](bar). |
| 254 | */ |
| 255 | return lowerPriority(src, offset, rules); |
| 256 | } |
| 257 | |
| 258 | export function correctUrl(token: string[] | null) { |
| 259 | if (token && typeof token[4] === 'string') { |
no test coverage detected