As Eric points out it's difficult to do what you suggest in a browser
independent way. This was especially true at the time that TiddlyWiki
was originally written. And also, as Eric says, even if you manage to
do this the problem is that the code extracted from the DOM does not
retain its comments or its original formatting. TiddlyWiki aims to
make itself accessible by including its code in a reasonably
understandable format (which is also one of the reasons the code is
not compressed).

Having said all that, it is possible to do what you suggest. Indeed
your suggestion can be simplified - you don't need to read in the file
and shove it into a DOM element since the TiddlyWiki HTML file is
already in the DOM. So a slightly modified way of doing what you
suggest is:

i) get a string that is a template for the TiddlyWiki file
ii) get the javascript from the DOM and put it in the appropriate
place in the template
iii) get the tiddler content and put it in the appropriate place in
the template
iv) put in the various other miscellaneous items that TiddlyWiki uses
v) save the file

A while ago I wrote a plugin to do something similar. Its at:

http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/experimental/FastSavePlugin.js

it needs to be used with the template at:

http://svn.tiddlywiki.org/Trunk/contributors/MartinBudden/tiddlers/TiddlyWikiTemplate.tiddler

The plugin is called FastSavePlugin because it is faster since it does
not need to reload the TiddlyWiki before saving (indeed this was the
primary motivation for writing it). This is especially true for a
large TiddlyWiki on a remote host.

The plugin works by overwriting the LoadOriginal function - instead of
loading the tiddlywiki from file it is generated by a custom formatter
that puts it together as above. The pluging does not go the whole hog
- there is still some string manipulation after this step, but it
would in principle be fairly straightforward to extend it avoid an
search and replace operations.

And as said earlier, it suffers from the problems that the javascript
in the saved file can loose its comments and formatting.

Martin

On 6 Jan, 06:50, Eric Shulman <[email protected]> wrote:
> > Yes, I understand that process.
> > My point was that a more "correct" (which I know is not always a good 
> > thing) way to do would be to
> > * read the file
> > * shove it into the innerHTML of a (not in document) dom node X
> > * use getElementByID to find the storearea div
> > * set the innerHTML of that div
> > * pull the innerHTML out of X
> > * write that string to the file
>
> TiddlyWiki directly encodes and generates the HTML for the storeArea
> DIV needed to save the current tiddlers.  Thus, when TW reads in the
> saved file content, the purpose of the string manipulation is not to
> locate the existing storeArea in the saved content... rather, it is to
> extract the *unparsed* contents of the rest of the file that surrounds
> the storeArea definition, so that the newly-generated storeArea HTML
> can be inserted into that content and then re-written to the file.
>
> However, the 'round-trip' process you outlined:  (1) read file (2) set
> innerHTML (3) read innerHTML (4) write file, will *not* produce
> correct results.  The reason is that the innerHTML you set is
> automaticaly *parsed* by the browser, and the innerHTML that is
> subsequently returned from the DOM node will be *re-generated*
> according that particular browser's internal 'pretty printing' logic,
> with all the JS code reformatted and all comments stripped out.
>
> The round-trip through innerHTML can also mangle other parts of the
> source code as well -- I think it fails to regenerate the CDATA blocks
> (but I'm not 100% certain of that) -- and there are other subtle cross-
> browser differences in the innerHTML output that make it  impractical
> and unreliable to use in the way you suggest.  In contrast, using
> string manipulation to merge the newly generated storeArea with the
> existing plain-text file content is 100% consistent across all
> browsers, specifically because it does *not* rely upon the browser's
> handling of innerHTML.
>
> -e
> Eric Shulman
> TiddlyTools / ELS Design Studios
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/TiddlyWikiDev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to