लक्ष्य
- संगति: एक parse चरण, कई renderers।
- सुरक्षित chunking: rendering से पहले टेक्स्ट को विभाजित करें ताकि inline formatting कभी chunks के बीच न टूटे।
- चैनल अनुकूलता: उसी IR को Markdown दोबारा parse किए बिना Slack mrkdwn, Telegram HTML, और Signal style ranges में मैप करें।
Pipeline
- Markdown parse करें -> IR
- IR plain text और style spans (bold/italic/strike/code/spoiler) तथा link spans है।
- Offsets UTF-16 code units हैं ताकि Signal style ranges उसके API के साथ संरेखित रहें।
- Tables केवल तब parse की जाती हैं जब कोई चैनल table conversion चुनता है।
- IR chunk करें (format-first)
- Chunking rendering से पहले IR text पर होती है।
- Inline formatting chunks के बीच split नहीं होती; spans हर chunk के अनुसार slice किए जाते हैं।
- प्रति चैनल render करें
- Slack: mrkdwn tokens (bold/italic/strike/code), links
<url|label>के रूप में। - Telegram: HTML tags (
<b>,<i>,<s>,<code>,<pre><code>,<a href>)। - Signal: plain text +
text-styleranges; label अलग होने पर linkslabel (url)बन जाते हैं।
- Slack: mrkdwn tokens (bold/italic/strike/code), links
IR उदाहरण
Input Markdown:यह कहाँ उपयोग होता है
- Slack, Telegram, और Signal आउटबाउंड adapters IR से render करते हैं।
- अन्य चैनल (WhatsApp, iMessage, Microsoft Teams, Discord) अभी भी plain text या अपने formatting rules का उपयोग करते हैं, और enabled होने पर chunking से पहले Markdown table conversion लागू होता है।
Table handling
Markdown tables सभी chat clients में समान रूप से समर्थित नहीं हैं। प्रति चैनल (और प्रति account) conversion नियंत्रित करने के लिएmarkdown.tables का उपयोग करें।
code: tables को code blocks के रूप में render करें (अधिकांश चैनलों के लिए default)।bullets: हर row को bullet points में बदलें (Matrix, Signal, और WhatsApp के लिए default)।off: table parsing और conversion बंद करें; raw table text वैसा ही गुजरता है।
Chunking rules
- Chunk limits channel adapters/config से आते हैं और IR text पर लागू होते हैं।
- Code fences को trailing newline के साथ single block के रूप में संरक्षित रखा जाता है ताकि चैनल उन्हें सही ढंग से render करें।
- List prefixes और blockquote prefixes IR text का हिस्सा हैं, इसलिए chunking mid-prefix split नहीं करती।
- Inline styles (bold/italic/strike/inline-code/spoiler) chunks के बीच कभी split नहीं होतीं; renderer हर chunk के अंदर styles दोबारा खोलता है।
Link policy
- Slack:
[label](url)-><url|label>; bare URLs bare ही रहते हैं। Double-linking से बचने के लिए parse के दौरान Autolink disabled रहता है। - Telegram:
[label](url)-><a href="url">label</a>(HTML parse mode)। - Signal:
[label](url)->label (url)जब तक label URL से match न करे।
Spoilers
Spoiler markers (||spoiler||) केवल Signal के लिए parse किए जाते हैं, जहाँ वे
SPOILER style ranges में map होते हैं। अन्य चैनल उन्हें plain text मानते हैं।
Channel formatter कैसे जोड़ें या update करें
- एक बार parse करें: channel-appropriate
options (autolink, heading style, blockquote prefix) के साथ साझा
markdownToIR(...)helper का उपयोग करें। - Render करें:
renderMarkdownWithMarkers(...)और style marker map (या Signal style ranges) के साथ renderer implement करें। - Chunk करें: rendering से पहले
chunkMarkdownIR(...)call करें; हर chunk को render करें। - Adapter wire करें: नए chunker और renderer का उपयोग करने के लिए channel outbound adapter update करें।
- Test करें: अगर चैनल chunking का उपयोग करता है तो format tests और outbound delivery test add या update करें।
Common gotchas
- Slack angle-bracket tokens (
<@U123>,<#C123>,<https://...>) को संरक्षित रखना चाहिए; raw HTML को सुरक्षित रूप से escape करें। - Telegram HTML में broken markup से बचने के लिए tags के बाहर text escape करना आवश्यक है।
- Signal style ranges UTF-16 offsets पर निर्भर करती हैं; code point offsets का उपयोग न करें।
- Fenced code blocks के लिए trailing newlines संरक्षित रखें ताकि closing markers अपनी ही line पर रहें।
Related
Streaming and chunking
आउटबाउंड streaming behavior, chunk boundaries, और channel-specific delivery।
System prompt
Conversation से पहले model क्या देखता है, जिसमें injected workspace files शामिल हैं।