diff --git a/core/language/en-GB/EditTemplate.multids b/core/language/en-GB/EditTemplate.multids index e5625c351..e703907c6 100644 --- a/core/language/en-GB/EditTemplate.multids +++ b/core/language/en-GB/EditTemplate.multids @@ -1,5 +1,6 @@ title: $:/language/EditTemplate/ +Body/External/Hint: This is an external tiddler stored outside of the main TiddlyWiki file. You can edit the tags and fields but cannot directly edit the content itself Body/Hint: Use [[wiki text|http://tiddlywiki.com/static/WikiText.html]] to add formatting, images, and dynamic features Body/Placeholder: Type the text for this tiddler Body/Preview/Button/Hide: hide preview diff --git a/core/modules/parsers/imageparser.js b/core/modules/parsers/imageparser.js index db532f11f..709c50ad9 100644 --- a/core/modules/parsers/imageparser.js +++ b/core/modules/parsers/imageparser.js @@ -19,7 +19,12 @@ var ImageParser = function(type,text,options) { attributes: {} }, src; - if(text) { + if(options._canonical_uri) { + element.attributes.src = {type: "string", value: options._canonical_uri}; + if(type === "application/pdf" || type === ".pdf") { + element.tag = "embed"; + } + } else if(text) { if(type === "application/pdf" || type === ".pdf") { element.attributes.src = {type: "string", value: "data:application/pdf;base64," + text}; element.tag = "embed"; diff --git a/core/modules/widgets/image.js b/core/modules/widgets/image.js index 1ab024ef6..be2ea8b6f 100644 --- a/core/modules/widgets/image.js +++ b/core/modules/widgets/image.js @@ -56,20 +56,37 @@ ImageWidget.prototype.render = function(parent,nextSibling) { } else { // Check if it is an image tiddler if(this.wiki.isImageTiddler(this.imageSource)) { - // Render the appropriate element for the image type var type = tiddler.fields.type, - text = tiddler.fields.text; - switch(type) { - case "application/pdf": - tag = "embed"; - src = "data:application/pdf;base64," + text; - break; - case "image/svg+xml": - src = "data:image/svg+xml," + encodeURIComponent(text); - break; - default: - src = "data:" + type + ";base64," + text; - break; + text = tiddler.fields.text, + _canonical_uri = tiddler.fields._canonical_uri; + // If the tiddler has body text then it doesn't need to be lazily loaded + if(text) { + // Render the appropriate element for the image type + switch(type) { + case "application/pdf": + tag = "embed"; + src = "data:application/pdf;base64," + text; + break; + case "image/svg+xml": + src = "data:image/svg+xml," + encodeURIComponent(text); + break; + default: + src = "data:" + type + ";base64," + text; + break; + } + } else if(_canonical_uri) { + switch(type) { + case "application/pdf": + tag = "embed"; + src = _canonical_uri; + break; + case "image/svg+xml": + src = _canonical_uri; + break; + default: + src = _canonical_uri; + break; + } } } } diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 0bae67fca..8d142d8d0 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -711,6 +711,7 @@ Parse a block of text of a specified MIME type options: see below Options include: parseAsInline: if true, the text of the tiddler will be parsed as an inline run + _canonical_uri: optional string of the canonical URI of this content */ exports.old_parseText = function(type,text,options) { options = options || {}; @@ -728,7 +729,8 @@ exports.old_parseText = function(type,text,options) { // Return the parser instance return new Parser(type,text,{ parseAsInline: options.parseAsInline, - wiki: this + wiki: this, + _canonical_uri: options._canonical_uri }); }; @@ -736,11 +738,14 @@ exports.old_parseText = function(type,text,options) { Parse a tiddler according to its MIME type */ exports.old_parseTiddler = function(title,options) { - options = options || {}; + options = $tw.utils.extend({},options); var cacheType = options.parseAsInline ? "newInlineParseTree" : "newBlockParseTree", tiddler = this.getTiddler(title), self = this; return tiddler ? this.getCacheForTiddler(title,cacheType,function() { + if(tiddler.hasField("_canonical_uri")) { + options._canonical_uri = tiddler.fields._canonical_uri; + } return self.old_parseText(tiddler.fields.type,tiddler.fields.text,options); }) : null; }; diff --git a/core/ui/EditTemplate/body.tid b/core/ui/EditTemplate/body.tid index a5092e920..0c58fc600 100644 --- a/core/ui/EditTemplate/body.tid +++ b/core/ui/EditTemplate/body.tid @@ -1,10 +1,26 @@ title: $:/core/ui/EditTemplate/body tags: $:/tags/EditTemplate -\define lingo-base() $:/language/EditTemplate/ +\define lingo-base() $:/language/EditTemplate/Body/ +<$list filter="[is[current]has[_canonical_uri]]"> + +
+ +$list> + +<$list filter="[is[current]!has[_canonical_uri]]"> + <$reveal state="$:/state/showeditpreview" type="match" text="yes"> -<+ +<$view tiddler="$:/core/templates/canonical-uri" field="text" format="text"/> + ++ +Note that these operations modify the tiddlers in the wiki store and so may affect the operation of subsequent commands. + +! Using External Images + +You can't edit an external image directly in the browser except by changing the URI field to point to a different image. diff --git a/editions/tw5.com/tiddlers/widgets/ImageWidget.tid b/editions/tw5.com/tiddlers/widgets/ImageWidget.tid index f616ea97d..6f1e1a694 100644 --- a/editions/tw5.com/tiddlers/widgets/ImageWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ImageWidget.tid @@ -1,6 +1,6 @@ title: ImageWidget created: 20140416160234142 -modified: 20140416160234142 +modified: 20140611160234142 tags: widget ! Introduction @@ -18,3 +18,11 @@ Any content of the `<$image>` widget is ignored. |tooltip |The tooltip to be displayed over the image | |class |CSS classes to be assigned to the `` element | +! External Images and the ''_canonical_uri'' field + +When used to display tiddler-based images, the image widget operates in two distinct modes: + +* If the ''_canonical_uri'' field is present then it is used as the ''src'' attribute of the generated `` element and the ''text'' field is ignored +* Without the ''_canonical_uri'' field, the image widget generates an `` element that embeds the image data directly using a `data:` URI. + +See ExternalImages for more details. diff --git a/editions/tw5.com/tiddlywiki.info b/editions/tw5.com/tiddlywiki.info index 14ef45476..8cd612e84 100644 --- a/editions/tw5.com/tiddlywiki.info +++ b/editions/tw5.com/tiddlywiki.info @@ -30,6 +30,11 @@ "build": { "index": [ "--rendertiddler","$:/core/save/all","index.html","text/plain"], + "externalimages": [ + "--savetiddlers","[is[image]] [type[text/html]]","images", + "--setfield","[is[image]] [type[text/html]]","_canonical_uri","$:/core/templates/canonical-uri","text/plain", + "--setfield","[is[image]]","text","","text/plain", + "--rendertiddler","$:/core/save/all","externalimages.html","text/plain"], "encrypted": [ "--password", "password", "--rendertiddler", "$:/core/save/all", "encrypted.html", "text/plain",