Fix broken markdown formatting by moving punctuation outside bold/italic text and removing incomplete image markdown during streaming
npm install unbroken-markdownFix broken markdown during streaming to ensure proper rendering. This package intelligently moves punctuation marks outside of bold/italic markers and handles incomplete markdown patterns during streaming.
When markdown is streamed or improperly formatted, you might see broken rendering like:
- "text" → "text" (quotes outside bold)
- text(info) → text(info) (parentheses outside italic)
- 50% → 50% (percentage outside bold)
- → <text> (angle brackets outside bold)
- 『책 제목』 → 『책 제목』 (Korean quotation marks)
- Incomplete image markdown removal during streaming
``bash`
npm install unbroken-markdownor
yarn add unbroken-markdownor
bun add unbroken-markdown
`typescript
import { unbreak } from 'unbroken-markdown';
const input = '"Hello (world)"';
const output = unbreak(input);
console.log(output); // "Hello (world)"
// Works with italic too
const italicInput = 'text(info)';
const italicOutput = unbreak(italicInput);
console.log(italicOutput); // text(info)
`
- Quotes: "text" → "text"text(info)
- Parentheses: → text(info)50%
- Percentages: → 50%text
- Links: → text
- Angle brackets: → <text>『text』
- Korean brackets: → 『text』, 「text」 → 「text」, 《text》 → 《text》, 〈text〉 → 〈text〉
- Quotes: "text" → "text"text(info)
- Parentheses: → text(info)50%
- Percentages: → 50%text
- Links: → text
- Angle brackets: → <text>『text』
- Korean brackets: → 『text』, 「text」 → 「text」, 《text》 → 《text》, 〈text〉 → 〈text〉
- Removes incomplete image markdown patterns
- Handles partial markdown during real-time streaming
- Ensures consistent rendering even with interrupted markdown
The main function that processes and fixes broken markdown text.
Parameters:
- markdown - The markdown string to process
Returns:
- Unbroken and properly formatted markdown string
`typescript`
const input = 'AI "innovative (breakthrough)" technology';
const output = unbreak(input);
// Output: AI "innovative (breakthrough)" technology
`typescript`
const input = 'Bold (text) and Italic (text)';
const output = unbreak(input);
// Output: Bold (text) and Italic (text)
`typescript`
const input = "'Church of Light' mentioned";
const output = unbreak(input);
// Output: 'Church of Light' mentioned
`typescript``
const input = '『책의 제목』을 표기할 때 사용해요.';
const output = unbreak(input);
// Output: 『책의 제목』을 표기할 때 사용해요.
Perfect for:
- Real-time markdown streaming applications
- Chat applications with markdown support
- Content management systems
- Markdown editors with live preview
- AI-generated content processing
MIT
Issues and pull requests are welcome at GitHub repository.