mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Refactored linkMassager mechanism
Now the link massager can control the HTML attributes of the link, and suppress it entirely if necessary. Using this new facility to generate a cleaner readme file for github
This commit is contained in:
parent
5d10e7b750
commit
af7b69e778
@ -102,7 +102,7 @@ var App = function() {
|
||||
// Install the default link massager
|
||||
this.store.linkMassager = function(linkInfo) {
|
||||
if(!linkInfo.isExternal) {
|
||||
linkInfo.to = encodeURIComponent(linkInfo.to);
|
||||
linkInfo.attributes.href = encodeURIComponent(linkInfo.to);
|
||||
}
|
||||
};
|
||||
// Set up for the browser
|
||||
|
@ -14,11 +14,20 @@ as follows:
|
||||
space: an optional space associated with the link
|
||||
isExternal: true if the link has been determined to be an external link by the default heuristics
|
||||
isMissing: true if a non-external link references a missing tiddler
|
||||
classes: an array of strings representing the CSS classes to be applied to the link. The default classes are already applied
|
||||
href: the href to be used in the link
|
||||
attributes: a hashmap of HTML attributes to add to the `<a>` tag
|
||||
suppressLink: see below
|
||||
}
|
||||
|
||||
The linkMassager can modify the `classes` and `href` fields as required.
|
||||
The link massager is called with the `attributes` hashmap initialised as follows:
|
||||
|
||||
{
|
||||
classes: an array of strings representing the CSS classes to be applied to the link. The default classes are already applieda according to whether the heuristics decide the tiddler is external or missing
|
||||
href: the href to be used in the link (defaults to the unencoded value of the `to` parameter)
|
||||
}
|
||||
|
||||
The linkMassager can modify the `classes` and `href` fields as required, and add additional HTML attributes, such as the `target` attribute.
|
||||
|
||||
The linkMassager can cause the link to be suppressed by setting the `linkInfo.suppressLink` to `true`. The content of the link will still be displayed.
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
@ -65,29 +74,32 @@ exports.macro = {
|
||||
if(!linkInfo.isExternal) {
|
||||
linkInfo.isMissing = !this.store.tiddlerExists(linkInfo.to);
|
||||
}
|
||||
linkInfo.href = encodeURIComponent(linkInfo.to);
|
||||
linkInfo.attributes = {
|
||||
href: linkInfo.to
|
||||
};
|
||||
// Generate the default classes for the link
|
||||
linkInfo.classes = ["tw-tiddlylink"];
|
||||
linkInfo.attributes.classes = ["tw-tiddlylink"];
|
||||
if(linkInfo.isExternal) {
|
||||
linkInfo.classes.push("tw-tiddlylink-external");
|
||||
linkInfo.attributes.classes.push("tw-tiddlylink-external");
|
||||
} else {
|
||||
linkInfo.classes.push("tw-tiddlylink-internal");
|
||||
linkInfo.attributes.classes.push("tw-tiddlylink-internal");
|
||||
if(linkInfo.isMissing) {
|
||||
linkInfo.classes.push("tw-tiddlylink-missing");
|
||||
linkInfo.attributes.classes.push("tw-tiddlylink-missing");
|
||||
} else {
|
||||
linkInfo.classes.push("tw-tiddlylink-resolves");
|
||||
linkInfo.attributes.classes.push("tw-tiddlylink-resolves");
|
||||
}
|
||||
}
|
||||
// Invoke the link massager if defined
|
||||
if(this.store.linkMassager) {
|
||||
this.store.linkMassager(linkInfo);
|
||||
}
|
||||
// Figure out the classes to assign to the link
|
||||
var content = [Renderer.ElementNode(
|
||||
"a",{
|
||||
href: linkInfo.href,
|
||||
"class": linkInfo.classes
|
||||
},this.cloneChildren())];
|
||||
// Create the link
|
||||
var content;
|
||||
if(linkInfo.suppressLink) {
|
||||
content = this.cloneChildren();
|
||||
} else {
|
||||
content = [Renderer.ElementNode("a",linkInfo.attributes,this.cloneChildren())];
|
||||
}
|
||||
for(var t=0; t<content.length; t++) {
|
||||
content[t].execute(this.parents,this.tiddlerTitle);
|
||||
}
|
||||
|
@ -117,6 +117,22 @@ var commandLineSwitches = {
|
||||
});
|
||||
}
|
||||
},
|
||||
links: {
|
||||
args: {min: 1, max: 1},
|
||||
handler: function(args,callback) {
|
||||
var type = args[0];
|
||||
app.store.linkMassager = function(linkInfo) {
|
||||
switch(type) {
|
||||
case "none":
|
||||
if(!linkInfo.isExternal) {
|
||||
linkInfo.suppressLink = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
process.nextTick(function() {callback(null);});
|
||||
}
|
||||
},
|
||||
savewiki: {
|
||||
args: {min: 1, max: 1},
|
||||
handler: function(args,callback) {
|
||||
@ -284,6 +300,9 @@ var processNextSwitch = function() {
|
||||
if(currSwitch < switches.length) {
|
||||
var s = switches[currSwitch++],
|
||||
csw = commandLineSwitches[s.switchName];
|
||||
if(!csw) {
|
||||
throw "Unknown command line switch --" + s.switchName;
|
||||
}
|
||||
if(s.args.length < csw.args.min) {
|
||||
throw "Command line switch --" + s.switchName + " should have a minimum of " + csw.args.min + " arguments";
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ The following options are available:
|
||||
|`--recipe <filepath>` |Loads a specfied `.recipe` file |
|
||||
|`--load <filepath>` |Load additional tiddlers from 2.x.x TiddlyWiki files (`.html`), `.tiddler`, `.tid`, `.json` or other files |
|
||||
|`--store <dirpath>` |Load a specified TiddlerFileStore |
|
||||
|`--links none` |Determines how links will be generated by subsequent options. See below for details |
|
||||
|`--savewiki <dirpath>` |Saves all the loaded tiddlers as a single file TiddlyWiki called `index.html` and an RSS feed called `index.xml` in a new directory of the specified name |
|
||||
|`--savetiddler <title> <filename> [<type>]` |Save an individual tiddler as a specified MIME type, defaults to `text/html` |
|
||||
|`--savetiddlers <outdir>` |Saves all the loaded tiddlers as `.tid` files in the specified directory |
|
||||
@ -49,3 +50,9 @@ node tiddlywiki.js --load mywiki.html --savetiddlers tmp/tiddlers
|
||||
`--servewiki` and `--servetiddlers` 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.
|
||||
|
||||
`--wikitest` looks for `*.tid` files in the specified folder. It then wikifies the tiddlers to both "text/plain" and "text/html" format and checks the results against the content of the `*.html` and `*.txt` files in the same directory.
|
||||
|
||||
`--links` controls the way that links are generated. Currently, the only option supported is:
|
||||
|
||||
`none`: Tiddler links are disabled
|
||||
|
||||
|
||||
|
8
tw5.sh
8
tw5.sh
@ -7,7 +7,13 @@ mkdir -p tmp
|
||||
mkdir -p tmp/tw5
|
||||
|
||||
# cook TiddlyWiki5
|
||||
node tiddlywiki.js --recipe $PWD/tiddlywiki5/tiddlywiki5.recipe --store tiddlywiki5/store --savewiki tmp/tw5 --savetiddler ReadMe readme.md || exit 1
|
||||
node tiddlywiki.js \
|
||||
--recipe $PWD/tiddlywiki5/tiddlywiki5.recipe \
|
||||
--store tiddlywiki5/store \
|
||||
--savewiki tmp/tw5 \
|
||||
--links none \
|
||||
--savetiddler ReadMe readme.md \
|
||||
|| exit 1
|
||||
|
||||
# cook a static version too
|
||||
#mkdir -p tmp/tw5/static
|
||||
|
Loading…
Reference in New Issue
Block a user