1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 19:47:20 +00:00

Display a warning for binary tiddlers in view mode

The base64 data is currently parsed as wikitext, which is slow and unhelpful

We already display the same warning for binary tiddlers in edit mode.
This commit is contained in:
Jermolene 2018-05-18 17:53:07 +01:00
parent f0b7c9a3d5
commit 6b14969cf6
3 changed files with 39 additions and 1 deletions

View File

@ -2002,6 +2002,7 @@ $tw.boot.startup = function(options) {
$tw.utils.registerFileType("text/x-bibtex","utf8",".bib",{deserializerType:"application/x-bibtex"});
$tw.utils.registerFileType("application/x-bibtex","utf8",".bib");
$tw.utils.registerFileType("application/epub+zip","base64",".epub");
$tw.utils.registerFileType("application/octet-stream","base64",".octet-stream");
// Create the wiki store for the app
$tw.wiki = new $tw.Wiki();
// Install built in tiddler fields modules

View File

@ -0,0 +1,29 @@
/*\
title: $:/core/modules/parsers/binaryparser.js
type: application/javascript
module-type: parser
The video parser parses a video tiddler into an embeddable HTML element
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var BINARY_WARNING_MESSAGE = "$:/core/ui/BinaryWarning";
var BinaryParser = function(type,text,options) {
this.tree = [{
type: "transclude",
attributes: {
tiddler: {type: "string", value: BINARY_WARNING_MESSAGE}
}
}];
};
exports["application/octet-stream"] = BinaryParser;
})();

View File

@ -785,6 +785,14 @@ exports.initParsers = function(moduleType) {
}
}
});
// Use the generic binary parser for any binary types not registered so far
if($tw.Wiki.parsers["application/octet-stream"]) {
Object.keys($tw.config.contentTypeInfo).forEach(function(type) {
if(!$tw.utils.hop($tw.Wiki.parsers,type) && $tw.config.contentTypeInfo[type].encoding === "base64") {
$tw.Wiki.parsers[type] = $tw.Wiki.parsers["application/octet-stream"];
}
});
}
};
/*
@ -847,7 +855,7 @@ exports.parseTextReference = function(title,field,index,options) {
}
if(field === "text" || (!field && !index)) {
if(tiddler && tiddler.fields) {
return this.parseText(tiddler.fields.type || "text/vnd.tiddlywiki",tiddler.fields.text,options);
return this.parseText(tiddler.fields.type,tiddler.fields.text,options);
} else {
return null;
}