mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-02 12:19:11 +00:00
Mapped wiki image markup to image macro
This commit is contained in:
parent
ac61e2d251
commit
9075b8a020
@ -507,7 +507,7 @@ var rules = [
|
||||
}
|
||||
if(w.autoLinkWikiWords) {
|
||||
var link = {type: "macro", name: "link", params: {
|
||||
target: {type: "string", value: w.matchText},
|
||||
target: {type: "string", value: w.matchText}
|
||||
},
|
||||
children: [{
|
||||
type: "text",
|
||||
@ -546,27 +546,29 @@ var rules = [
|
||||
handler: function(w)
|
||||
{
|
||||
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) {
|
||||
var e = w.output;
|
||||
if(lookaheadMatch[5]) {
|
||||
var link = lookaheadMatch[5],
|
||||
t = {type: "a", children: []};
|
||||
setAttr(t,"href",link);
|
||||
w.output.push(t);
|
||||
e = t.children;
|
||||
if(lookaheadMatch[1]) {
|
||||
image.params.alignment = {type: "string", value: "left"};
|
||||
} else if(lookaheadMatch[2]) {
|
||||
image.params.alignment = {type: "string", value: "right"};
|
||||
}
|
||||
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]) {
|
||||
setAttr(img,"title",lookaheadMatch[3]);
|
||||
setAttr(img,"alt",lookaheadMatch[3]);
|
||||
image.params.text = {type: "string", value: 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;
|
||||
}
|
||||
}
|
||||
@ -605,7 +607,7 @@ var rules = [
|
||||
match: "''|//|__|\\^\\^|~~|--(?!\\s|$)|\\{\\{\\{|`",
|
||||
handler: function(w)
|
||||
{
|
||||
var e;
|
||||
var e,lookaheadRegExp,lookaheadMatch;
|
||||
switch(w.matchText) {
|
||||
case "''":
|
||||
e = {type: "strong", children: []};
|
||||
@ -638,9 +640,9 @@ var rules = [
|
||||
w.subWikifyTerm(e.children,/(--)/mg);
|
||||
break;
|
||||
case "`":
|
||||
var lookaheadRegExp = /`((?:.|\n)*?)`/mg;
|
||||
lookaheadRegExp = /`((?:.|\n)*?)`/mg;
|
||||
lookaheadRegExp.lastIndex = w.matchStart;
|
||||
var lookaheadMatch = lookaheadRegExp.exec(w.source);
|
||||
lookaheadMatch = lookaheadRegExp.exec(w.source);
|
||||
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
||||
w.output.push({type: "code", children: [
|
||||
{type: "text", value: lookaheadMatch[1]}
|
||||
@ -649,9 +651,9 @@ var rules = [
|
||||
}
|
||||
break;
|
||||
case "{{{":
|
||||
var lookaheadRegExp = /\{\{\{((?:.|\n)*?)\}\}\}/mg;
|
||||
lookaheadRegExp = /\{\{\{((?:.|\n)*?)\}\}\}/mg;
|
||||
lookaheadRegExp.lastIndex = w.matchStart;
|
||||
var lookaheadMatch = lookaheadRegExp.exec(w.source);
|
||||
lookaheadMatch = lookaheadRegExp.exec(w.source);
|
||||
if(lookaheadMatch && lookaheadMatch.index == w.matchStart) {
|
||||
w.output.push({type: "code", children: [
|
||||
{type: "text", value: lookaheadMatch[1]}
|
||||
|
@ -14,17 +14,31 @@ exports.macro = {
|
||||
types: ["text/html","text/plain"],
|
||||
params: {
|
||||
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) {
|
||||
if(type === "text/html") {
|
||||
return utils.stitchElement("img",{
|
||||
href: params.src,
|
||||
alt: params.text,
|
||||
title: params.text
|
||||
},{
|
||||
selfClosing: true
|
||||
});
|
||||
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",{
|
||||
href: params.src,
|
||||
alt: params.text,
|
||||
title: params.text
|
||||
},{
|
||||
selfClosing: true
|
||||
});
|
||||
}
|
||||
} else if (type === "text/plain") {
|
||||
return params.text ? params.text : params.src;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ exports.macro = {
|
||||
classNames: store.adjustClassesForLink([],params.target)
|
||||
});
|
||||
} else if (type === "text/plain") {
|
||||
return "";
|
||||
return content;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,10 @@
|
||||
title: Introduction
|
||||
|
||||
<<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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user