mirror of
https://github.com/rabirabirara/obsidian-jelly-snippets.git
synced 2026-07-22 07:30:22 +00:00
37 lines
692 B
TypeScript
37 lines
692 B
TypeScript
export enum Symbol {
|
|
// on parse
|
|
Newline = "\\nl\\",
|
|
Tab = "\\tab\\",
|
|
// on replace
|
|
CursorEnd = "\\end\\",
|
|
}
|
|
|
|
export namespace Symbol {
|
|
export const MAP: Record<string, string> = {
|
|
[Symbol.Newline]: "\n",
|
|
[Symbol.Tab]: "\t",
|
|
[Symbol.CursorEnd]: "",
|
|
};
|
|
export function replaceSymbols(inputStr: string): string {
|
|
const result: string[] = [];
|
|
let i = 0;
|
|
|
|
while (i < inputStr.length) {
|
|
let found = false;
|
|
for (const symbol in MAP) {
|
|
if (inputStr.startsWith(symbol, i)) {
|
|
result.push(MAP[symbol]);
|
|
i += symbol.length;
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!found) {
|
|
result.push(inputStr[i]);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
return result.join("");
|
|
}
|
|
}
|