Ok, this seems to work. In my example, the contents of a given tiddler 
(MyReductionText) are replaced with their reduced subset when the button is 
pushed.

 First the regular macro stuff:

\define tmp2()
<<reduce """$(mytext)$""">>
\end


<$set name="mytext" value={{MyReductionText!!text}}>
<<tmp2>>
<$button>
<$action-setfield 
    $tiddler="MyReductionText" 
    text=<<tmp2>>   />
<$action-navigate $to="MyReductionText"/>
Modify and Go to Reduction Text
</$button>
</$set>

And then the javascript macro. Remember that the macro has to have 
content-type set to applicaton/javascript with an additional field 
"module-type" with value "macro".

/*\
title: $:/Macro/reduce.js
type: application/javascript
module-type: macro
This is a macro finds and returns all unique words in a given string of 
text 

\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

exports.name = "reduce";
exports.params = [    { name: "text" } ];

/*
Run the macro
*/

exports.run = function(text) {

    if(!text)        text = "mytext";


    var araWords = text.toLowerCase().replace(    /\W/g," ").split(" ") ;
    var mapWords = {} ;    
    var araReduced = [];
    
    araWords.forEach(function (x) {
       if (!mapWords[x]) {
          araReduced.push(x);
          mapWords[x] = true;
        }
    });


/*
  
*/

  return araReduced.sort().reverse().join(" ") ; 

};

})();



-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/5ab90d65-b767-4ef6-adf5-d973cc16aa60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to