chiark / gitweb /
Split media URLs at w-1 chars, not w.
authorSimon Tatham <anakin@pobox.com>
Fri, 5 Jan 2024 12:57:43 +0000 (12:57 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 5 Jan 2024 12:57:43 +0000 (12:57 +0000)
This makes no real difference, but now they match the URLs in the text
of posts. In the Python version both split at w, but now that I'm
delegating HTML processing to html2text, that splits overlong words at
the same width it wraps sensible lines to. So I have to either have
them inconsistent or change the media one.

w-1 is more 'Mono' anyway, let's be honest :-)

src/text.rs

index fde9cdc6c691ea62e90fe5e0a9869fddae3882ba..0337d3dcba4bcae2b2c4561f449a2c1a1daaf595 100644 (file)
@@ -1252,7 +1252,8 @@ impl TextFragment for Media {
     fn render_highlighted(&self, width: usize, _highlight: Option<Highlight>)
                           -> Vec<ColouredString>
     {
-        let mut lines = vec! { ColouredString::uniform(&self.url, 'M') };
+        let mut lines: Vec<_> = ColouredString::uniform(&self.url, 'M')
+            .split(width.saturating_sub(1)).map(|x| x.to_owned()).collect();
         for para in &self.description {
             lines.extend_from_slice(&para.render(width));
         }