mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-04 13:19:11 +00:00
Added image rule
This commit is contained in:
parent
c6a2083e26
commit
ec342ed245
59
core/modules/parsers/newwikitextparser/rules/image.js
Normal file
59
core/modules/parsers/newwikitextparser/rules/image.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/parsers/newwikitextparser/rules/image.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: wikitextrule
|
||||||
|
|
||||||
|
Wiki text run rule for pretty links
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.name = "image";
|
||||||
|
|
||||||
|
exports.runParser = true;
|
||||||
|
|
||||||
|
exports.regExpString = "\\[(?:[<>]?)[Ii][Mm][Gg]\\[(?:(?:[^\\|\\]]+)\\|)?(?:[^\\[\\]\\|]+)\\](?:\\[(?:[^\\]]*)\\])?\\]";
|
||||||
|
|
||||||
|
exports.parse = function(match,isBlock) {
|
||||||
|
var regExp = /\[([<>]?)[Ii][Mm][Gg]\[(?:([^\|\]]+)\|)?([^\[\]\|]+)\](?:\[([^\]]*)\])?\]/mg;
|
||||||
|
regExp.lastIndex = this.pos;
|
||||||
|
match = regExp.exec(this.source);
|
||||||
|
if(match && match.index === this.pos) {
|
||||||
|
this.pos = match.index + match[0].length;
|
||||||
|
var srcParams = {};
|
||||||
|
if(match[1] === "<") {
|
||||||
|
srcParams.alignment = "left";
|
||||||
|
} else if(match[1] === ">") {
|
||||||
|
srcParams.alignment = "right";
|
||||||
|
}
|
||||||
|
if(match[2]) {
|
||||||
|
srcParams.text = match[2];
|
||||||
|
}
|
||||||
|
if(match[3]) {
|
||||||
|
srcParams.src = match[3];
|
||||||
|
}
|
||||||
|
var imageMacroNode = $tw.Tree.Macro("image",{
|
||||||
|
srcParams: srcParams,
|
||||||
|
wiki: this.wiki
|
||||||
|
});
|
||||||
|
this.dependencies.mergeDependencies(imageMacroNode.dependencies);
|
||||||
|
if(match[4]) {
|
||||||
|
var linkMacroNode = $tw.Tree.Macro("link",{
|
||||||
|
srcParams: {to: match[4]},
|
||||||
|
content: [imageMacroNode],
|
||||||
|
wiki: this.wiki
|
||||||
|
});
|
||||||
|
this.dependencies.mergeDependencies(linkMacroNode.dependencies);
|
||||||
|
return [linkMacroNode];
|
||||||
|
} else {
|
||||||
|
return [imageMacroNode];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user