| |
| |
| |
| |
|
|
| import type {AnyParseNode} from "./types/nodes"; |
|
|
| |
| const uppercase = /([A-Z])/g; |
| export const hyphenate = (str: string): string => |
| str.replace(uppercase, "-$1").toLowerCase(); |
|
|
| const ESCAPE_LOOKUP: Record<string, string> = { |
| "&": "&", |
| ">": ">", |
| "<": "<", |
| "\"": """, |
| "'": "'", |
| }; |
|
|
| const ESCAPE_REGEX = /[&><"']/g; |
|
|
| |
| |
| |
| export const escape = (text: unknown): string => |
| String(text).replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]); |
|
|
| |
| |
| |
| |
| |
| export const getBaseElem = (group: AnyParseNode): AnyParseNode => { |
| if (group.type === "ordgroup") { |
| if (group.body.length === 1) { |
| return getBaseElem(group.body[0]); |
| } else { |
| return group; |
| } |
| } else if (group.type === "color") { |
| if (group.body.length === 1) { |
| return getBaseElem(group.body[0]); |
| } else { |
| return group; |
| } |
| } else if (group.type === "font") { |
| return getBaseElem(group.body); |
| } else { |
| return group; |
| } |
| }; |
|
|
| const characterNodesTypes = new Set(["mathord", "textord", "atom"]); |
|
|
| |
| |
| |
| |
| |
| export const isCharacterBox = (group: AnyParseNode): boolean => |
| characterNodesTypes.has(getBaseElem(group).type); |
|
|
| |
| |
| |
| |
| |
| export const protocolFromUrl = (url: string): string | null => { |
| |
| |
| |
| const protocol = /^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i |
| .exec(url); |
| if (!protocol) { |
| return "_relative"; |
| } |
| |
| if (protocol[2] !== ":") { |
| return null; |
| } |
| |
| |
| if (!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(protocol[1])) { |
| return null; |
| } |
| |
| return protocol[1].toLowerCase(); |
| }; |
|
|