diff --git a/src/shared-configs/DelimLookup.ts b/src/shared-configs/DelimLookup.ts new file mode 100644 index 0000000..fa90749 --- /dev/null +++ b/src/shared-configs/DelimLookup.ts @@ -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 +} \ No newline at end of file diff --git a/src/shared-configs/FormatRules.ts b/src/shared-configs/FormatRules.ts new file mode 100644 index 0000000..54c75cc --- /dev/null +++ b/src/shared-configs/FormatRules.ts @@ -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") + } +} \ No newline at end of file diff --git a/src/shared-configs/NonHighlightFormats.ts b/src/shared-configs/NonHighlightFormats.ts new file mode 100644 index 0000000..5267f1d --- /dev/null +++ b/src/shared-configs/NonHighlightFormats.ts @@ -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; +})(); \ No newline at end of file diff --git a/src/shared-configs/SpaceAllowedFormats.ts b/src/shared-configs/SpaceAllowedFormats.ts new file mode 100644 index 0000000..21dcf42 --- /dev/null +++ b/src/shared-configs/SpaceAllowedFormats.ts @@ -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; +})(); \ No newline at end of file diff --git a/src/shared-configs/SpaceRestrictedFormats.ts b/src/shared-configs/SpaceRestrictedFormats.ts new file mode 100644 index 0000000..61b247a --- /dev/null +++ b/src/shared-configs/SpaceRestrictedFormats.ts @@ -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; +})(); \ No newline at end of file diff --git a/src/shared-configs/index.ts b/src/shared-configs/index.ts new file mode 100644 index 0000000..d59e553 --- /dev/null +++ b/src/shared-configs/index.ts @@ -0,0 +1,5 @@ +export * from "./DelimLookup"; +export * from "./FormatRules"; +export * from "./NonHighlightFormats"; +export * from "./SpaceAllowedFormats"; +export * from "./SpaceRestrictedFormats"; \ No newline at end of file