1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 05:19:57 +00:00

Fix the datauri macro to work with _canonical_uri tiddlers

This commit is contained in:
Jeremy Ruston 2020-03-30 10:55:37 +01:00
parent 6f4daa70e1
commit 091bcfce7d
4 changed files with 18 additions and 11 deletions

View File

@ -22,14 +22,15 @@ exports.name = "makedatauri";
exports.params = [ exports.params = [
{name: "text"}, {name: "text"},
{name: "type"} {name: "type"},
{name: "_canonical_uri"}
]; ];
/* /*
Run the macro Run the macro
*/ */
exports.run = function(text,type) { exports.run = function(text,type,_canonical_uri) {
return $tw.utils.makeDataUri(text,type); return $tw.utils.makeDataUri(text,type,_canonical_uri);
}; };
})(); })();

View File

@ -728,16 +728,20 @@ exports.timer = function(base) {
/* /*
Convert text and content type to a data URI 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"; type = type || "text/vnd.tiddlywiki";
var typeInfo = $tw.config.contentTypeInfo[type] || $tw.config.contentTypeInfo["text/plain"], var typeInfo = $tw.config.contentTypeInfo[type] || $tw.config.contentTypeInfo["text/plain"],
isBase64 = typeInfo.encoding === "base64", isBase64 = typeInfo.encoding === "base64",
parts = []; parts = [];
parts.push("data:"); if(_canonical_uri) {
parts.push(type); parts.push(_canonical_uri);
parts.push(isBase64 ? ";base64" : ""); } else {
parts.push(","); parts.push("data:");
parts.push(isBase64 ? text : encodeURIComponent(text)); parts.push(type);
parts.push(isBase64 ? ";base64" : "");
parts.push(",");
parts.push(isBase64 ? text : encodeURIComponent(text));
}
return parts.join(""); return parts.join("");
}; };

View File

@ -60,7 +60,7 @@ column-count: $columns$;
\end \end
\define datauri(title) \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 \end
\define if-sidebar(text) \define if-sidebar(text)

View File

@ -1,5 +1,5 @@
created: 20131228163141555 created: 20131228163141555
modified: 20150221223416000 modified: 20200330105334133
tags: Macros [[Core Macros]] tags: Macros [[Core Macros]]
title: makedatauri Macro title: makedatauri Macro
type: text/vnd.tiddlywiki 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 : The text to be converted to a data URI
;type ;type
: The ContentType of the text : The ContentType of the text
;_canonical_uri
: The optional ''_canonical_uri'' address of the content
<<.macro-examples "makedatauri">> <<.macro-examples "makedatauri">>