Вопрос

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.

Это было полезно?

Решение

  1. Render RedCloth into html.
  2. Strip html.
  3. Than do word count.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top