mirror of
https://github.com/kotaindah55/extended-markdown-syntax.git
synced 2026-07-22 05:38:06 +00:00
feat: add some configs for parsing
This commit is contained in:
parent
bf20f09b7e
commit
5f5fc5c72d
6 changed files with 89 additions and 0 deletions
9
src/shared-configs/DelimLookup.ts
Normal file
9
src/shared-configs/DelimLookup.ts
Normal 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
|
||||
}
|
||||
41
src/shared-configs/FormatRules.ts
Normal file
41
src/shared-configs/FormatRules.ts
Normal 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")
|
||||
}
|
||||
}
|
||||
12
src/shared-configs/NonHighlightFormats.ts
Normal file
12
src/shared-configs/NonHighlightFormats.ts
Normal 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;
|
||||
})();
|
||||
11
src/shared-configs/SpaceAllowedFormats.ts
Normal file
11
src/shared-configs/SpaceAllowedFormats.ts
Normal 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;
|
||||
})();
|
||||
11
src/shared-configs/SpaceRestrictedFormats.ts
Normal file
11
src/shared-configs/SpaceRestrictedFormats.ts
Normal 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;
|
||||
})();
|
||||
5
src/shared-configs/index.ts
Normal file
5
src/shared-configs/index.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export * from "./DelimLookup";
|
||||
export * from "./FormatRules";
|
||||
export * from "./NonHighlightFormats";
|
||||
export * from "./SpaceAllowedFormats";
|
||||
export * from "./SpaceRestrictedFormats";
|
||||
Loading…
Reference in a new issue