npm.io
2.1.528 • Published 9h ago

@djangocfg/ui-utils

Licence
MIT
Version
2.1.528
Deps
4
Size
11 kB
Vulns
0
Weekly
0

@djangocfg/ui-utils

Framework-agnostic text utilities for the DjangoCFG UI packages. No React, no DOM — safe to import anywhere, including a worker or a test.

Why this package exists

Markdown → plain text was being re-implemented per surface with regexes. Those did not merely miss constructs, they edited the user's text (all measured):

input regex result correct
file_name_here.txt filenamehere.txt file_name_here.txt
5 * 3 = 15 5 3 = 15 5 * 3 = 15
```js\nconst x = 1\n``` js const x = 1 const x = 1

Parsing with the real CommonMark + GFM stack is both correct and shorter. It lives in its own package so ui-core (Radix, charts) does not gain a markdown parser, and so any package can depend on it without a cycle.

Usage

import { stripMarkdown, plainTextLine } from '@djangocfg/ui-utils/markdown';

stripMarkdown('**Done**: see `src/x.ts`');   // "Done: see src/x.ts"
plainTextLine('# Title\n\nbody');            // "Title"

Which one:

  • stripMarkdown — a PREVIEW. All the text, one line. Every word counts, so GFM task state is re-emitted as / (dropping the box would claim an unfinished item is done).
  • plainTextLine — a NAME (row title, chip, search hit). The first block that carries words; '' when nothing is renderable, so the caller can show its own placeholder rather than punctuation. Task marks are off — the surface draws completion itself.

Both are total: a parser failure falls back to the raw text rather than returning '', because a blank label loses the message entirely.