Skip to content

Commit

Permalink
refactor(MarkdownUtil): rename list and table pattern constants for c…
Browse files Browse the repository at this point in the history
…larity and consistency
  • Loading branch information
olafsulich committed Jan 13, 2025
1 parent 75f3f98 commit 95fe381
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/script/util/MarkdownUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ const HORIZONTAL_RULE_PATTERN = /^(?:[-*_]){3,}\s*$/m;
const STRIKETHROUGH_PATTERN = /~~[^~]+~~/;

// List patterns
const LIST_SANITIZE_UNORDERED = /^[-*+]\s.*/gm;
const LIST_SANITIZE_ORDERED = /^[\d]+\.\s.*/gm;
const LIST_DETECT_UNORDERED = /^[-*+]\s.*/m;
const LIST_DETECT_ORDERED = /^[\d]+\.\s.*/m;
const LIST_UNORDERED_SANITIZE_PATTERN = /^[-*+]\s.*/gm;
const LIST_ORDERED_SANITIZE_PATTERN = /^[\d]+\.\s.*/gm;
const LIST_UNORDERED_DETECT_PATTERN = /^[-*+]\s.*/m;
const LIST_ORDERED_DETECT_PATTERN = /^[\d]+\.\s.*/m;

// Table patterns
const TABLE_DETECT_ROW = /^\|[^|]+\|/m;
const TABLE_DETECT_SEPARATOR = /^\|[-:|]+\|/m;
const TABLE_SANITIZE = /^\|.*\|$/gm;
const TABLE_ROW_DETECT_PATTERN = /^\|[^|]+\|/m;
const TABLE_SEPARATOR_DETECT_PATTERN = /^\|[-:|]+\|/m;
const TABLE_SANITIZE_PATTERN = /^\|.*\|$/gm;

// Special patterns
const ESCAPED_CHARS_PATTERN = /\\(.)/g;
Expand All @@ -54,14 +54,14 @@ const MARKDOWN_PATTERNS = [
ITALIC_PATTERN_2,
LINK_PATTERN,
IMAGE_PATTERN,
LIST_DETECT_UNORDERED,
LIST_DETECT_ORDERED,
LIST_UNORDERED_DETECT_PATTERN,
LIST_ORDERED_DETECT_PATTERN,
BLOCKQUOTE_PATTERN,
CODE_BLOCK_PATTERN,
CODE_INLINE_PATTERN,
HORIZONTAL_RULE_PATTERN,
TABLE_DETECT_ROW,
TABLE_DETECT_SEPARATOR,
TABLE_ROW_DETECT_PATTERN,
TABLE_SEPARATOR_DETECT_PATTERN,
STRIKETHROUGH_PATTERN,
];

Expand Down Expand Up @@ -148,11 +148,11 @@ const markdownSanitizers: MarkdownSanitizer[] = [
},
},
{
pattern: LIST_SANITIZE_UNORDERED,
pattern: LIST_UNORDERED_SANITIZE_PATTERN,
transform: (match: string) => match.replace(/^[-*+]\s/, ''),
},
{
pattern: LIST_SANITIZE_ORDERED,
pattern: LIST_ORDERED_SANITIZE_PATTERN,
transform: (match: string) => match.replace(/^[\d]+\.\s/, ''),
},
{
Expand All @@ -172,7 +172,7 @@ const markdownSanitizers: MarkdownSanitizer[] = [
transform: (_match: string) => '',
},
{
pattern: TABLE_SANITIZE,
pattern: TABLE_SANITIZE_PATTERN,
transform: (match: string) => {
const line = match.trim();
if (isTableSeparator(line)) {
Expand Down

0 comments on commit 95fe381

Please sign in to comment.