feat: add some configs for parsing

This commit is contained in:
kotaindah55 2025-02-03 20:13:41 +02:00
parent bf20f09b7e
commit 5f5fc5c72d
6 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,9 @@
import { Format } from "src/enums";
import { MainFormat } from "src/types";
export const DelimLookup: { [Prop in string]: MainFormat } = {
["+"]: Format.INSERTION,
["|"]: Format.SPOILER,
["^"]: Format.SUPERSCRIPT,
["~"]: Format.SUBSCRIPT
}

View file

@ -0,0 +1,41 @@
import { Format } from "src/enums";
import { MainFormat } from "src/types";
export const FormatRules: { [P in MainFormat]: {char: string, length: number, exactLen: boolean, allowSpace: boolean, getEl: () => Element} } = {
[Format.INSERTION]: {
char: "+",
length: 2,
exactLen: true,
allowSpace: true,
getEl: () => document.createElement("ins")
},
[Format.SPOILER]: {
char: "|",
length: 2,
exactLen: true,
allowSpace: true,
getEl: () => document.createElement("spoiler-span")
},
[Format.SUPERSCRIPT]: {
char: "^",
length: 1,
exactLen: true,
allowSpace: false,
getEl: () => document.createElement("sup")
},
[Format.SUBSCRIPT]: {
char: "~",
length: 1,
exactLen: true,
allowSpace: false,
getEl: () => document.createElement("sub")
},
// unused
[Format.HIGHLIGHT]: {
char: "=",
length: 2,
exactLen: false,
allowSpace: true,
getEl: () => document.createElement("mark")
}
}

View file

@ -0,0 +1,12 @@
import { MainFormat } from "src/types";
import { FormatRules } from "src/shared-configs";
import { Format } from "src/enums";
export const NonHighlightFormats = (() => {
let formats: MainFormat[] = [];
for (let format in FormatRules) {
let type = Number.parseInt(format) as MainFormat;
if (type != Format.HIGHLIGHT) { formats.push(type) }
}
return formats;
})();

View file

@ -0,0 +1,11 @@
import { MainFormat } from "src/types";
import { FormatRules } from "src/shared-configs";
export const SpaceAllowedFormats = (() => {
let formats: MainFormat[] = [];
for (let format in FormatRules) {
let type = Number.parseInt(format) as MainFormat;
if (FormatRules[type].allowSpace) { formats.push(type) }
}
return formats;
})();

View file

@ -0,0 +1,11 @@
import { MainFormat } from "src/types";
import { FormatRules } from "src/shared-configs";
export const SpaceRestrictedFormats = (() => {
let formats: MainFormat[] = [];
for (let format in FormatRules) {
let type = Number.parseInt(format) as MainFormat;
if (!FormatRules[type].allowSpace) { formats.push(type) }
}
return formats;
})();

View file

@ -0,0 +1,5 @@
export * from "./DelimLookup";
export * from "./FormatRules";
export * from "./NonHighlightFormats";
export * from "./SpaceAllowedFormats";
export * from "./SpaceRestrictedFormats";