Are there any scripts or plugins that write out tiddler content to a
file?
I'm trying to make a html export of selected tiddlers that have links.
Maybe someday TW may work on this browser:
http://www.opera.com/products/mobile/products/winmobileppc/ ?
or something like IsaoSonobe's TiddlyWikiPod.
I'm still searching for the grail of having a mobile TW.
ELS Import and Export Tiddlers are indispensable to make that happen,
but the exportTiddlerPlugin output doesn't create links to the
tiddlers.
I went with Udo's ForEachTiddler to create a index of links to tiddler
output but I still have to create the webpage manually before
converting it to a mobile plucker version.
Here are the steps I do currently:
#run the export macro below
#paste the text outputs into a single text file
#wrap the markup with <html> and <body> tag pairs
#save as a html file
#convert the webpage to plucker format so I can read it on my Palm
handheld.
This results in a web page with an index of links to tiddlers which is
wunderbar, but is there a way I can modify the script below to add the
<html> and <body> tags and have the resulting output as 1 file? -so the
number of steps is reduced
The toFile part of the write function writes out the result of that FET
loop and I want to insert additional text before and after the result:
Here's my modified tiddler to create the 2 text files: index and body
from tiddlers tagged as "star"
{{{<<forEachTiddler
where tiddler.tags.contains("star")
script 'function getSortedTagsText(tiddler) {var tags = tiddler.tags;
if (!tags) return ""; tags.sort(); var result = ""; for (var i = 0; i <
tags.length;i++) {result += tags[i]+ " ";} return result;} function
writeTiddler(tiddler) {return "<A
HREF=\"#"+tiddler.title+"\">"+tiddler.title+"</A>\n"}'
write
'writeTiddler(tiddler)'
toFile 'file:///c:/MyTiddlyWikiExportIndex.txt' withLineSeparator
'\r\n'
>>
<<forEachTiddler
where tiddler.tags.contains("star")
script 'function getSortedTagsText(tiddler) {var tags = tiddler.tags;
if (!tags) return ""; tags.sort(); var result = ""; for (var i = 0; i <
tags.length;i++) {result += tags[i]+ " ";} return result;} function
writeTiddler(tiddler) {return "<A
NAME=\""+tiddler.title+"\">"+tiddler.title+"</A>\nTags: "+
getSortedTagsText(tiddler)+"\nModified:
"+tiddler.modified.convertToYYYYMMDDHHMM()+"\nModifier:
"+tiddler.modifier+"\n--------------------------------------------------\n"+tiddler.text+"\n--------------------------------------------------\n(End
of "+tiddler.title+")<p></p><p></p>\n"}'
write
'writeTiddler(tiddler)'
toFile 'file:///c:/MyTiddlyWikiExport.txt' withLineSeparator '\r\n'
>>
function getSortedTagsText(tiddler) {
var tags = tiddler.tags;
if (!tags)
return "";
tags.sort();
var result = "";
for (var i = 0; i < tags.length;i++) {
result += tags[i]+ " ";
}
return result;
}
function writeTiddler(tiddler) {
return "==== "+tiddler.title+"=========================\n"+
"Tags: "+ getSortedTagsText(tiddler)+"\n"+
"Modified: "+tiddler.modified.convertToYYYYMMDDHHMM()+"\n"+
"Modifier: "+tiddler.modifier+"\n"+
"----------\n"+
tiddler.text+"\n"+
"----------\n"
"(End of "+tiddler.title+")\n"
}
}}}
Any suggestions, half-truths or bald faced lies appreciated.
Best,
tony
//
---------------------------------------------------------------------------------
// Publishing
//
---------------------------------------------------------------------------------
// Label for publish button
config.macros.doPublish = {label: "publish", prompt: "Publish Tiddlers
as HTML files"};
config.macros.doPublish.handler = function(place)
{
if(!readOnly)
createTiddlyButton(place,this.label,this.prompt,function ()
{doPublish(); return false;},null,null,this.accessKey);
}
function doPublish() {
var savedTiddlers = [];
var tiddlers = store.getTiddlers("title");
var place = document.getElementById(story.container)
var HTMLTemplate = getTiddlerTextAsHTML("PublishTemplate")
HTMLTemplate = wiki2Web(HTMLTemplate);
for (var t = 0; t < tiddlers.length; t++) {
var tiddler = tiddlers[t];
if (tiddler.tags.contains("publish")) {
var tiddlerHTML = getTiddlerTextAsHTML(tiddler.title)
var HTML = HTMLTemplate.format([
tiddler.title.htmlEncode(),
wiki2Web(tiddlerHTML),
tiddler.tags.join(","),
tiddler.modifier,
tiddler.modified.toLocaleString(),
tiddler.created.toLocaleString()
]);
saveFile("C:\\temp\\" + tiddler.title.filenameEncode() + ".html",
HTML)
story.closeTiddler(tiddler.title);
}
}
}
function getTiddlerTextAsHTML(tiddlerName) {
var result = document.createElement("span");
wikify(store.getTiddler(tiddlerName).text, result);
applyHtmlMacros(result,store.getTiddler(tiddlerName));
return result.innerHTML;
}
// Convert wikified text to html
function wiki2Web(wikiHTML) {
var regexpLinks = new RegExp("<a tiddlylink=.*?</a>","mg");
var result = wikiHTML.match(regexpLinks);
if (result) {
for(i = 0; i < result.length; i++) {
var tiddlerName = result[i].match(/ tiddlylink="(.*?)"/)[1];
var url = tiddlerName.htmlDecode().filenameEncode() + ".html";
wikiHTML = wikiHTML.myReplace(result[i], "<a href=\"" + url + "\">"
+ tiddlerName + "</a>");
}
}
return wikiHTML
}
// Replace without regex
String.prototype.myReplace = function(sea, rep) {
var t1 = this.indexOf(sea);
var t2 = parseInt(this.indexOf(sea)) + parseInt(sea.length);
var t3 = this.length;
return this.substring(0, t1) + rep + this.substring(t2, t3)
}
// Convert illegal characters to underscores
String.prototype.filenameEncode = function()
{
return(this.toLowerCase().replace(/[^a-z0-9_-]/ ,"_"));
}
To use this you need to create a tiddler called "PublishTemplate" which
you can customize to present your layout. My example is:
<html>
<head>
<title>%0</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<meta name="keywords" content="%2"/>
</head>
<body>
<table border='0'>
<tr>
<td valign='top'><div class='viewer' macro='tiddler
PublishMenu'></div></td>
<td valign='top'>
<h1>%0</h1>
%1
</td>
</tr>
</table>
<hr>
<center><small>
%3, %4 (created %5)
</small></center>
</body>
</html>
The tiddler "PublishMenu" is my attempt at adding a navigation to the
exported files. It's function is to link to all tiddlers tagged with
"publish" and "menu". You could just user:
<<tagging menu>>
but for the AND logic I have used Udo's ForEachTiddlerPlugin:
<<forEachTiddler
where
'tiddler.tags.contains("publish") && tiddler.tags.contains("menu")'
sortBy
'tiddler.title'
write
'"| [[" + tiddler.title + "]] |\n"'
>>
Is this working/tested code yet? Any needed install instructions?
wikiHTML = wikiHTML.replace(/ href="http:\/\//gi, " target=\"_blank\"
href=\"http://");
}
return wikiHTML
}
// Replace without regex
String.prototype.myReplace = function(sea, rep) {
var t1 = this.indexOf(sea);
var t2 = parseInt(this.indexOf(sea)) + parseInt(sea.length);
var t3 = this.length;
return this.substring(0, t1) + rep + this.substring(t2, t3)
}
// Convert illegal characters to underscores
String.prototype.filenameEncode = function()
{
return(this.toLowerCase().replace(/[^a-z0-9_-]/g ,"_"));
}
I too think it is very useful thanks for creating it.
I created 3 tiddlers: PublishMacro (tagged systemConfig),
PublishTemplate and PublishMenu. I tagged a bunch of tiddlers menu and
publish and put in the html template into the PublishTemplate tiddler.
Unfortunately, TW throws up an error in the PublishTemplate (it does
give a nice drop down in a table)
" 1. Error while executing macro <<tiddler
2. PublishMenu>>:
3. No such macro"
which seems odd since I do have a PublishMenu tiddler.
Should I be tagging the tiddlers with other tags or do you have some
more insight?
Thank you,
tony