Skip to content

Commit f5ffab9

Browse files
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 #69
1 parent a81c156 commit f5ffab9

File tree

8 files changed

+857
-198
lines changed

8 files changed

+857
-198
lines changed

Cargo.lock

Lines changed: 269 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ repository = "https://github.com/bug-ops/zeph"
1212

1313
[workspace.dependencies]
1414
anyhow = "1.0"
15+
criterion = "0.8"
1516
eventsource-stream = "0.2"
1617
futures-core = "0.3"
1718
ollama-rs = { version = "0.3", default-features = false, features = ["rustls", "stream"] }
19+
pulldown-cmark = "0.13"
1820
qdrant-client = { version = "1.16", default-features = false }
1921
reqwest = { version = "0.13", default-features = false }
2022
serde = "1.0"

0 commit comments

Comments
 (0)