diff --git a/core/modules/macros/makedatauri.js b/core/modules/macros/makedatauri.js index a7474bdf0..0ff862df1 100644 --- a/core/modules/macros/makedatauri.js +++ b/core/modules/macros/makedatauri.js @@ -22,14 +22,15 @@ exports.name = "makedatauri"; exports.params = [ {name: "text"}, - {name: "type"} + {name: "type"}, + {name: "_canonical_uri"} ]; /* Run the macro */ -exports.run = function(text,type) { - return $tw.utils.makeDataUri(text,type); +exports.run = function(text,type,_canonical_uri) { + return $tw.utils.makeDataUri(text,type,_canonical_uri); }; })(); diff --git a/core/modules/utils/utils.js b/core/modules/utils/utils.js index 2495be49f..26fed0f3c 100644 --- a/core/modules/utils/utils.js +++ b/core/modules/utils/utils.js @@ -728,16 +728,20 @@ exports.timer = function(base) { /* Convert text and content type to a data URI */ -exports.makeDataUri = function(text,type) { +exports.makeDataUri = function(text,type,_canonical_uri) { type = type || "text/vnd.tiddlywiki"; var typeInfo = $tw.config.contentTypeInfo[type] || $tw.config.contentTypeInfo["text/plain"], isBase64 = typeInfo.encoding === "base64", parts = []; - parts.push("data:"); - parts.push(type); - parts.push(isBase64 ? ";base64" : ""); - parts.push(","); - parts.push(isBase64 ? text : encodeURIComponent(text)); + if(_canonical_uri) { + parts.push(_canonical_uri); + } else { + parts.push("data:"); + parts.push(type); + parts.push(isBase64 ? ";base64" : ""); + parts.push(","); + parts.push(isBase64 ? text : encodeURIComponent(text)); + } return parts.join(""); }; diff --git a/core/wiki/macros/CSS.tid b/core/wiki/macros/CSS.tid index 563f917a9..9e6239e90 100644 --- a/core/wiki/macros/CSS.tid +++ b/core/wiki/macros/CSS.tid @@ -60,7 +60,7 @@ column-count: $columns$; \end \define datauri(title) -<$macrocall $name="makedatauri" type={{$title$!!type}} text={{$title$}}/> +<$macrocall $name="makedatauri" type={{$title$!!type}} text={{$title$}} _canonical_uri={{$title$!!_canonical_uri}}/> \end \define if-sidebar(text) diff --git a/editions/tw5.com/tiddlers/macros/MakeDataUriMacro.tid b/editions/tw5.com/tiddlers/macros/MakeDataUriMacro.tid index ba26e4c4d..4ef300af2 100644 --- a/editions/tw5.com/tiddlers/macros/MakeDataUriMacro.tid +++ b/editions/tw5.com/tiddlers/macros/MakeDataUriMacro.tid @@ -1,5 +1,5 @@ created: 20131228163141555 -modified: 20150221223416000 +modified: 20200330105334133 tags: Macros [[Core Macros]] title: makedatauri Macro type: text/vnd.tiddlywiki @@ -15,5 +15,7 @@ The <<.def makedatauri>> [[macro|Macros]] takes a piece of text and an associate : The text to be converted to a data URI ;type : The ContentType of the text +;_canonical_uri +: The optional ''_canonical_uri'' address of the content <<.macro-examples "makedatauri">>