Parse WhatApp markdown and sanitize messages; remove message drift calculation; standardize spacing for body and child containers.

This commit is contained in:
天クマ 2026-08-17 16:58:15 -03:00
commit 97509c47ca
5 changed files with 75 additions and 42 deletions

28
web/src/parser.ts Normal file
View file

@ -0,0 +1,28 @@
export class Parser {
input: string;
constructor(input: string) {
this.input = input;
}
parse(token: string, to: string): Parser {
const esc = Parser.escapeRegex(token);
const regex = new RegExp(`(^|\\s)${esc}(.+?)${esc}(?=\\s|$)`, "gs");
this.input = this.input.replace(regex, (match, pre, inner) => {
return `${pre}${to.replace("$1", inner)}`;
});
return this;
}
replace(searchValue: string, replaceValue: string): Parser {
this.input = this.input.replaceAll(searchValue, replaceValue);
return this;
}
static escapeRegex(string: string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
}