0

I've just started using RedCloth as part of a simple wiki feature in my ruby on rails app.

I'd like to be able to display a word count next to wiki pages in the index.

Given the textile pulled from the database as input, how should I go about getting an accurate word count as output?

The most obvious solution would be to simply split by /\s+/ and remove all the known textile tokens such as p. or # from the resulting array.

But I'm wondering if there's a more elegant (less tedious) solution, such as a feature of RedCloth or a fast and ready way of removing the markup from the RedCloth html output which would leave just whitespace separated words.

Nat
  • 2,689
  • 2
  • 29
  • 35

2 Answers2

2

Your split idea is, unfortunately, probably the best one. For the sake of performance, I'd do the calculation when you save changes to a wiki page, and just warehouse that number.

jbarket
  • 882
  • 7
  • 14
1
  1. Render RedCloth into html.
  2. Strip html.
  3. Than do word count.
przemo_li
  • 3,932
  • 4
  • 35
  • 60