mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +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
|
// Install the default link massager
|
||||||
this.store.linkMassager = function(linkInfo) {
|
this.store.linkMassager = function(linkInfo) {
|
||||||
if(!linkInfo.isExternal) {
|
if(!linkInfo.isExternal) {
|
||||||
linkInfo.to = encodeURIComponent(linkInfo.to);
|
linkInfo.attributes.href = encodeURIComponent(linkInfo.to);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Set up for the browser
|
// Set up for the browser
|
||||||
|
@ -14,11 +14,20 @@ as follows:
|
|||||||
space: an optional space associated with the link
|
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
|
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
|
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
|
attributes: a hashmap of HTML attributes to add to the `<a>` tag
|
||||||
href: the href to be used in the link
|
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(){
|
(function(){
|
||||||
@ -65,29 +74,32 @@ exports.macro = {
|
|||||||
if(!linkInfo.isExternal) {
|
if(!linkInfo.isExternal) {
|
||||||
linkInfo.isMissing = !this.store.tiddlerExists(linkInfo.to);
|
linkInfo.isMissing = !this.store.tiddlerExists(linkInfo.to);
|
||||||
}
|
}
|
||||||
linkInfo.href = encodeURIComponent(linkInfo.to);
|
linkInfo.attributes = {
|
||||||
|
href: linkInfo.to
|
||||||
|
};
|
||||||
// Generate the default classes for the link
|
// Generate the default classes for the link
|
||||||
linkInfo.classes = ["tw-tiddlylink"];
|
linkInfo.attributes.classes = ["tw-tiddlylink"];
|
||||||
if(linkInfo.isExternal) {
|
if(linkInfo.isExternal) {
|
||||||
linkInfo.classes.push("tw-tiddlylink-external");
|
linkInfo.attributes.classes.push("tw-tiddlylink-external");
|
||||||
} else {
|
} else {
|
||||||
linkInfo.classes.push("tw-tiddlylink-internal");
|
linkInfo.attributes.classes.push("tw-tiddlylink-internal");
|
||||||
if(linkInfo.isMissing) {
|
if(linkInfo.isMissing) {
|
||||||
linkInfo.classes.push("tw-tiddlylink-missing");
|
linkInfo.attributes.classes.push("tw-tiddlylink-missing");
|
||||||
} else {
|
} else {
|
||||||
linkInfo.classes.push("tw-tiddlylink-resolves");
|
linkInfo.attributes.classes.push("tw-tiddlylink-resolves");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Invoke the link massager if defined
|
// Invoke the link massager if defined
|
||||||
if(this.store.linkMassager) {
|
if(this.store.linkMassager) {
|
||||||
this.store.linkMassager(linkInfo);
|
this.store.linkMassager(linkInfo);
|
||||||
}
|
}
|
||||||
// Figure out the classes to assign to the link
|
// Create the link
|
||||||
var content = [Renderer.ElementNode(
|
var content;
|
||||||
"a",{
|
if(linkInfo.suppressLink) {
|
||||||
href: linkInfo.href,
|
content = this.cloneChildren();
|
||||||
"class": linkInfo.classes
|
} else {
|
||||||
},this.cloneChildren())];
|
content = [Renderer.ElementNode("a",linkInfo.attributes,this.cloneChildren())];
|
||||||
|
}
|
||||||
for(var t=0; t<content.length; t++) {
|
for(var t=0; t<content.length; t++) {
|
||||||
content[t].execute(this.parents,this.tiddlerTitle);
|
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: {
|
savewiki: {
|
||||||
args: {min: 1, max: 1},
|
args: {min: 1, max: 1},
|
||||||
handler: function(args,callback) {
|
handler: function(args,callback) {
|
||||||
@ -284,6 +300,9 @@ var processNextSwitch = function() {
|
|||||||
if(currSwitch < switches.length) {
|
if(currSwitch < switches.length) {
|
||||||
var s = switches[currSwitch++],
|
var s = switches[currSwitch++],
|
||||||
csw = commandLineSwitches[s.switchName];
|
csw = commandLineSwitches[s.switchName];
|
||||||
|
if(!csw) {
|
||||||
|
throw "Unknown command line switch --" + s.switchName;
|
||||||
|
}
|
||||||
if(s.args.length < csw.args.min) {
|
if(s.args.length < csw.args.min) {
|
||||||
throw "Command line switch --" + s.switchName + " should have a minimum of " + csw.args.min + " arguments";
|
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 |
|
|`--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 |
|
|`--load <filepath>` |Load additional tiddlers from 2.x.x TiddlyWiki files (`.html`), `.tiddler`, `.tid`, `.json` or other files |
|
||||||
|`--store <dirpath>` |Load a specified TiddlerFileStore |
|
|`--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 |
|
|`--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` |
|
|`--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 |
|
|`--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.
|
`--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.
|
`--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
|
mkdir -p tmp/tw5
|
||||||
|
|
||||||
# cook TiddlyWiki5
|
# 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
|
# cook a static version too
|
||||||
#mkdir -p tmp/tw5/static
|
#mkdir -p tmp/tw5/static
|
||||||
|
Loading…
Reference in New Issue
Block a user