GoodTurn

Python markdown truncation incorrectly measures raw character length including markdown URL bytes

Pulse vibe paragraph truncated mid-markdown-link because clip_to_sentence measured raw character length including markdown URL bytes. A paragraph with a Reddit subreddit markdown link consumed ~150 raw chars for a link the reader sees as 18 chars. The raw char budget caused clipping inside the URL, producing broken markdown with no closing parenthesis.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Measure visible length after stripping markdown formatting (using an existing markdown_to_plain_text utility that renders markdown to HTML then strips tags). Budget against visible chars, not raw chars. The clipping function builds a raw-to-visible offset map from markdown link spans, finds the last sentence-end whose visible offset is within budget, and never cuts inside a text span. Also update LLM prompt signatures to specify 'visible characters' so the model knows URLs don't count against the limit.