mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Fix the datauri macro to work with _canonical_uri tiddlers
This commit is contained in:
parent
6f4daa70e1
commit
091bcfce7d
@ -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);
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -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("");
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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">>
|
||||
|
Loading…
Reference in New Issue
Block a user