1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-17 23:34:50 +00:00
TiddlyWiki5/archive/readme.md
2012-05-05 22:49:23 +01:00

39 lines
21 KiB
Markdown

<div data-tiddler-target='ReadMe' data-tiddler-template='ReadMe' class='tw-tiddler-frame'><h1>Welcome to TiddlyWiki5</h1><div data-tiddler-target='HelloThere' data-tiddler-template='HelloThere' class='tw-tiddler-frame'>Welcome to TiddlyWiki5, a reboot of TiddlyWiki, the venerable, reusable non-linear personal web notebook first released in 2004. It is a complete interactive wiki that can run from a single HTML file in the browser or as a powerful node.js application.<br><br>TiddlyWiki5 is currently in early beta, which is to say that it is useful but incomplete. You can try out the prototype at <a href='http://tiddlywiki.com/tiddlywiki5' class='tw-tiddlylink tw-tiddlylink-external'>http://tiddlywiki.com/tiddlywiki5</a>, get involved in the <a href='https://github.com/Jermolene/TiddlyWiki5' class='tw-tiddlylink tw-tiddlylink-external'>development on GitHub</a> or the discussions on <a href='http://groups.google.com/group/TiddlyWikiDev' class='tw-tiddlylink tw-tiddlylink-external'>the TiddlyWikiDev Google Group</a>.<br></div><br><h1>Usage</h1><div data-tiddler-target='CommandLineInterface' data-tiddler-template='CommandLineInterface' class='tw-tiddler-frame'>TiddlyWiki5 can be used on the command line to perform an extensive set of operations based on RecipeFiles, TiddlerFiles and TiddlyWikiFiles.<br><br>The command line interface for TiddlyWiki5 has been designed to support two distinct usages:<br><ul><li> Cooking (or building) old 2.6.x versions of classic TiddlyWiki from the constituent JavaScript components</li><li> Cooking and serving TiddlyWiki5 itself</li></ul><br><h2>Usage</h2><code>
node tiddlywiki.js &lt;options&gt;
</code><br>The command line options are processed sequentially from left to right. Processing pauses during long operations, like loading a recipe file and all the subrecipes and tiddlers that it references, and then resumes with the next command line option in sequence.<br><br>The state that is carried between options is as follows:<br><ul><li> The set of tiddlers that are currently loaded into memory</li><li> The recipe file last used to load tiddlers (recipe files are used primarily to manage shadow tiddlers)</li><li> The TiddlerFileStore used to store the main content tiddlers. This is independent of the current recipe</li></ul><br>The following options are available:<br><table class='table'><tbody><tr class='evenRow'><td align='left'><code>--recipe &lt;filepath&gt;</code></td><td align='left'>Loads a specfied <code>.recipe</code> file</td></tr><tr class='oddRow'><td align='left'><code>--load &lt;filepath&gt;</code></td><td align='left'>Load additional tiddlers from 2.x.x TiddlyWiki files (<code>.html</code>), <code>.tiddler</code>, <code>.tid</code>, <code>.json</code> or other files</td></tr><tr class='evenRow'><td align='left'><code>--store &lt;dirpath&gt;</code></td><td align='left'>Load a specified TiddlerFileStore</td></tr><tr class='oddRow'><td align='left'><code>--links none</code></td><td align='left'>Determines how links will be generated by subsequent options. See below for details</td></tr><tr class='evenRow'><td align='left'><code>--savewiki &lt;dirpath&gt;</code></td><td align='left'>Saves all the loaded tiddlers as a single file TiddlyWiki called <code>index.html</code> and an RSS feed called <code>index.xml</code> in a new directory of the specified name</td></tr><tr class='oddRow'><td align='left'><code>--savetiddler &lt;title&gt; &lt;filename&gt; [&lt;type&gt;]</code></td><td align='left'>Save an individual tiddler as a specified MIME type, defaults to <code>text/html</code></td></tr><tr class='evenRow'><td align='left'><code>--savetiddlers &lt;outdir&gt;</code></td><td align='left'>Saves all the loaded tiddlers as <code>.tid</code> files in the specified directory</td></tr><tr class='oddRow'><td align='left'><code>--savehtml &lt;outdir&gt;</code></td><td align='left'>Saves all the loaded tiddlers as static, unstyled <code>.html</code> files in the specified directory</td></tr><tr class='evenRow'><td align='left'><code>--servewiki &lt;port&gt;</code></td><td align='left'>Serve the cooked TiddlyWiki over HTTP at <code>/</code></td></tr><tr class='oddRow'><td align='left'><code>--servetiddlers &lt;port&gt;</code></td><td align='left'>Serve individual tiddlers over HTTP at <code>/tiddlertitle</code></td></tr><tr class='evenRow'><td align='left'><code>--wikitest &lt;dir&gt; [save]</code></td><td align='left'>Run wikification tests against the tiddlers in the given directory. Include the <code>save</code> flag to save the test result files as the new targets</td></tr><tr class='oddRow'><td align='left'><code>--dumpstore</code></td><td align='left'>Dump the TiddlyWiki store in JSON format</td></tr><tr class='evenRow'><td align='left'><code>--dumprecipe</code></td><td align='left'>Dump the current recipe in JSON format</td></tr><tr class='oddRow'><td align='left'><code>--verbose</code></td><td align='left'>verbose output, useful for debugging</td></tr></tbody></table><h2> Examples</h2>This example loads the tiddlers from a TiddlyWiki HTML file and makes them available over HTTP:<br><code>
node tiddlywiki.js --load mywiki.html --servewiki 127.0.0.1:8000
</code><br>This example cooks a TiddlyWiki from a recipe:<br><code>
node tiddlywiki.js --recipe tiddlywiki.com/index.recipe --savewiki tmp/
</code><br>This example ginsus a TiddlyWiki into its constituent tiddlers:<br><code>
node tiddlywiki.js --load mywiki.html --savetiddlers tmp/tiddlers
</code><br><h2> Notes</h2>The HTTP serving functionality built into TiddlyWiki5 is designed to support personal use scenarios. If you want to flexibly and robustly share tiddlers on the web for multiple users, you should use TiddlyWeb or TiddlySpace.<br><br><code>--servewiki</code> and <code>--servetiddlers</code> are for different purposes and should not be used together. The former is for TiddlyWiki core developers who want to be able to edit the TiddlyWiki source files in a text editor and view the results in the browser by clicking refresh; it is slow because it reloads all the TiddlyWiki JavaScript files each time the page is loaded. The latter is for experimenting with the new wikification engine.<br><br><code>--wikitest</code> looks for <code>*.tid</code> files in the specified folder. It then wikifies the tiddlers to both &quot;text/plain&quot; and &quot;text/html&quot; format and checks the results against the content of the <code>*.html</code> and <code>*.txt</code> files in the same directory.<br><br><code>--links</code> controls the way that links are generated. Currently, the only option supported is:<br><br> <code>none</code>: Tiddler links are disabled<br><br><br></div><br><h1>Testing</h1><div data-tiddler-target='Testing' data-tiddler-template='Testing' class='tw-tiddler-frame'><h1>Test Scripts</h1><br>Three test scripts are provided, each as a Mac OS X <code>*.sh</code> bash script and a Windows <code>*.bat</code> batch file. In each case they should be run with the current directory set to the directory in which they reside.<br><br><ul><li> <code>test.sh</code>/<code>test.bat</code> cooks the main tiddlywiki.com recipe for TiddlyWiki 2.6.5 and compares it with the results of the old build process (ie, running cook.rb and then opening the file in a browser and performing a 'save changes' operation). It also runs a series of wikifications tests that work off the data in <code>test/wikitests/</code>.</li><li> <code>tw5.sh</code>/<code>tw5.bat</code> builds TiddlyWiki5 as a static HTML file</li><li> <code>tw5s.sh</code>/<code>tw5s.bat</code> serves TiddlyWiki5 over HTTP on port 8080</li></ul></div><br><h1>Architecture</h1><div data-tiddler-target='TiddlyWikiArchitecture' data-tiddler-template='TiddlyWikiArchitecture' class='tw-tiddler-frame'><h2> Overview</h2><br>The heart of TiddlyWiki can be seen as an extensible representation transformation engine. Given the text of a tiddler and its associated MIME type, the engine can produce a rendering of the tiddler in a new MIME type. Furthermore, it can efficiently selectively update the rendering to track any changes in the tiddler or its dependents.<br><br>The most important transformations are from <code>text/x-tiddlywiki</code> wikitext into <code>text/html</code> or <code>text/plain</code> but the engine is used throughout the system for other transformations, such as converting images for display in HTML, sanitising fragments of JavaScript, and processing CSS.<br><br>The key feature of wikitext is the ability to include one tiddler within another (usually referred to as <em>transclusion</em>). For example, one could have a tiddler called <em>Disclaimer</em> that contains the boilerplate of a legal disclaimer, and then include it within lots of different tiddlers with the macro call <code>&lt;&lt;tiddler Disclaimer&gt;&gt;</code>. This simple feature brings great power in terms of encapsulating and reusing content, and evolving a clean, usable implementation architecture to support it efficiently is a key objective of the TiddlyWiki5 design.<br><br>It turns out that the transclusion capability combined with the selective refreshing mechanism provides a good foundation for building TiddlyWiki's user interface itself. Consider, for example, the StoryMacro in its simplest form:<br><pre>&lt;&lt;story story:MyStoryTiddler&gt;&gt;
</pre>The story macro looks for a list of tiddler titles in the tiddler <code>MyStoryTiddler</code>, and displays them in sequence. The subtle part is that subsequently, if <code>MyStoryTiddler</code> changes, the <code>&lt;&lt;story&gt;&gt;</code> macro is selectively re-rendered. So, to navigate to a new tiddler, code merely needs to add the name of the tiddler and a line break to the top of <code>MyStoryTiddler</code>:<br><pre>var storyTiddler = store.getTiddler(&quot;MyStoryTiddler&quot;);
store.addTiddler(new Tiddler(storyTiddler,{text: navigateTo + &quot;\n&quot; + storyTiddler.text}));
</pre>The mechanisms that allow all of this to work are fairly intricate. The sections below progressively build the key architectural concepts of TiddlyWiki5 in a way that should provide a good basis for exploring the code directly.<br><h2> Tiddlers</h2>Tiddlers are an immutable dictionary of name:value pairs called fields.<br><br>The only field that is required is the <code>title</code> field, but useful tiddlers also have a <code>text</code> field, and some or all of the standard fields <code>modified</code>, <code>modifier</code>, <code>created</code>, <code>creator</code>, <code>tags</code> and <code>type</code>.<br><br>Hardcoded in the system is the knowledge that the <code>tags</code> field is a string array, and that the <code>modified</code> and <code>created</code> fields are JavaScript <code>Date</code> objects. All other fields are strings.<br><br>The <code>type</code> field identifies the representation of the tiddler text with a MIME type.<br><h2> WikiStore</h2>Groups of uniquely titled tiddlers are contained in WikiStore objects.<br><br>The WikiStore also manages the plugin modules used for macros, and operations like serializing, deserializing, parsing and rendering tiddlers.<br><br>Each WikiStore is connected to another shadow store that is used to provide default content. Under usual circumstances, when an attempt is made to retrieve a tiddler that doesn't exist in the store, the search continues into its shadow store (and so on, if the shadow store itself has a shadow store).<br><h2> WikiStore Events</h2>Clients can register event handlers with the WikiStore object. Event handlers can be registered to be triggered for modifications to any tiddler in the store, or with a filter to only be invoked when a particular tiddler or set of tiddlers changes.<br><br>Whenever a change is made to a tiddler, the wikistore registers a <code>nexttick</code> handler (if it hasn't already done so). The <code>nexttick</code> handler looks back at all the tiddler changes, and dispatches any matching event handlers. <br><h2> Parsing and Rendering</h2>TiddlyWiki parses the content of tiddlers to build an internal tree representation that is used for several purposes:<br><ul><li> Rendering a tiddler to other formats (e.g. converting wikitext to HTML)</li><li> Detecting outgoing links from a tiddler, and from them...</li><li> ...computing incoming links to a tiddler</li><li> Detecting tiddlers that are orphans with no incoming links</li><li> Detecting tiddlers that are referred to but missing</li></ul>The parse tree is built when needed, and then cached by the WikiStore until the tiddler changes.<br><br>TiddlyWiki5 uses multiple parsers:<br><ul><li> Wikitext (<code>text/x-tiddlywiki</code>) in <code>js/WikiTextParser.js</code></li><li> JavaScript (<code>text/javascript</code>) in <code>js/JavaScriptParser.js</code></li><li> Images (<code>image/png</code> and <code>image/jpg</code>) in <code>js/ImageParser.js</code></li><li> JSON (<code>application/json</code>) in <code>js/JSONParser.js</code></li></ul>Additional parsers are planned:<br><ul><li> CSS (<code>text/css</code>)</li><li> Recipe (<code>text/x-tiddlywiki-recipe</code>)</li></ul>One global instance of each parser is instantiated in <code>js/App.js</code> and registered with the main WikiStore object.<br><br>The parsers are all used the same way:<br><pre class='javascript-source'><span class='javascript-keyword'>var</span> <span class='javascript-identifier'>parseTree</span> <span class='javascript-punctuator'>=</span> <span class='javascript-identifier'>parser</span><span class='javascript-punctuator'>.</span><span class='javascript-identifier'>parse</span><span class='javascript-punctuator'>(</span><span class='javascript-identifier'>type</span><span class='javascript-punctuator'>,</span><span class='javascript-identifier'>text</span><span class='javascript-punctuator'>)</span> <span class='javascript-comment javascript-line-comment'>// Parses the text and returns a parse tree object
</span></pre>The parse tree object exposes the following fields:<br><pre class='javascript-source'><span class='javascript-keyword'>var</span> <span class='javascript-identifier'>renderer</span> <span class='javascript-punctuator'>=</span> <span class='javascript-identifier'>parseTree</span><span class='javascript-punctuator'>.</span><span class='javascript-identifier'>compile</span><span class='javascript-punctuator'>(</span><span class='javascript-identifier'>type</span><span class='javascript-punctuator'>)</span><span class='javascript-punctuator'>;</span> <span class='javascript-comment javascript-line-comment'>// Compiles the parse tree into a renderer for the specified MIME type
</span><span class='javascript-identifier'>console</span><span class='javascript-punctuator'>.</span><span class='javascript-identifier'>log</span><span class='javascript-punctuator'>(</span><span class='javascript-identifier'>parseTree</span><span class='javascript-punctuator'>.</span><span class='javascript-identifier'>toString</span><span class='javascript-punctuator'>(</span><span class='javascript-identifier'>type</span><span class='javascript-punctuator'>)</span><span class='javascript-punctuator'>)</span><span class='javascript-punctuator'>;</span> <span class='javascript-comment javascript-line-comment'>// Returns a readable string representation of the parse tree (either <code>text/html</code> or <code>text/plain</code>)
</span><span class='javascript-keyword'>var</span> <span class='javascript-identifier'>dependencies</span> <span class='javascript-punctuator'>=</span> <span class='javascript-identifier'>parseTree</span><span class='javascript-punctuator'>.</span><span class='javascript-identifier'>dependencies</span><span class='javascript-punctuator'>;</span> <span class='javascript-comment javascript-line-comment'>// Gets the dependencies of the parse tree (see below)
</span></pre>The dependencies are returned as an object like this:<br><pre>{
tiddlers: {&quot;tiddlertitle1&quot;: true, &quot;tiddlertitle2&quot;: false},
dependentAll: false
}
</pre>The <code>tiddlers</code> field is a hashmap of the title of each tiddler that is linked or included in the current one. The value is <code>true</code> if the tiddler is a <em>'fat'</em> dependency (ie the text is included in some way) or <code>false</code> if the tiddler is a <em><code>skinny</code></em> dependency.<br><br>The <code>dependentAll</code> field is used to indicate that the tiddler contains a macro that scans the entire pool of tiddlers (for example the <code>&lt;&lt;list&gt;&gt;</code> macro), and is potentially dependent on any of them. The effect is that the tiddler should be rerendered whenever any other tiddler changes.<br><h2> Rendering</h2>The <code>parseTree.compile(type)</code> method returns a renderer object that contains a JavaScript function that generates the new representation of the original parsed text.<br><br>The renderer is invoked as follows:<br><pre class='javascript-source'><span class='javascript-keyword'>var</span> <span class='javascript-identifier'>renderer</span> <span class='javascript-punctuator'>=</span> <span class='javascript-identifier'>parseTree</span><span class='javascript-punctuator'>.</span><span class='javascript-identifier'>compile</span><span class='javascript-punctuator'>(</span><span class='javascript-string'>&quot;text/html&quot;</span><span class='javascript-punctuator'>)</span><span class='javascript-punctuator'>;</span>
<span class='javascript-keyword'>var</span> <span class='javascript-identifier'>html</span> <span class='javascript-punctuator'>=</span> <span class='javascript-identifier'>renderer</span><span class='javascript-punctuator'>.</span><span class='javascript-identifier'>render</span><span class='javascript-punctuator'>(</span><span class='javascript-identifier'>tiddler</span><span class='javascript-punctuator'>,</span><span class='javascript-identifier'>store</span><span class='javascript-punctuator'>)</span><span class='javascript-punctuator'>;</span>
</pre>The <code>tiddler</code> parameter to the <code>render</code> method identifies the tiddler that is acting as the context for this rendering &mdash; for example, it provides the fields displayed by the <code>&lt;&lt;view&gt;&gt;</code> macro. The <code>store</code> parameter is used to resolve any references to other tiddlers.<br><h2> Rerendering</h2>When rendering to the HTML/SVG DOM in the browser, TiddlyWiki5 also allows a previous rendering to be selectively updated in response to changes in dependent tiddlers. At the moment, only the WikiTextRenderer supports rerendering.<br><br>The rerender method on the renderer is called as follows:<br><pre>var node = document.getElementById(&quot;myNode&quot;);
var renderer = parseTree.compile(&quot;text/html&quot;);
myNode.innerHTML = renderer.render(tiddler,store);
// And then, later:
renderer.rerender(node,changes,tiddler,store,renderStep);
</pre>The parameters to <code>rerender()</code> are:<br><table class='table'><tbody><tr class='evenRow'><th align='left'>Name</th><th align='left'>Description</th></tr><tr class='oddRow'><td align='left'>node</td><td align='left'>A reference to the DOM node containing the rendering to be rerendered</td></tr><tr class='evenRow'><td align='left'>changes</td><td align='left'>A hashmap of <code>{title: &quot;created|modified|deleted&quot;}</code> indicating which tiddlers have changed since the original rendering</td></tr><tr class='oddRow'><td align='left'>tiddler</td><td align='left'>The tiddler providing the rendering context</td></tr><tr class='evenRow'><td align='left'>store</td><td align='left'>The store to use for resolving references to other tiddlers</td></tr><tr class='oddRow'><td align='left'>renderStep</td><td align='left'>See below</td></tr></tbody></table>Currently, the only macro that supports rerendering is the <code>&lt;&lt;story&gt;&gt;</code> macro; all other macros are rerendered by calling the ordinary <code>render()</code> method again. The reason that the <code>&lt;&lt;story&gt;&gt;</code> macro goes to the trouble of having a <code>rerender()</code> method is so that it can be carefully selective about not disturbing tiddlers in the DOM that aren't affected by the change. If there were, for instance, a video playing in one of the open tiddlers it would be reset to the beginning if the tiddler were rerendered.<br><br><br></div><br><h1>Planned WikiText Features</h1><div data-tiddler-target='NewWikiTextFeatures' data-tiddler-template='NewWikiTextFeatures' class='tw-tiddler-frame'>It is proposed to extend the existing TiddlyWiki WikiText syntax with the following extensions<br><br><ol><li> Addition of <code>**bold**</code> character formatting</li><li> Addition of <code>`backtick for code`</code> character formatting</li><li> Addition of WikiCreole-style forced line break, e.g. <code>force\\linebreak</code></li><li> Addition of WikiCreole-style headings, e.g. <code>==Heading</code></li><li> Addition of WikiCreole-style headings in tables, e.g. <code>|=|=table|=header|</code></li><li> Addition of white-listed HTML and SVG tags intermixed with wikitext</li><li> Addition of WikiCreole-style pretty links, e.g. <code>[[description -&gt; link]]</code></li><li> Addition of multiline macros, e.g.</li></ol><pre>&lt;&lt;myMacro
param1: Parameter value
param2: value
&quot;unnamed parameter&quot;
param4: ((
A multiline parameter that can go on for as long as it likes
and contain linebreaks.
))
&gt;&gt;
</pre><ol><li> Addition of typed text blocks, e.g.</li></ol><pre> $$$.js
return &quot;This will have syntax highlighting applied&quot;
$$$
</pre></div><br><br><em>This <code>readme</code> file was automatically generated by TiddlyWiki5</em><br></div>