Get wordcount to count rendered words (not raw)?

I use telmiger’s solution for wordcount while editing, and roughly this as an interim solution to display in subtitle.

However, as a writer working with a wordcount goal, I’d love to make use of a wordcount field that somehow parses the //wikified// result of the text field, not the number of word-like strings in the raw text field.

That way, if I <!-- comment-out --> a paragraph (for example), or use local css to format a block quote, the wordcount field would properly track (within decent wiggle room for “what’s a word?”) what is rendered, not what’s under the hood.

Is this doable?

Many thanks!

-Springer

I’m using this :

<$wikify name=text text={{!!text}} mode=inline output=text>
<$count filter="[<text>split[ ]split[
]!is[blank]]"/> words
</$wikify>

With a field “code-body” set to “yes”, and the title set to “WordCount” → very important otherwise you might crash your wiki

Then you can use it like this : {{YourTiddlerToCount||WordCount}}

You can put this in the view template for the tiddler subtitle for example, like this : {{||WordCount}}
But not in the text field of the tiddler to be counted itself otherwise it will count the transclusion too.

EDIT: dont do the last thing, seems like it causes too much recursions, I’ll try to find a fix

1 Like

Yes, that’s what I’ve been wrestling with since you posted – how to display the wordcount in any part of the ViewTemplate for that tiddler. (I also tried linkstyle to make the number appear after the title.) It does work when invoked at a distance.

This should avoid the recursion issue :

<$list filter="[{!!title}!match[$:/core/ui/ViewTemplate/subtitle]]">
<$wikify name=text text={{!!text}} mode=inline output=text>
<$text text=" "/><$count filter="[<text>split[ ]split[
]!is[blank]]"/><$text text=" "/>words
</$wikify>
</$list>

It work for every tiddlers except the $:/core/ui/ViewTemplate/subtitle tiddler, I wish there was a better solution :confused:

You can try it by drag and dropping this tiddler in a test wiki :

$ _core_ui_ViewTemplate_subtitle.json (700 Bytes)

EDIT: Maybe it would be a good idea to use this technique in the edit view template only, and store the word count in a field when hitting the save button. That way the wikify widget would only be used while editing a tiddler, which should improve performances when a lot of tiddlers are open

1 Like

I’ve confirmed that your solution works (in the subtitle ViewTemplate form you specified above). Since it’s not quick for me to set up the set-field action on save to hard-code the wordcount (though I do see why it might be better), I’ll return to this later. I do after all have to return to the actual writing…

At least I see a solution coming into shape, and so quickly!

Many thanks, telumire!!

1 Like