https://github.com/xissy/unbroken-markdown
https://github.com/xissy/unbroken-markdown
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/xissy/unbroken-markdown
- Owner: xissy
- License: mit
- Created: 2025-08-22T08:59:15.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-29T23:34:27.000Z (10 months ago)
- Last Synced: 2025-08-30T01:19:04.789Z (10 months ago)
- Language: TypeScript
- Size: 43.9 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unbroken-markdown
Fix 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.
## What it does
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
## Installation
```bash
npm install unbroken-markdown
# or
yarn add unbroken-markdown
# or
bun add unbroken-markdown
```
## Usage
```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)
```
## Features
### Bold Pattern Fixes
- Quotes: `**"text"**` → `"**text**"`
- Parentheses: `**text(info)**` → `**text**(info)`
- Percentages: `**50%**` → `**50**%`
- Links: `**[text](url)**` → `[**text**](url)`
- Angle brackets: `****` → `<**text**>`
- Korean brackets: `**『text』**` → `『**text**』`, `**「text」**` → `「**text**」`, `**《text》**` → `《**text**》`, `**〈text〉**` → `〈**text**〉`
### Italic Pattern Fixes
- Quotes: `*"text"*` → `"*text*"`
- Parentheses: `*text(info)*` → `*text*(info)`
- Percentages: `*50%*` → `*50*%`
- Links: `*[text](url)*` → `[*text*](url)`
- Angle brackets: `**` → `<*text*>`
- Korean brackets: `*『text』*` → `『*text*』`, `*「text」*` → `「*text*」`, `*《text》*` → `《*text*》`, `*〈text〉*` → `〈*text*〉`
### Streaming Support
- Removes incomplete image markdown patterns
- Handles partial markdown during real-time streaming
- Ensures consistent rendering even with interrupted markdown
## API
### `unbreak(markdown: string): string`
The main function that processes and fixes broken markdown text.
**Parameters:**
- `markdown` - The markdown string to process
**Returns:**
- Unbroken and properly formatted markdown string
## Examples
### Complex nested patterns
```typescript
const input = '**AI "innovative (breakthrough)" technology**';
const output = unbreak(input);
// Output: AI "**innovative** (breakthrough)" technology
```
### Mixed bold and italic
```typescript
const input = '**Bold (text)** and *Italic (text)*';
const output = unbreak(input);
// Output: **Bold** (text) and *Italic* (text)
```
### Text with quotes
```typescript
const input = "**'Church of Light'** mentioned";
const output = unbreak(input);
// Output: '**Church of Light**' mentioned
```
### Korean quotation marks
```typescript
const input = '**『책의 제목』**을 표기할 때 사용해요.';
const output = unbreak(input);
// Output: 『**책의 제목**』을 표기할 때 사용해요.
```
## Use Cases
Perfect for:
- Real-time markdown streaming applications
- Chat applications with markdown support
- Content management systems
- Markdown editors with live preview
- AI-generated content processing
## License
MIT
## Contributing
Issues and pull requests are welcome at [GitHub repository](https://github.com/xissy/unbroken-markdown).