Commit 7cf63fd
authored
feat(md, config): Implement streaming markdown rendering (#399)
Introduce the `jp_md` crate to handle progressive rendering of
CommonMark content from LLM streams. This implementation solves the
latency issues associated with waiting for a full response before
displaying formatted output.
The core of this change is the `Buffer` utility, which segments incoming
text chunks into complete markdown blocks based on CommonMark grammar.
This allows for immediate rendering of paragraphs, headers, and lists as
they are completed. Fenced code blocks are handled with line-by-line
granularity to enable real-time syntax highlighting.
A custom `TerminalFormatter` replaces standard rendering to ensure
ANSI-aware line wrapping. Unlike generic formatters, it correctly
calculates visual column widths by excluding escape sequences and
manages SGR state across line breaks to prevent background color bleed.
Users can now configure their rendering preferences via the new
`style.markdown` configuration section:
```toml
[style.markdown]
wrap_width = 80
table_max_column_width = 40
theme = "gruvbox-dark"
hr_style = "line"
```
The architectural decisions and trade-offs for this implementation are
documented in RFD 004.
NOTE: This change has NOT been wired up to the CLI yet. This will happen
in a follow-up PR.
---------
Signed-off-by: Jean Mertz <git@jeanmertz.com>1 parent f090bfa commit 7cf63fd
File tree
119 files changed
+6892
-27
lines changed- .config/supply-chain
- crates
- jp_cli
- jp_config/src
- snapshots
- style
- jp_conversation/src/snapshots
- jp_llm/tests/fixtures
- anthropic
- google
- llamacpp
- ollama
- openai
- openrouter
- jp_md
- src
- buffer
- tests
- fixtures
- snapshots
- jp_term
- docs/rfd
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
119 files changed
+6892
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
4 | 24 | | |
5 | 25 | | |
6 | 26 | | |
| |||
11 | 31 | | |
12 | 32 | | |
13 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
14 | 44 | | |
15 | 45 | | |
16 | 46 | | |
| |||
365 | 395 | | |
366 | 396 | | |
367 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
368 | 422 | | |
369 | 423 | | |
370 | 424 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
590 | 590 | | |
591 | 591 | | |
592 | 592 | | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
593 | 597 | | |
594 | 598 | | |
595 | 599 | | |
| |||
File renamed without changes.
Lines changed: 36 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
392 | 420 | | |
393 | 421 | | |
394 | 422 | | |
| |||
670 | 698 | | |
671 | 699 | | |
672 | 700 | | |
673 | | - | |
674 | | - | |
| 701 | + | |
| 702 | + | |
675 | 703 | | |
676 | 704 | | |
677 | 705 | | |
| |||
3536 | 3564 | | |
3537 | 3565 | | |
3538 | 3566 | | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
3539 | 3573 | | |
3540 | 3574 | | |
3541 | 3575 | | |
| |||
0 commit comments