@wordpress/blocks
Version:
Block API for WordPress.
57 lines (55 loc) • 1.8 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/blocks/src/api/raw-handling/latex-to-math.js
var latex_to_math_exports = {};
__export(latex_to_math_exports, {
default: () => isLatexMathMode
});
module.exports = __toCommonJS(latex_to_math_exports);
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;
}
//# sourceMappingURL=latex-to-math.js.map