1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-06 13:56:45 +00:00

Mapped wiki image markup to image macro

This commit is contained in:
Jeremy Ruston 2012-01-16 08:58:51 +00:00
parent ac61e2d251
commit 9075b8a020
4 changed files with 52 additions and 32 deletions

View File

@ -507,7 +507,7 @@ var rules = [
} }
if(w.autoLinkWikiWords) { if(w.autoLinkWikiWords) {
var link = {type: "macro", name: "link", params: { var link = {type: "macro", name: "link", params: {
target: {type: "string", value: w.matchText}, target: {type: "string", value: w.matchText}
}, },
children: [{ children: [{
type: "text", type: "text",
@ -546,27 +546,29 @@ var rules = [
handler: function(w) handler: function(w)
{ {
this.lookaheadRegExp.lastIndex = w.matchStart; this.lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = this.lookaheadRegExp.exec(w.source); var lookaheadMatch = this.lookaheadRegExp.exec(w.source),
image = {type: "macro", name: "image", params: {
src: {type: "string", value: ""}
}},
link = {type: "macro", name: "link", params: {
target: {type: "string", value: ""}
}, children: [image]};
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) { if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
var e = w.output; if(lookaheadMatch[1]) {
if(lookaheadMatch[5]) { image.params.alignment = {type: "string", value: "left"};
var link = lookaheadMatch[5], } else if(lookaheadMatch[2]) {
t = {type: "a", children: []}; image.params.alignment = {type: "string", value: "right"};
setAttr(t,"href",link);
w.output.push(t);
e = t.children;
} }
var img = {type: "img"};
e.push(img);
if(lookaheadMatch[1])
setAttr(img,"align","left");
else if(lookaheadMatch[2])
setAttr(img,"align","right");
if(lookaheadMatch[3]) { if(lookaheadMatch[3]) {
setAttr(img,"title",lookaheadMatch[3]); image.params.text = {type: "string", value: lookaheadMatch[3]};
setAttr(img,"alt",lookaheadMatch[3]); }
image.params.src.value = lookaheadMatch[4];
if(lookaheadMatch[5]) {
link.params.target.value = lookaheadMatch[5];
w.output.push(link);
} else {
w.output.push(image);
} }
setAttr(img,"src",lookaheadMatch[4]);
w.nextMatch = this.lookaheadRegExp.lastIndex; w.nextMatch = this.lookaheadRegExp.lastIndex;
} }
} }
@ -605,7 +607,7 @@ var rules = [
match: "''|//|__|\\^\\^|~~|--(?!\\s|$)|\\{\\{\\{|`", match: "''|//|__|\\^\\^|~~|--(?!\\s|$)|\\{\\{\\{|`",
handler: function(w) handler: function(w)
{ {
var e; var e,lookaheadRegExp,lookaheadMatch;
switch(w.matchText) { switch(w.matchText) {
case "''": case "''":
e = {type: "strong", children: []}; e = {type: "strong", children: []};
@ -638,9 +640,9 @@ var rules = [
w.subWikifyTerm(e.children,/(--)/mg); w.subWikifyTerm(e.children,/(--)/mg);
break; break;
case "`": case "`":
var lookaheadRegExp = /`((?:.|\n)*?)`/mg; lookaheadRegExp = /`((?:.|\n)*?)`/mg;
lookaheadRegExp.lastIndex = w.matchStart; lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = lookaheadRegExp.exec(w.source); lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) { if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.output.push({type: "code", children: [ w.output.push({type: "code", children: [
{type: "text", value: lookaheadMatch[1]} {type: "text", value: lookaheadMatch[1]}
@ -649,9 +651,9 @@ var rules = [
} }
break; break;
case "{{{": case "{{{":
var lookaheadRegExp = /\{\{\{((?:.|\n)*?)\}\}\}/mg; lookaheadRegExp = /\{\{\{((?:.|\n)*?)\}\}\}/mg;
lookaheadRegExp.lastIndex = w.matchStart; lookaheadRegExp.lastIndex = w.matchStart;
var lookaheadMatch = lookaheadRegExp.exec(w.source); lookaheadMatch = lookaheadRegExp.exec(w.source);
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) { if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
w.output.push({type: "code", children: [ w.output.push({type: "code", children: [
{type: "text", value: lookaheadMatch[1]} {type: "text", value: lookaheadMatch[1]}

View File

@ -14,10 +14,23 @@ exports.macro = {
types: ["text/html","text/plain"], types: ["text/html","text/plain"],
params: { params: {
src: {byName: "default", type: "tiddler", optional: false}, src: {byName: "default", type: "tiddler", optional: false},
text: {byName: true, type: "text", optional: true} text: {byName: true, type: "text", optional: true},
alignment: {byName: true, type: "text", optional: true}
}, },
handler: function(type,tiddler,store,params) { handler: function(type,tiddler,store,params) {
if(type === "text/html") { if(type === "text/html") {
if(store.tiddlerExists(params.src)) {
if(params.text) {
return utils.stitchElement("div",{
alt: params.text,
title: params.text
},{
content: store.renderTiddler(type,params.src)
});
} else {
return store.renderTiddler(type,params.src);
}
} else {
return utils.stitchElement("img",{ return utils.stitchElement("img",{
href: params.src, href: params.src,
alt: params.text, alt: params.text,
@ -25,6 +38,7 @@ exports.macro = {
},{ },{
selfClosing: true selfClosing: true
}); });
}
} else if (type === "text/plain") { } else if (type === "text/plain") {
return params.text ? params.text : params.src; return params.text ? params.text : params.src;
} }

View File

@ -25,7 +25,7 @@ exports.macro = {
classNames: store.adjustClassesForLink([],params.target) classNames: store.adjustClassesForLink([],params.target)
}); });
} else if (type === "text/plain") { } else if (type === "text/plain") {
return ""; return content;
} }
} }
}; };

View File

@ -1,6 +1,10 @@
title: Introduction title: Introduction
<<tiddler [[Motovun Jack.jpg]]>> <<tiddler [[Motovun Jack.jpg]]>>
<<image [[Motovun Jack.jpg]] text:"A kitten">>
[img[Motovun Jack.jpg]]
[img[tooltip|Motovun Jack.jpg]]
[img[tooltip|Motovun Jack.jpg][http://google.com/]]
TiddlyWiki5 gains new capabilities through a [[completely rebuilt architecture|TiddlyWikiArchitecture]] using the latest features of HTML5 and node.js. It runs natively under node.js, and can also use its own components to construct a version of itself that works entirely within the browser, just as TiddlyWiki has always done. TiddlyWiki5 gains new capabilities through a [[completely rebuilt architecture|TiddlyWikiArchitecture]] using the latest features of HTML5 and node.js. It runs natively under node.js, and can also use its own components to construct a version of itself that works entirely within the browser, just as TiddlyWiki has always done.