import DISingleton from "../../di/DISingleton"; import { RegisterSingleton } from "../../di/RegisterSingleton"; import { Register } from "../../di/Register"; type Processor = [string, string, (s: string, e: string, t: string) => string ]; type Exp = [ RegExp, Processor?, Processor?, Processor?, Processor?, Processor?, Processor? ] | [ RegExp , (t: string) => string ] | [ RegExp , string ]; const regExps: Exp[] = [ [ /(\_{3})([^\_]+)(\_{3})/gmi, "$2" ], [ /(\_{2})([^\_]+)(\_{2})/gmi, "$2" ], [ /(\_{1})([^\_]+)(\_{1})/gmi, "$2" ], [ /(\*{3})([^\*]+)(\*{3})/gmi, "$2" ], [ /(\*{2})([^\*]+)(\*{2})/gmi, "$2" ], [ /(\*{1})([^\*]+)(\*{1})/gmi, "$2" ], [ /(\#{5})\s([^\n]+)/gmi, "
$2
"], [ /(\#{4})\s([^\n]+)/gmi, "

$2

"], [ /(\#{3})\s([^\n]+)/gmi, "

$2

"], [ /(\#{2})\s([^\n]+)/gmi, "

$2

"], [ /(\#{1})\s([^\n]+)/gmi, "

$2

"], [ /\n+/gmi, (t) => `
` ] ]; @DISingleton() export default class MarkdownService { public static instance: MarkdownService = new MarkdownService(); public toHtml(text: string): string { for (const iterator of regExps) { const reg = iterator[0]; if (iterator.length === 2) { const re = iterator[1]; if (typeof re === "string" || typeof re === "function") { text = text.replace(reg, re as any); } } } return text; } }