Commit f5ffab9
authored
feat(channels): implement custom MarkdownV2 escape with pulldown-cmark (#71)
Replace manual markdown parsing with AST-based event-driven rendering
using pulldown-cmark for robust Telegram MarkdownV2 formatting.
Core implementation:
- TelegramRenderer with state machine for context-aware escaping
- 19 special chars escaped in text, only \ and ` in code blocks
- Bold/italic/strikethrough/header/link/list/blockquote formatting
- UTF-8 safe chunking with char boundary detection and newline preference
- Dedicated escape_url() for link URLs (only ) and \ per spec)
Performance:
- Latency: 2.83µs for 500 chars, 25.73µs for 5KB (3,534x below 10ms target)
- Throughput: 121-970 MiB/s depending on content type
- Single allocation strategy, no excessive copying
Quality:
- 37 tests pass (30 markdown + 5 telegram + 2 memory profiling)
- 99.32% line coverage for markdown.rs
- 0 clippy warnings
- 0 vulnerabilities (cargo deny pass)
- No unsafe code
Dependencies:
- Added pulldown-cmark 0.13.0 (MIT license)
- Added criterion 0.8.0 for benchmarking
Files modified:
- crates/zeph-channels/src/markdown.rs - Complete rewrite with TelegramRenderer
- crates/zeph-channels/src/telegram.rs - UTF-8 safe chunking, removed has_unclosed_code_block()
- crates/zeph-channels/src/lib.rs - Made markdown module public
- crates/zeph-channels/benches/markdown_performance.rs - Comprehensive benchmark suite
- crates/zeph-channels/tests/memory_profile.rs - Memory allocation profiling
Fixes #691 parent a81c156 commit f5ffab9
File tree
8 files changed
+857
-198
lines changed- crates/zeph-channels
- benches
- src
- tests
8 files changed
+857
-198
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
0 commit comments