/*\
title: $:/macros/skeeve/wordcount.js
type: application/javascript
module-type: macro
<<wordcount text>>
Examples:
<<wordcount "sometext">>
<<wordcount tiddler:"tiddlertitle">>
<$macrocall $name="wordcount" text="sometext"/>
<$macrocall $name="wordcount" tiddler={{!!title}}/>
Inspired by: http://wordcountmacro.tiddlyspot.com/
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
This is a macro to get the number of "words" of a string/text or a tiddler.
*/
exports.name = "wordcount";
exports.params = [
{ name: "text" },
{ name: "tiddler" },
];
/*
Run the macro
*/
exports.run = function(text, tiddler) {
if(!text) {
if(!tiddler) {
return "0";
}
text = tiddler + " " + ($tw.wiki.getTiddlerText(tiddler) || "");
}
return text.match(/\w+/g).length.toString() || "0";
};
})();
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.
You overlooked: Save and Reload.
--
Ideally the word count would be displayed in edit mode...
Ideally the word count would be displayed in edit mode...
--
I hadn't intended to support transclusions. I am not sure how the regular expression word detection would deal with things like tables or the other html elements so I was just intending this to be used with plain text.
But it shouldn't be to terribly hard. I should have everything I need to do it in the calendar widget I made. I may eventually get around to it.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/3543859d-1723-4622-94e4-43dcfc1482e4%40googlegroups.com.