Skip to content

refactor(tui): clean markdown.tsx per KISS/DRY#13719

Merged
OutThisLife merged 1 commit into
mainfrom
bb/tui-markdown-cleanup
Apr 21, 2026
Merged

refactor(tui): clean markdown.tsx per KISS/DRY#13719
OutThisLife merged 1 commit into
mainfrom
bb/tui-markdown-cleanup

Conversation

@OutThisLife

@OutThisLife OutThisLife commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Stacks on top of #13715 — merge that first, then this rebases to just the cleanup commit.

Pure refactor of markdown.tsx per KISS/DRY house rules. The file had accumulated shapes that violate our rules:

  • INLINE_RE was a single ~500-char escaped string with an outer no-op capture group — so the 17 inner groups were indexed m[2]-m[17] instead of m[1]-m[16], and the alternatives weren't individually readable.
  • Single-use helpers (parseFence, isFenceClose, isMarkdownFence, trimBareUrl) added indirection without meaningful naming wins.
  • Intermediate variables (path, raw, lang, depth, body, task body, setext match, etc.) were bound once and used once.
  • Duplicate branches for !line.trim() under compact vs normal flow.
  • Block-level regexes (setext, bullet, task, numbered, quote, fence-close) were inline literals inside the hot while loop — compiled fresh per line.
  • Types (Fence, MdProps) were at the top instead of at the bottom.

Changes

  • INLINE_RE source → ordered array of patterns with // 1,2 image / // 3,4 link / … comments mapping to capture indices. Outer wrapping group removed.
  • MdInline capture-group references shifted -1 (m[1]–m[16]).
  • Inline parseFence / isFenceClose / isMarkdownFence / trimBareUrl.
  • Hoist block regexes: FENCE_CLOSE_RE, SETEXT_RE, BULLET_RE, TASK_RE, NUMBERED_RE, QUOTE_RE.
  • Collapse duplicate blank-line branches.
  • Promote Fence to a local Kind union. Move types to the bottom.
  • Rename splitTableRowsplitRow (it's not specific to tables).
  • Use optional chaining (?.[1], ?.[2]) on match results where we only want one capture.

Test plan

Net for this commit alone: -22 LoC, same behavior.

- Drop the outer no-op capture group from INLINE_RE and restructure the
  source as an ordered list of patterns-with-index-comments so each
  alternative is individually greppable. Shift group indices in MdInline
  down by one accordingly.
- Inline single-use helpers (parseFence, isFenceClose, isMarkdownFence,
  trimBareUrl) and intermediate variables (path, lang, raw, prefix, body,
  depth, task body, setext match, etc.).
- Hoist block-level regexes used inside MdImpl (FENCE_CLOSE_RE, SETEXT_RE,
  BULLET_RE, TASK_RE, NUMBERED_RE, QUOTE_RE) to top-level consts so
  they're compiled once instead of per-line.
- Collapse the duplicate compact-vs-normal blank-line branches into one
  if/!compact gap call.
- Move Fence and MdProps types to the bottom per house style.
- Shorten splitTableRow → splitRow and use optional chaining in a few
  match sites.

No behavior change; 162/162 tests pass. Net -22 LoC.
@OutThisLife OutThisLife force-pushed the bb/tui-markdown-cleanup branch from fa76afb to b97b4c4 Compare April 21, 2026 23:11
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Apr 21, 2026
@OutThisLife OutThisLife changed the base branch from main to bb/tui-markdown-tilde-subscript April 21, 2026 23:12
Base automatically changed from bb/tui-markdown-tilde-subscript to main April 21, 2026 23:13
@OutThisLife OutThisLife merged commit 35a4b09 into main Apr 21, 2026
9 of 10 checks passed
@OutThisLife OutThisLife deleted the bb/tui-markdown-cleanup branch April 21, 2026 23:13
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…wn-cleanup

refactor(tui): clean markdown.tsx per KISS/DRY
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…wn-cleanup

refactor(tui): clean markdown.tsx per KISS/DRY
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…wn-cleanup

refactor(tui): clean markdown.tsx per KISS/DRY
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…wn-cleanup

refactor(tui): clean markdown.tsx per KISS/DRY
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…wn-cleanup

refactor(tui): clean markdown.tsx per KISS/DRY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants