문제

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