From 0b5e149a23bf576792612845fd97839db680c581 Mon Sep 17 00:00:00 2001 From: whilefoo Date: Sun, 3 Sep 2023 16:10:46 +0200 Subject: [PATCH] feat: html tags enum --- src/handlers/payout/post.ts | 63 +++++++++++++++++++------------------ src/types/html.ts | 27 ++++++++++++++++ 2 files changed, 59 insertions(+), 31 deletions(-) create mode 100644 src/types/html.ts diff --git a/src/handlers/payout/post.ts b/src/handlers/payout/post.ts index 8ee159b38..fed1aaabe 100644 --- a/src/handlers/payout/post.ts +++ b/src/handlers/payout/post.ts @@ -5,6 +5,7 @@ import { Incentives, MarkdownItem, MarkdownItems, Payload, StateReason, UserType import { commentParser } from "../comment"; import Decimal from "decimal.js"; import { bountyInfo } from "../wildcard"; +import { HTMLItem } from "../../types/html"; const ItemsToExclude: string[] = [MarkdownItem.BlockQuote]; /** @@ -271,35 +272,35 @@ const calculateRewardValue = (comments: Record, incentiv }; const MarkdownItemToHTMLTag: Record = { - [MarkdownItem.Text]: "p", - [MarkdownItem.Paragraph]: "p", - [MarkdownItem.Heading]: "h1", - [MarkdownItem.Heading1]: "h1", - [MarkdownItem.Heading2]: "h2", - [MarkdownItem.Heading3]: "h3", - [MarkdownItem.Heading4]: "h4", - [MarkdownItem.Heading5]: "h5", - [MarkdownItem.Heading6]: "h6", - [MarkdownItem.ListItem]: "li", - [MarkdownItem.List]: "ul", - [MarkdownItem.Link]: "a", - [MarkdownItem.Image]: "img", - [MarkdownItem.BlockQuote]: "blockquote", - [MarkdownItem.Code]: "code", - [MarkdownItem.Emphasis]: "em", - [MarkdownItem.Strong]: "strong", - [MarkdownItem.Delete]: "del", - [MarkdownItem.HTML]: "html", - [MarkdownItem.InlineCode]: "code", - [MarkdownItem.LinkReference]: "a", - [MarkdownItem.ImageReference]: "img", - [MarkdownItem.FootnoteReference]: "sup", - [MarkdownItem.FootnoteDefinition]: "li", - [MarkdownItem.Table]: "table", - [MarkdownItem.TableCell]: "td", - [MarkdownItem.TableRow]: "tr", - [MarkdownItem.ThematicBreak]: "hr", - [MarkdownItem.Break]: "br", - [MarkdownItem.Root]: "div", - [MarkdownItem.Definition]: "dl", + [MarkdownItem.Text]: HTMLItem.P, + [MarkdownItem.Paragraph]: HTMLItem.P, + [MarkdownItem.Heading]: HTMLItem.H1, + [MarkdownItem.Heading1]: HTMLItem.H1, + [MarkdownItem.Heading2]: HTMLItem.H2, + [MarkdownItem.Heading3]: HTMLItem.H3, + [MarkdownItem.Heading4]: HTMLItem.H4, + [MarkdownItem.Heading5]: HTMLItem.H5, + [MarkdownItem.Heading6]: HTMLItem.H6, + [MarkdownItem.ListItem]: HTMLItem.LI, + [MarkdownItem.List]: HTMLItem.UL, + [MarkdownItem.Link]: HTMLItem.A, + [MarkdownItem.Image]: HTMLItem.IMG, + [MarkdownItem.BlockQuote]: HTMLItem.BLOCKQUOTE, + [MarkdownItem.Code]: HTMLItem.PRE, + [MarkdownItem.Emphasis]: HTMLItem.EM, + [MarkdownItem.Strong]: HTMLItem.STRONG, + [MarkdownItem.Delete]: HTMLItem.DEL, + [MarkdownItem.HTML]: HTMLItem.HTML, + [MarkdownItem.InlineCode]: HTMLItem.CODE, + [MarkdownItem.LinkReference]: HTMLItem.A, + [MarkdownItem.ImageReference]: HTMLItem.IMG, + [MarkdownItem.FootnoteReference]: HTMLItem.SUP, + [MarkdownItem.FootnoteDefinition]: HTMLItem.P, + [MarkdownItem.Table]: HTMLItem.TABLE, + [MarkdownItem.TableCell]: HTMLItem.TD, + [MarkdownItem.TableRow]: HTMLItem.TR, + [MarkdownItem.ThematicBreak]: HTMLItem.HR, + [MarkdownItem.Break]: HTMLItem.BR, + [MarkdownItem.Root]: HTMLItem.HTML, + [MarkdownItem.Definition]: HTMLItem.DL, }; diff --git a/src/types/html.ts b/src/types/html.ts new file mode 100644 index 000000000..33cb32d01 --- /dev/null +++ b/src/types/html.ts @@ -0,0 +1,27 @@ +export enum HTMLItem { + P = "p", + H1 = "h1", + H2 = "h2", + H3 = "h3", + H4 = "h4", + H5 = "h5", + H6 = "h6", + UL = "ul", + A = "a", + IMG = "img", + BLOCKQUOTE = "blockquote", + CODE = "code", + EM = "em", + STRONG = "strong", + DEL = "del", + HTML = "html", + SUP = "sup", + LI = "li", + TABLE = "table", + TR = "tr", + TD = "td", + HR = "hr", + BR = "br", + DL = "dl", + PRE = "pre", +}