<$set name="mytext" value={{!!text}}>
<$button class="tc-btn-invisible" tooltip={{$:/language/Buttons/Reduce/Hint}} aria-label={{$:/language/Buttons/Reduce/Caption}}>
<$action-sendmessage
$message="tm-edit-text-operation"
$param="replace-all"
text=<<reduce "$(mytext)$">>
/>
{{$:/plugin/ajh/reduce/image}}
</$button>
</$set>/*\
$:/plugin/ajh/reduce/macro.js
type: application/javascript
module-type: macro
<<reduce text>>
Examples:
<<reduce>>
<<reduce "one two three">>
<$macrocall $name="reduce" text={{!!text}}/>
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
This is a macro to compress text into a blob for use with making external files seem searchable
*/
exports.name = "reduce";
exports.params = [
{ name: "text" }
];
/*
Run the macro
*/
exports.run = function(text) {
if(!text)
text = "mytext";
var zwrds = text.toLowerCase().replace( /\W/g," ");
var ztrc = zwrds.split(" ").sort().reverse();
var zntrc = " ";
var add = "";
for (var i = 0; i < ztrc.length; i++) {
if (zntrc.indexOf(ztrc[i]) < 1) {
add = ztrc[i].toString();
zntrc += add;
}
}
var format= zntrc.slice(1);
return reduce;
};
})();text=<<reduce "$(mytext)$">>if(!text) text =this.getVariable("mytext") ;
I'm pretty sure that this bit won't work:text=<<reduce "$(mytext)$">>
title:Foo
test: (blank)
\define foo() This is $(arg)$
<$set name="arg" value="myarg">
<$set name="tmp" value=<<foo>>>
<$button>
<$action-setfield
$tiddler="Foo"
test=<<tmp>>
/>
Click
</$button>
</$set>
</$set>
test = {{!!test}}<$vars arg=<<currentTiddler>> tmp=<<reduce title:$(arg)$>>>
<$button class="tc-btn-invisible">
<$action-sendmessage
$message="tm-edit-text-operation"
$param="replace-all"
text=<<tmp>>
/>
{{$:/plugin/ajh/reduce/image}}
</$button>
</$vars> var text = $tw.wiki.getTiddlerText(title);
var zwrds = text.toLowerCase().replace( /\W/g," ");
var ztrc = zwrds.split(" ").sort().reverse();
var zntrc = " ";
var add = "";
for (var i = 0; i < ztrc.length; i++) {
if (zntrc.indexOf(ztrc[i]) < 1) {
add = ztrc[i].toString();
zntrc += add;
}
}
var t= zntrc.slice(1);
return t;--
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 https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/f1743db2-8d22-494a-950c-e91bf062fd56%40googlegroups.com.
\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>/*\
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 tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
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.
/*\
title: $:/plugin/ajh/reduce/module.js
type: application/javascript
module-type: macro
Setup the root widget handler that can be used to compress text into a blob for use with making external files seem searchable.
\*/
(function () {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "reduce";
exports.params = [
{name: "title"}
];
/*
Run the macro
*/
exports.run = function(title) {
var text = $tw.wiki.getTiddlerText(title);
if(!text) {
return title;
}
var zwrds = text.toLowerCase().replace( /\W/g," ");
var ztrc = zwrds.split(" ").sort().reverse();
var zntrc = " ";
var add = "";
for (var i = 0; i < ztrc.length; i++) {
if (zntrc.indexOf(ztrc[i]) < 1) {
add = ztrc[i].toString();
zntrc += add;
}
}
var t= zntrc.slice(1);
return t;
};
})();title: $:/plugin/ajh/reduce/macro.js
type: application/javascript
module-type: macro
Reduce text into a blob removing duplicate words and spaces.
\*/
(function () {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "reduce";
exports.params = [];
/*
Run the macro
*/
exports.run = function() {
this.editTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
var text = $tw.wiki.getTiddlerText(this.editTitle);
var zwrds = text.toLowerCase().replace( /\W/g," ");
var ztrc = zwrds.split(" ").sort().reverse();
var zntrc = " ";
var add = "";
for (var i = 0; i < ztrc.length; i++) {
if (zntrc.indexOf(ztrc[i]) < 1) {
add = ztrc[i].toString();
zntrc += add;
}
}
var t= zntrc.slice(1);
return t;
};
})();