Line breaks missing from embedded tweets

Expected behaviour: tweet displays correctly.
Current behaviour: newlines missing
Steps to reproduce: onebox the following tweet, or one like it

PR welcome on the onebox gem if you want to fix it.


This is not a bug, depending on the Twitter client and platform newlines may or may not be visible.

1 Like

1 Like

Links in Tweet text must be displayed using the display_url field in the URL entities API response, and link to the original url field. See our best practices article for additional details.

This would be way higher priority and help so much more.

Ok, it seems like this should be doable by getting the html tweet body supplied by twitter and interpolating that directly into the template. Is that correct? I don’t think mustache will allow us to do this except by including raw html.

As for the formatting, it appears twitter uses white-space: pre-wrap;, which is usually applied to embedded tweets with a script. The options I can see are:

  • pre tag
  • may break wrapping
  • styling
  • overriding css could break tweet display
  • escape all whitespace
  • including exotic unicode space chars?

Alternatively, you might choose to leave the twitter engine styling as-is, and let users enable ‘rich’ oembed type if they want more extensive styling. If I understand correctly, whitelisting is currently done by editing a ruby file; would it be helpful if I were to try and shift that to a configurable option, and allow enabling different oembed or opengraph types on a per-site basis?