Wordcount for TW5

357 views
Skip to first unread message

Alex Hough

unread,
Dec 10, 2014, 5:15:12 AM12/10/14
to TiddlyWiki
Is there an update for TW 5 for this [1]

ALex

Stephan Hradek

unread,
Dec 10, 2014, 6:10:31 AM12/10/14
to tiddl...@googlegroups.com, Tiddl...@googlegroups.com

Is this sufficient?

/*\
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";
};

})();


Alex Hough

unread,
Dec 10, 2014, 6:39:42 AM12/10/14
to TiddlyWiki
Dear Stephan
I've cut and pasted the text into a tiddler, given it the title "$:/macros/skeeve/wordcount.js" and set the type to "application/javascript"

I have also added a field with "module-type: macro"

I've tried this on TW.com the result is that nothing  appears to happen. I bet I've overlooked something very simple...

best wishes
 
Alex

--
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.

Stephan Hradek

unread,
Dec 10, 2014, 6:47:15 AM12/10/14
to tiddl...@googlegroups.com
You overlooked: Save and Reload.

Alex Hough

unread,
Dec 10, 2014, 7:40:39 AM12/10/14
to TiddlyWiki
Dear Stephen

I have!
Easy to overlook when everything seems to change right away in TW5.

Many thanks - it works fine now

Ideally the word count would be displayed in edit mode...


Alex

On 10 December 2014 at 11:47, Stephan Hradek <stephan...@gmail.com> wrote:
You overlooked: Save and Reload.

--

Tobias Beer

unread,
Dec 10, 2014, 9:52:45 AM12/10/14
to tiddl...@googlegroups.com
Hi Alex,
 
Ideally the word count would be displayed in edit mode...

I believe, equivalent to...


...you can make a custom edit-template section to display your word-count at the bottom.

Best wishes, Tobias.

Stephan Hradek

unread,
Dec 10, 2014, 10:39:43 AM12/10/14
to tiddl...@googlegroups.com


Am Mittwoch, 10. Dezember 2014 13:40:39 UTC+1 schrieb AlexHough:
Ideally the word count would be displayed in edit mode...

As far as I understood the original one, the macro is put into the edit template.

Try that.

RichShumaker

unread,
Dec 10, 2014, 4:14:06 PM12/10/14
to tiddl...@googlegroups.com
Hilarious I just cracked myself up.
Combining the help Tobias gave me earlier with TW Links on every Tiddler.
I thought that you could have a Word Count in the Corner of every Tiddler corner.
Combine that with Jeremy's discussion of using TW to send Tweets you would know if you were over your character count.
Also you could set it up for different maximums(for sending SMS and Tweets), unless SMS and Twitter are the same in which case d'oh!!!

So then you could use TW to Tweet and Message people, not sure how the data would come back into the TiddlyWiki from messaging and Twitter.
Now my brain hurts time to take a break.

Rich Shumaker

Alex Hough

unread,
Jun 28, 2015, 11:03:16 AM6/28/15
to TiddlyWiki
Thanks again Stephan,

For those interested, i've adapted ResumeBuilderWiki's "Objective" tiddler  to make my own "Idea" tiddler.

The macrocount gets the data in the tiddler. I am using a download of pre-release, and the docmentation macro for warning

{$:/language/StartupPitch/Idea/Prompt}}

;Idea
<$edit-text tiddler='$:/data/Idea' class='tc-edit-texteditor' placeholder='Notes'/>
<<.warning [[Current wordcount: <$macrocall $name="wordcount" tiddler={{$:/data/Idea}}/>]]>>


A possible cool addition would be to turn the text red when wordcout goes over a pre-determined limit or, in the context of ResumeBuilderWiki', not allow you to continue

Alex


--

Jed Carty

unread,
Jun 28, 2015, 2:19:46 PM6/28/15
to tiddl...@googlegroups.com, Tiddl...@googlegroups.com
I hadn't really thought about using this. I can add what you are talking about but I think I am going to need to turn the macro into a widget so it updates when the input changes instead of just when the tiddler is rendered. And I should probably modify this to count characters for my twitter plugin as well.

The conditional css to change the text color shouldn't be a big deal, but it will require a numeric comparison which would require another macro or widget.

Making it so you can no longer give input based on something like this may be a problem. The only way I can think of to do that would be to remove the edit widget and just display the text instead, but that would keep you from being able to change the text at all, not just prevent you from adding more to it.

Jed Carty

unread,
Jun 29, 2015, 3:53:31 PM6/29/15
to tiddl...@googlegroups.com, Tiddl...@googlegroups.com
I forgot to actually put up what I made. It is a widget based partly off of the macro Skeeve made. It can update in real time unlike a macro, it can count words or characters and you can have it change the color of the numbers based on the count. You can also set a state tiddler for the current color so you can change other text based on the word/character count. I made a demo site here.

PMario

unread,
Jun 29, 2015, 4:20:29 PM6/29/15
to tiddl...@googlegroups.com, Tiddl...@googlegroups.com
Hi Jed,

Nice widget. .. There is an issue with transclusions.

tiddler: a

asdf asdf {{b}}

tiddler: b

this is a test

<$word-count tiddler='a' field='text' mode=word/> ... says: 3

There has been a discussion in a hangout 1. Oct. 2013
This discussion may be interesting.

-m

PMario

unread,
Jun 29, 2015, 4:29:51 PM6/29/15
to tiddl...@googlegroups.com, Tiddl...@googlegroups.com
Jeremys hints as a response to my misguided attempts is probably more interesting :)  https://youtu.be/DZiU4uSGFnQ?t=3601
-m

Jed Carty

unread,
Jun 29, 2015, 5:15:17 PM6/29/15
to tiddl...@googlegroups.com, Tiddl...@googlegroups.com
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.

Alex S. Garcia

unread,
Jun 29, 2015, 5:26:50 PM6/29/15
to tiddl...@googlegroups.com
> <http://ooktech.com/jed/ExampleWikis/WordCount/>.

Wow! Neat. This is *exactly* what I've been trying to set up for ages...

I unfortunately cannot get this to work in my own tiddlers, though.

I'm guessing it requires TW5 to function properly? (I can't seem to set type &
module-type, for instance, for the javascript code widget).

I use Tiddlywiki Write, a modified version of TW 2.6.1.



Alex.
--
-------------------------------------------------------------------------
http://www.alexsgarcia.com/
http://www.myspace.com/asglyrics
Music Videos : http://mvdbase.com [database]
http://www.freelists.org/list/mv [mailing-list]
-------------------------------------------------------------------------

Alex Hough

unread,
Jun 29, 2015, 5:48:52 PM6/29/15
to TiddlyWiki
@Jed,

Great work!

Alex

On 29 June 2015 at 22:15, Jed Carty <inmy...@gmail.com> wrote:
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.
Reply all
Reply to author
Forward
0 new messages