UNPKG

@wordpress/blocks

Version:
37 lines (36 loc) 899 B
// packages/blocks/src/api/raw-handling/latex-to-math.js function isLatexMathMode(text) { const lettersRegex = /[\p{L}\s]+/gu; let match; while (match = lettersRegex.exec(text)) { if (text[match.index - 1] === "{") { continue; } let sequence = match[0]; if (text[match.index - 1] === "\\") { sequence = sequence.replace(/^[a-zA-Z]+/, ""); } if (sequence.length < 6) { continue; } return false; } if (/\\[a-zA-Z]+\s*\{/g.test(text)) { return true; } const softClues = [ (t) => t.includes("^") && !t.startsWith("^"), (t) => ["=", "+", "-", "/", "*"].some( (operator) => t.includes(operator) ), (t) => /\\[a-zA-Z]+/g.test(t) ]; if (softClues.filter((clue) => clue(text)).length >= 2) { return true; } return false; } export { isLatexMathMode as default }; //# sourceMappingURL=latex-to-math.js.map