From 4ba5532653bff52b61c109463ee4333a481c250a Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:18:00 +0300 Subject: [PATCH 01/10] refactor: regex literals only; drop JS mirrors and hand-written d.ts --- src/lists/empty-ol.ts | 7 +------ src/lists/empty-ul.ts | 7 +------ src/lists/ol.ts | 6 ++---- src/lists/ul.ts | 17 ++--------------- src/tags/blockquote.ts | 11 ++--------- src/tags/br.ts | 9 ++------- src/tags/code.ts | 8 ++------ src/tags/del.ts | 8 ++------ src/tags/empty-blockquote.ts | 7 +------ src/tags/header.ts | 4 +++- src/tags/hr.ts | 11 ++--------- src/tags/image.ts | 10 ++-------- src/tags/italic.ts | 2 +- src/tags/link.ts | 10 ++-------- src/tags/paragraph.ts | 9 ++------- src/tags/quote.ts | 7 +------ src/tags/strong.ts | 2 +- src/utils.ts | 8 ++------ 18 files changed, 31 insertions(+), 112 deletions(-) diff --git a/src/lists/empty-ol.ts b/src/lists/empty-ol.ts index 45d7a49c..39afb48f 100644 --- a/src/lists/empty-ol.ts +++ b/src/lists/empty-ol.ts @@ -1,7 +1,2 @@ -/** - * Matches consecutive ordered list HTML tags with optional whitespace. - * Useful for cleaning up generated HTML. - * - * Example:
    or
    - */ +/** @example "
    " */ export const REGEXP_EMPTY_OL = /<\/ol>\s?
      /g; diff --git a/src/lists/empty-ul.ts b/src/lists/empty-ul.ts index 85f5280f..213778ba 100644 --- a/src/lists/empty-ul.ts +++ b/src/lists/empty-ul.ts @@ -1,7 +1,2 @@ -/** - * Matches consecutive unordered list HTML tags with optional whitespace. - * Useful for cleaning up generated HTML. - * - * Example:
        or
        - */ +/** @example "
        " */ export const REGEXP_EMPTY_UL = /<\/ul>\s?
          /g; diff --git a/src/lists/ol.ts b/src/lists/ol.ts index 9c18748e..2e0a0e4b 100644 --- a/src/lists/ol.ts +++ b/src/lists/ol.ts @@ -1,4 +1,2 @@ -import { NEWLINE } from '../utils'; - -/** Matches ordered list items: 1. item */ -export const REGEXP_OL_LIST = new RegExp(NEWLINE + '[0-9]+\\.(.*)', 'g'); +/** @example "\n1. item" */ +export const REGEXP_OL_LIST = /(?:\r\n|\r|\n)\d+\.(.*)/g; diff --git a/src/lists/ul.ts b/src/lists/ul.ts index 800189ca..fa7233ed 100644 --- a/src/lists/ul.ts +++ b/src/lists/ul.ts @@ -1,15 +1,2 @@ -import { NEWLINE } from '../utils'; - -/** - * Matches unordered list items (lines starting with *). - * Supports optional leading indentation (4 spaces). - * Platform-agnostic newline handling. - * - * Example: - * * item one - * * item two - */ -export const REGEXP_UL_LIST = new RegExp( - `${NEWLINE}(((?:\\s{4})?\\*(.*?)${NEWLINE}){1,})`, - 'g' -); +/** @example "\n* item\n" */ +export const REGEXP_UL_LIST = /(?:\r\n|\r|\n)(?:\s{4})?\*(.*)/g; diff --git a/src/tags/blockquote.ts b/src/tags/blockquote.ts index 7ddc9517..dc37f3e1 100644 --- a/src/tags/blockquote.ts +++ b/src/tags/blockquote.ts @@ -1,9 +1,2 @@ -import { NEWLINE } from '../utils'; - -/** - * Matches blockquote lines starting with > or >. - * Platform-agnostic newline handling. - * - * Example: > blockquote text - */ -export const REGEXP_BLOCKQUOTE = new RegExp(`${NEWLINE}(>|>)(.*)`, 'g'); +/** @example "\n> quote" */ +export const REGEXP_BLOCKQUOTE = /(?:\r\n|\r|\n)(?:>|>)(.*)/g; diff --git a/src/tags/br.ts b/src/tags/br.ts index 44b094fb..0457a490 100644 --- a/src/tags/br.ts +++ b/src/tags/br.ts @@ -1,7 +1,2 @@ -import { NEWLINE } from '../utils'; - -/** - * Matches two or more consecutive newlines (paragraph / line breaks). - * Platform-agnostic. - */ -export const REGEXP_BR = new RegExp(`((${NEWLINE}){2,})`, 'g'); +/** @example "a\n\nb" */ +export const REGEXP_BR = /(?:\r\n|\r|\n){2,}/g; diff --git a/src/tags/code.ts b/src/tags/code.ts index 4ebe11c2..f855addb 100644 --- a/src/tags/code.ts +++ b/src/tags/code.ts @@ -1,6 +1,2 @@ -/** - * Matches inline code using single backtick delimiters. - * - * Example: `code` - */ -export const REGEXP_CODE = /`(.*?)`/g; +/** @example "`code`" */ +export const REGEXP_CODE = /`(.+?)`/g; diff --git a/src/tags/del.ts b/src/tags/del.ts index 044d80d3..ca0f3807 100644 --- a/src/tags/del.ts +++ b/src/tags/del.ts @@ -1,6 +1,2 @@ -/** - * Matches strikethrough text using ~~ delimiters. - * - * Example: ~~strikethrough~~ - */ -export const REGEXP_DEL = /~~(.*?)~~/g; +/** @example "~~deleted~~" */ +export const REGEXP_DEL = /~~(.+?)~~/g; diff --git a/src/tags/empty-blockquote.ts b/src/tags/empty-blockquote.ts index 07577404..7fd2d78f 100644 --- a/src/tags/empty-blockquote.ts +++ b/src/tags/empty-blockquote.ts @@ -1,7 +1,2 @@ -/** - * Matches consecutive empty blockquote HTML tags. - * Useful for cleaning up generated HTML. - * - * Example:
          - */ +/** @example "
          " */ export const REGEXP_EMPTY_BLOCKQUOTE = /<\/blockquote>
          /g; diff --git a/src/tags/header.ts b/src/tags/header.ts index 46c81645..77440372 100644 --- a/src/tags/header.ts +++ b/src/tags/header.ts @@ -1,6 +1,8 @@ -/** ATX headers after start-of-string or a newline. */ +/** @example "\n# Title" */ export const REGEXP_HEADER = /(^|\r\n|\r|\n)(#{1,6})\s+(.*)/gm; +/** @example "## Heading" */ export const REGEXP_H2 = /^##\s+(.*)$/gim; +/** @example "### Heading" */ export const REGEXP_H3 = /^###\s+(.*)$/gim; diff --git a/src/tags/hr.ts b/src/tags/hr.ts index 962cc7d2..617addf4 100644 --- a/src/tags/hr.ts +++ b/src/tags/hr.ts @@ -1,9 +1,2 @@ -import { NEWLINE } from '../utils'; - -/** - * Matches horizontal rule lines (5 or more dashes). - * Platform-agnostic newline handling. - * - * Example: ----- - */ -export const REGEXP_HR = new RegExp(`${NEWLINE}-{5,}`, 'g'); +/** @example "\n-----" */ +export const REGEXP_HR = /(?:\r\n|\r|\n)-{5,}/g; diff --git a/src/tags/image.ts b/src/tags/image.ts index ab8483c9..5fa13cdc 100644 --- a/src/tags/image.ts +++ b/src/tags/image.ts @@ -1,8 +1,2 @@ -/** - * Matches markdown image syntax. - * Captures: [1] alt text, [2] url - */ -export const REGEXP_IMAGE = new RegExp( - '!\\[([^\\[]*?)\\]\\(([^)]+?)\\)', - 'g' -); +/** @example "![alt](https://example.com/a.png)" */ +export const REGEXP_IMAGE = /!\[([^\[]*?)\]\(([^)]+?)\)/g; diff --git a/src/tags/italic.ts b/src/tags/italic.ts index 7e806c39..4c333805 100644 --- a/src/tags/italic.ts +++ b/src/tags/italic.ts @@ -1,2 +1,2 @@ -/** Italic: *text* or _text_, with surrounding whitespace or start/end. */ +/** @example " *italic* " */ export const REGEXP_ITALIC = /(^|[\s>])(\*|_)(.+?)\2([\s<]|$)/g; diff --git a/src/tags/link.ts b/src/tags/link.ts index 5ac888f4..9aa228a5 100644 --- a/src/tags/link.ts +++ b/src/tags/link.ts @@ -1,8 +1,2 @@ -/** - * Matches markdown link syntax. - * Captures: [1] link text, [2] url - */ -export const REGEXP_LINK = new RegExp( - '\\[([^\\[]*?)\\]\\(([^)]+?)\\)', - 'g' -); +/** @example "[GitHub](https://github.com)" */ +export const REGEXP_LINK = /\[([^\[]*?)\]\(([^)]+?)\)/g; diff --git a/src/tags/paragraph.ts b/src/tags/paragraph.ts index a7991deb..247946e4 100644 --- a/src/tags/paragraph.ts +++ b/src/tags/paragraph.ts @@ -1,7 +1,2 @@ -import { NEWLINE } from '../utils'; - -/** - * Matches paragraph content between newlines. - * Platform-agnostic newline handling. - */ -export const REGEXP_PARAGRAPH = new RegExp(`${NEWLINE}(.+?)${NEWLINE}`, 'g'); +/** @example "\nhello\n" */ +export const REGEXP_PARAGRAPH = /(?:\r\n|\r|\n)(.+?)(?:\r\n|\r|\n)/g; diff --git a/src/tags/quote.ts b/src/tags/quote.ts index 030f9fd0..2e2ca876 100644 --- a/src/tags/quote.ts +++ b/src/tags/quote.ts @@ -1,7 +1,2 @@ -/** - * Matches quoted text using the non-standard :"...": syntax - * used by some email/newsletter pipelines. - * - * Example: :"quoted text": - */ +/** @example ":\"quoted\":" */ export const REGEXP_Q = /:"(.*?)":/g; diff --git a/src/tags/strong.ts b/src/tags/strong.ts index 35d9c2cb..551eb7f9 100644 --- a/src/tags/strong.ts +++ b/src/tags/strong.ts @@ -1,2 +1,2 @@ -/** Bold: **text** or __text__. */ +/** @example "**bold**" */ export const REGEXP_STRONG = /\*\*(.+?)\*\*|__(.+?)__/g; diff --git a/src/utils.ts b/src/utils.ts index e8e526c0..a54e167f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,2 @@ -/** Unix / Windows / old-Mac newline as a RegExp source fragment. */ -export const NEWLINE = String.raw`(?:\r\n|\r|\n)`; - -export function nl(pattern: string, flags = 'g'): RegExp { - return new RegExp(pattern.replace(/\n/g, NEWLINE), flags); -} +/** Newline fragment for docs / composition. Prefer literals in tag files. */ +export const NEWLINE = '(?:\r\n|\r|\n)'; From 54f816df95e77076eb2dbaeb2af9cff91ca286b1 Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:18:03 +0300 Subject: [PATCH 02/10] chore: remove hand-written src/index.d.ts (tsup emits dist types) --- src/index.d.ts | 111 ------------------------------------------------- 1 file changed, 111 deletions(-) delete mode 100644 src/index.d.ts diff --git a/src/index.d.ts b/src/index.d.ts deleted file mode 100644 index 9e1191fb..00000000 --- a/src/index.d.ts +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Matches markdown headers (lines starting with one or more # characters). - * Example: `# Heading 1`, `## Heading 2` - */ -export const REGEXP_HEADER: RegExp; - -/** - * Matches markdown level 2 headers (lines starting with exactly ##). - * Example: `## Heading 2` - */ -export const REGEXP_H2: RegExp; - -/** - * Matches markdown level 3 headers (lines starting with exactly ###). - * Example: `### Heading 3` - */ -export const REGEXP_H3: RegExp; - -/** - * Matches markdown image syntax. - * Example: `![alt text](https://example.com/image.png)` - */ -export const REGEXP_IMAGE: RegExp; - -/** - * Matches markdown link syntax. - * Example: `[link text](https://example.com)` - */ -export const REGEXP_LINK: RegExp; - -/** - * Matches bold/strong text using `**` or `__` delimiters. - * Example: `**bold**`, `__bold__` - */ -export const REGEXP_STRONG: RegExp; - -/** - * Matches strikethrough text using `~~` delimiters. - * Example: `~~strikethrough~~` - */ -export const REGEXP_DEL: RegExp; - -/** - * Matches quoted text using `::"...":` syntax. - * Example: `::"quoted text":` - */ -export const REGEXP_Q: RegExp; - -/** - * Matches inline code using backtick delimiters. - * Example: `` `code` `` - */ -export const REGEXP_CODE: RegExp; - -/** - * Matches unordered list items (lines starting with `*`). - * Example: `* list item` - */ -export const REGEXP_UL_LIST: RegExp; - -/** - * Matches ordered list items (lines starting with a number and period). - * Example: `1. list item` - */ -export const REGEXP_OL_LIST: RegExp; - -/** - * Matches blockquote lines starting with `>` or `>`. - * Example: `> blockquote text` - */ -export const REGEXP_BLOCKQUOTE: RegExp; - -/** - * Matches horizontal rule lines (5 or more dashes). - * Example: `-----` - */ -export const REGEXP_HR: RegExp; - -/** - * Matches paragraph content between newlines. - */ -export const REGEXP_PARAGRAPH: RegExp; - -/** - * Matches empty unordered list HTML tags (consecutive `
          ` pairs). - * Example: `
          ` - */ -export const REGEXP_EMPTY_UL: RegExp; - -/** - * Matches empty ordered list HTML tags (consecutive `
      ` pairs). - * Example: `
      ` - */ -export const REGEXP_EMPTY_OL: RegExp; - -/** - * Matches two or more consecutive newlines (line breaks). - */ -export const REGEXP_BR: RegExp; - -/** - * Matches consecutive empty blockquote HTML tags. - * Example: `
      ` - */ -export const REGEXP_EMPTY_BLOCKQUOTE: RegExp; - -/** - * Matches italic/emphasis text using `*` or `_` delimiters. - * Example: `*italic*`, `_italic_` - */ -export const REGEXP_EM: RegExp; From 4583176e05c27b7da32e4ca5803ac7e5942e0b5d Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:18:05 +0300 Subject: [PATCH 03/10] chore: remove JS barrel that shadowed src/tags/ --- src/tags.js | 54 ----------------------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 src/tags.js diff --git a/src/tags.js b/src/tags.js deleted file mode 100644 index 6d3ed7df..00000000 --- a/src/tags.js +++ /dev/null @@ -1,54 +0,0 @@ -import os from "os"; - -const platform = os.platform(); - -const newLine = platform === "win32" ? "\r\n" : "\n"; - -// TODO: make all regex to feel similar -const REGEXP_HEADER = new RegExp(`${newLine}(#+)(.*)`, "g"); - -const REGEXP_H3 = /^### (.*$)/gim; -const REGEXP_H2 = /^## (.*$)/gim; -// ----------- - -// TODO: make all regex to feel similar -const REGEXP_IMAGE = /!\[([^\[]+)\]\(([^\)]+)\)/g; -// TODO ADD REF PARAMETER TO URL -const REGEXP_LINK = /\[([^\[]+)\]\(([^\)]+)\)/g; -const REGEXP_STRONG = /(\*\*|__)(.*?)(\*?)\1/g; -const REGEXP_DEL = /\~\~(.*?)\~\~/g; -const REGEXP_Q = /\:\"(.*?)\"\:/g; -const REGEXP_CODE = /`(.*?)`/g; - -// ----------- -const REGEXP_BLOCKQUOTE = new RegExp(`${newLine}(>|\\>)(.*)`, "g"); -const REGEXP_HR = new RegExp(`${newLine}-{5,}`, "g"); - -const REGEXP_PARAGRAPH = new RegExp(`${newLine}(.+?)${newLine}`, "g"); - -// ----------- -const REGEXP_BR = new RegExp(`((${newLine}){2,})`, "g"); - -const REGEXP_EMPTY_BLOCKQUOTE = /<\/blockquote>
      /g; - -const REGEXP_EM = /(\s|>)(\*|_)(.*?)\2(\s|<)/g; - -export { - REGEXP_HEADER, - REGEXP_H2, - REGEXP_H3, - REGEXP_IMAGE, - REGEXP_LINK, - REGEXP_STRONG, - REGEXP_DEL, - REGEXP_Q, - REGEXP_CODE, - // ----------- - REGEXP_BLOCKQUOTE, - REGEXP_HR, - REGEXP_PARAGRAPH, - // ----------- - REGEXP_BR, - REGEXP_EMPTY_BLOCKQUOTE, - REGEXP_EM, -}; From ff9136291fbd3b5acb15ecc07084c7d6c09f501f Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:18:11 +0300 Subject: [PATCH 04/10] chore: remove JS mirror of src/index.ts --- src/index.js | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/index.js diff --git a/src/index.js b/src/index.js deleted file mode 100644 index cb398670..00000000 --- a/src/index.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Legacy CommonJS/ESM entry kept for compatibility during migration. - * Prefer the TypeScript source (src/index.ts) and the built dist/ package. - */ -export { - REGEXP_HEADER, - REGEXP_H2, - REGEXP_H3, - REGEXP_IMAGE, - REGEXP_LINK, - REGEXP_STRONG, - REGEXP_DEL, - REGEXP_Q, - REGEXP_CODE, - REGEXP_BLOCKQUOTE, - REGEXP_HR, - REGEXP_PARAGRAPH, - REGEXP_BR, - REGEXP_EMPTY_BLOCKQUOTE, - REGEXP_ITALIC, -} from './tags/index.js'; -export { - REGEXP_UL_LIST, - REGEXP_OL_LIST, - REGEXP_EMPTY_UL, - REGEXP_EMPTY_OL, -} from './lists/index.js'; From f29eaff443c5596004ff7eecdb5dd9c5c7f8bccf Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:18:14 +0300 Subject: [PATCH 05/10] chore: remove JS mirror of src/utils.ts --- src/utils.js | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/utils.js diff --git a/src/utils.js b/src/utils.js deleted file mode 100644 index 701fdc49..00000000 --- a/src/utils.js +++ /dev/null @@ -1,5 +0,0 @@ -import os from "os"; - -const platform = os.platform(); - -export const newLine = platform === "win32" ? "\r\n" : "\n"; From 41c7efb239e9189ffabb0531dff320c9c9947673 Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:18:17 +0300 Subject: [PATCH 06/10] chore: remove leftover src/list.js --- src/list.js | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/list.js diff --git a/src/list.js b/src/list.js deleted file mode 100644 index 24ce1693..00000000 --- a/src/list.js +++ /dev/null @@ -1,23 +0,0 @@ -import os from "os"; - -const platform = os.platform(); - -const newLine = platform === "win32" ? "\r\n" : "\n"; - -const REGEXP_UL_LIST = new RegExp( - `${newLine}(((\\s{4})?\\*(.*?)${newLine}){1,})`, - "g" -); -const REGEXP_OL_LIST = new RegExp(`${newLine}[0-9]+\\.(.*)`, "g"); - -// @TODO make all regEx the same style -const REGEXP_EMPTY_UL = /<\/ul>\s?
        /g; -const REGEXP_EMPTY_OL = /<\/ol>\s?
          /g; - -export { - REGEXP_UL_LIST, - REGEXP_OL_LIST, - // ----------- - REGEXP_EMPTY_UL, - REGEXP_EMPTY_OL, -}; From ae1950a14d13a1fa20f25838f2bdba6fae308f00 Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:18:20 +0300 Subject: [PATCH 07/10] chore: remove src/tags/index.js --- src/tags/index.js | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/tags/index.js diff --git a/src/tags/index.js b/src/tags/index.js deleted file mode 100644 index b5df3a92..00000000 --- a/src/tags/index.js +++ /dev/null @@ -1,13 +0,0 @@ -export { REGEXP_HEADER, REGEXP_H2, REGEXP_H3 } from './header.js'; -export { REGEXP_BLOCKQUOTE } from './blockquote.js'; -export { REGEXP_CODE } from './code.js'; -export { REGEXP_LINK } from './link.js'; -export { REGEXP_IMAGE } from './image.js'; -export { REGEXP_STRONG } from './strong.js'; -export { REGEXP_DEL } from './del.js'; -export { REGEXP_ITALIC } from './italic.js'; -export { REGEXP_HR } from './hr.js'; -export { REGEXP_BR } from './br.js'; -export { REGEXP_PARAGRAPH } from './paragraph.js'; -export { REGEXP_Q } from './quote.js'; -export { REGEXP_EMPTY_BLOCKQUOTE } from './empty-blockquote.js'; From 6fa32c2a0f95fa46972743c1e37eb0afd342ec65 Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:18:26 +0300 Subject: [PATCH 08/10] chore: remove leftover em.ts (replaced by italic) --- src/tags/em.ts | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/tags/em.ts diff --git a/src/tags/em.ts b/src/tags/em.ts deleted file mode 100644 index 6f5927f5..00000000 --- a/src/tags/em.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @deprecated Removed. Use REGEXP_ITALIC from './italic' instead. - * This file only exists so accidental imports fail clearly at review time. - * Delete this file after the hygiene pass (`git rm src/tags/em.ts`). - */ -export { REGEXP_ITALIC as REGEXP_ITALIC_ONLY } from './italic'; From 676f39bdf0af72bdd484403b03e6c271ca0ad191 Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:18:33 +0300 Subject: [PATCH 09/10] chore: remove leftover em.js --- src/tags/em.js | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/tags/em.js diff --git a/src/tags/em.js b/src/tags/em.js deleted file mode 100644 index 90999a59..00000000 --- a/src/tags/em.js +++ /dev/null @@ -1,4 +0,0 @@ -/** - * @deprecated Use REGEXP_ITALIC from './italic.js'. Delete this file. - */ -export { REGEXP_ITALIC as REGEXP_ITALIC_ONLY } from './italic.js'; From 5938a12c152a6ba737a2b30aece95202a443570f Mon Sep 17 00:00:00 2001 From: Arthur Tkachenko Date: Sun, 13 Sep 2026 04:25:01 +0300 Subject: [PATCH 10/10] docs: restore fuller JSDoc on regex exports --- src/index.ts | 6 +++--- src/lists/empty-ol.ts | 8 +++++++- src/lists/empty-ul.ts | 8 +++++++- src/lists/ol.ts | 6 +++++- src/lists/ul.ts | 9 ++++++++- src/tags/blockquote.ts | 7 ++++++- src/tags/br.ts | 7 ++++++- src/tags/code.ts | 6 +++++- src/tags/del.ts | 6 +++++- src/tags/empty-blockquote.ts | 7 ++++++- src/tags/header.ts | 24 +++++++++++++++++++++--- src/tags/hr.ts | 6 +++++- src/tags/image.ts | 7 ++++++- src/tags/italic.ts | 9 ++++++++- src/tags/link.ts | 7 ++++++- src/tags/paragraph.ts | 6 +++++- src/tags/quote.ts | 6 +++++- src/tags/strong.ts | 8 +++++++- src/utils.ts | 6 +++++- 19 files changed, 126 insertions(+), 23 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6c4bba28..76b27622 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,10 @@ /** * markdown-regex * - * A set of ready-to-use RegExp constants for parsing and extracting - * elements from Markdown content. - * + * Ready-to-use RegExp constants for parsing Markdown. * Zero runtime dependencies. Works in Node, browsers, and bundlers. + * + * @packageDocumentation */ export { diff --git a/src/lists/empty-ol.ts b/src/lists/empty-ol.ts index 39afb48f..c1333ac8 100644 --- a/src/lists/empty-ol.ts +++ b/src/lists/empty-ol.ts @@ -1,2 +1,8 @@ -/** @example "
          " */ +/** + * Matches consecutive empty ordered-list HTML tags. + * Useful when cleaning generated HTML. + * + * @example
          + * @example
          + */ export const REGEXP_EMPTY_OL = /<\/ol>\s?
            /g; diff --git a/src/lists/empty-ul.ts b/src/lists/empty-ul.ts index 213778ba..54aa3e00 100644 --- a/src/lists/empty-ul.ts +++ b/src/lists/empty-ul.ts @@ -1,2 +1,8 @@ -/** @example "
        " */ +/** + * Matches consecutive empty unordered-list HTML tags. + * Useful when cleaning generated HTML. + * + * @example
        + * @example
        + */ export const REGEXP_EMPTY_UL = /<\/ul>\s?
          /g; diff --git a/src/lists/ol.ts b/src/lists/ol.ts index 2e0a0e4b..90168dd9 100644 --- a/src/lists/ol.ts +++ b/src/lists/ol.ts @@ -1,2 +1,6 @@ -/** @example "\n1. item" */ +/** + * Matches an ordered list item (number + period after a newline). + * + * @example 1. first item + */ export const REGEXP_OL_LIST = /(?:\r\n|\r|\n)\d+\.(.*)/g; diff --git a/src/lists/ul.ts b/src/lists/ul.ts index fa7233ed..d122d588 100644 --- a/src/lists/ul.ts +++ b/src/lists/ul.ts @@ -1,2 +1,9 @@ -/** @example "\n* item\n" */ +/** + * Matches an unordered list item (`*` after a newline). + * Optional 4-space indent is allowed. + * + * @example + * * item one + * * item two + */ export const REGEXP_UL_LIST = /(?:\r\n|\r|\n)(?:\s{4})?\*(.*)/g; diff --git a/src/tags/blockquote.ts b/src/tags/blockquote.ts index dc37f3e1..75a06932 100644 --- a/src/tags/blockquote.ts +++ b/src/tags/blockquote.ts @@ -1,2 +1,7 @@ -/** @example "\n> quote" */ +/** + * Matches blockquote lines starting with `>` or `>` after a newline. + * + * @example + * > quoted paragraph + */ export const REGEXP_BLOCKQUOTE = /(?:\r\n|\r|\n)(?:>|>)(.*)/g; diff --git a/src/tags/br.ts b/src/tags/br.ts index 0457a490..ebdb338b 100644 --- a/src/tags/br.ts +++ b/src/tags/br.ts @@ -1,2 +1,7 @@ -/** @example "a\n\nb" */ +/** + * Matches two or more consecutive newlines (paragraph / line breaks). + * Understands `\n`, `\r\n` and `\r`. + * + * @example a\\n\\nb + */ export const REGEXP_BR = /(?:\r\n|\r|\n){2,}/g; diff --git a/src/tags/code.ts b/src/tags/code.ts index f855addb..994b652d 100644 --- a/src/tags/code.ts +++ b/src/tags/code.ts @@ -1,2 +1,6 @@ -/** @example "`code`" */ +/** + * Matches inline code using single backtick delimiters. + * + * @example `code` + */ export const REGEXP_CODE = /`(.+?)`/g; diff --git a/src/tags/del.ts b/src/tags/del.ts index ca0f3807..f96b6314 100644 --- a/src/tags/del.ts +++ b/src/tags/del.ts @@ -1,2 +1,6 @@ -/** @example "~~deleted~~" */ +/** + * Matches strikethrough text using `~~` delimiters. + * + * @example ~~deleted~~ + */ export const REGEXP_DEL = /~~(.+?)~~/g; diff --git a/src/tags/empty-blockquote.ts b/src/tags/empty-blockquote.ts index 7fd2d78f..1fc41255 100644 --- a/src/tags/empty-blockquote.ts +++ b/src/tags/empty-blockquote.ts @@ -1,2 +1,7 @@ -/** @example "
      " */ +/** + * Matches consecutive empty blockquote HTML tags. + * Useful when cleaning generated HTML. + * + * @example
      + */ export const REGEXP_EMPTY_BLOCKQUOTE = /<\/blockquote>
      /g; diff --git a/src/tags/header.ts b/src/tags/header.ts index 77440372..985935ae 100644 --- a/src/tags/header.ts +++ b/src/tags/header.ts @@ -1,8 +1,26 @@ -/** @example "\n# Title" */ +/** + * Matches ATX markdown headers (lines starting with 1–6 `#` characters). + * Matches at the start of the string or after a newline (Unix / Windows / old Mac). + * + * Captures: [1] the newline or start, [2] the `#` run, [3] the heading text. + * + * @example + * # Heading 1 + * ## Heading 2 + * ### Heading 3 + */ export const REGEXP_HEADER = /(^|\r\n|\r|\n)(#{1,6})\s+(.*)/gm; -/** @example "## Heading" */ +/** + * Matches level-2 headers only (`## …`). + * + * @example ## Heading 2 + */ export const REGEXP_H2 = /^##\s+(.*)$/gim; -/** @example "### Heading" */ +/** + * Matches level-3 headers only (`### …`). + * + * @example ### Heading 3 + */ export const REGEXP_H3 = /^###\s+(.*)$/gim; diff --git a/src/tags/hr.ts b/src/tags/hr.ts index 617addf4..3c4420ef 100644 --- a/src/tags/hr.ts +++ b/src/tags/hr.ts @@ -1,2 +1,6 @@ -/** @example "\n-----" */ +/** + * Matches a horizontal rule: 5 or more dashes on their own line. + * + * @example -----\n + */ export const REGEXP_HR = /(?:\r\n|\r|\n)-{5,}/g; diff --git a/src/tags/image.ts b/src/tags/image.ts index 5fa13cdc..bfc49d4c 100644 --- a/src/tags/image.ts +++ b/src/tags/image.ts @@ -1,2 +1,7 @@ -/** @example "![alt](https://example.com/a.png)" */ +/** + * Matches markdown image syntax. + * Captures: [1] alt text, [2] url. + * + * @example ![alt text](https://example.com/image.png) + */ export const REGEXP_IMAGE = /!\[([^\[]*?)\]\(([^)]+?)\)/g; diff --git a/src/tags/italic.ts b/src/tags/italic.ts index 4c333805..e0dc7fe9 100644 --- a/src/tags/italic.ts +++ b/src/tags/italic.ts @@ -1,2 +1,9 @@ -/** @example " *italic* " */ +/** + * Matches italic/emphasis using `*` or `_` delimiters. + * Requires surrounding whitespace (or start/end / `>` / `<`) so that + * mid-word underscores are less likely to match. + * + * @example *italic* + * @example _italic_ + */ export const REGEXP_ITALIC = /(^|[\s>])(\*|_)(.+?)\2([\s<]|$)/g; diff --git a/src/tags/link.ts b/src/tags/link.ts index 9aa228a5..976ac1a6 100644 --- a/src/tags/link.ts +++ b/src/tags/link.ts @@ -1,2 +1,7 @@ -/** @example "[GitHub](https://github.com)" */ +/** + * Matches markdown link syntax. + * Captures: [1] link text, [2] url. + * + * @example [GitHub](https://github.com) + */ export const REGEXP_LINK = /\[([^\[]*?)\]\(([^)]+?)\)/g; diff --git a/src/tags/paragraph.ts b/src/tags/paragraph.ts index 247946e4..cce1d156 100644 --- a/src/tags/paragraph.ts +++ b/src/tags/paragraph.ts @@ -1,2 +1,6 @@ -/** @example "\nhello\n" */ +/** + * Matches paragraph-like content sitting between two newlines. + * + * @example \\nhello world\\n + */ export const REGEXP_PARAGRAPH = /(?:\r\n|\r|\n)(.+?)(?:\r\n|\r|\n)/g; diff --git a/src/tags/quote.ts b/src/tags/quote.ts index 2e2ca876..8b3bf5ed 100644 --- a/src/tags/quote.ts +++ b/src/tags/quote.ts @@ -1,2 +1,6 @@ -/** @example ":\"quoted\":" */ +/** + * Matches the custom quote syntax used in some newsletter pipelines. + * + * @example :"quoted text": + */ export const REGEXP_Q = /:"(.*?)":/g; diff --git a/src/tags/strong.ts b/src/tags/strong.ts index 551eb7f9..301628f4 100644 --- a/src/tags/strong.ts +++ b/src/tags/strong.ts @@ -1,2 +1,8 @@ -/** @example "**bold**" */ +/** + * Matches bold/strong text using `**` or `__` delimiters. + * Captures the inner text in group 1 (`**`) or group 2 (`__`). + * + * @example **bold** + * @example __bold__ + */ export const REGEXP_STRONG = /\*\*(.+?)\*\*|__(.+?)__/g; diff --git a/src/utils.ts b/src/utils.ts index a54e167f..03994d19 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,2 +1,6 @@ -/** Newline fragment for docs / composition. Prefer literals in tag files. */ +/** + * Flexible newline fragment: Unix (`\n`), Windows (`\r\n`), old Mac (`\r`). + * Prefer embedding `(?:\r\n|\r|\n)` directly in regex literals. + * This constant is kept for callers that compose patterns at runtime. + */ export const NEWLINE = '(?:\r\n|\r|\n)';