title: Rails truncate UTF-8 strings containing &eacute; (for example)
body: <p>I am working on a <em>rails 3.1</em> app with <em>ruby 1.9.3</em> and <em>mongoid</em> as my ORM. I am facing an annoying issue. I would like to truncate the content of a post like this:</p>
  
  <pre><code>&lt;%= raw truncate(strip_tags(post.content), :length =&gt; 200) %&gt;
  </code></pre>
  
  <p>I am using <code>raw</code> and <code>strip_tags</code> because my <code>post.content</code> is actually handled with a rich text editor. </p>
  
  <p>I have a serious issue with non ASCII characters. Imagine my post content is the following:</p>
  
  <pre><code>éééé éééé éééé éééé éééé éééé éééé éééé
  </code></pre>
  
  <p>What I am doing above in a naive way does this:</p>
  
  <pre><code>éééé éééé éééé éééé éééé &amp;eac... 
  </code></pre>
  
  <p>Looks like truncate is seeing every word of the string like <code>&amp;eacute;&amp;eactute;&amp;eacute;&amp;eacute;</code>.</p>
  
  <p>Is there a way to either:</p>
  
  <ol>
  <li><strong>Have truncate handle an actual UTF-8 strings</strong>, where 'é' stands for a single character ? That would be my favorite approach.</li>
  <li>Hack the above instruction such that the result is better, like force rails to truncate between 2 words,</li>
  </ol>
  
  <p>I am asking this question because I have not found <strong>any</strong> solution so far. This is the only place in my app where I have problems with such character, and it is a major issues since the whole content of the website is in french, so contains a lot of <code>é, ç, à, ù</code>.</p>
  
  <p>Also, I think this behavior is quite unfortunate for the <code>truncate</code> helper because in my case it does not truncate 200 characters at all, but approximately 25 characters !</p>