From 6b14969cf60bdcad16ac5978030bf1d929a712c6 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Fri, 18 May 2018 17:53:07 +0100 Subject: [PATCH] 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. --- boot/boot.js | 1 + core/modules/parsers/binaryparser.js | 29 ++++++++++++++++++++++++++++ core/modules/wiki.js | 10 +++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 core/modules/parsers/binaryparser.js diff --git a/boot/boot.js b/boot/boot.js index bb06047b3..d6647884d 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -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 diff --git a/core/modules/parsers/binaryparser.js b/core/modules/parsers/binaryparser.js new file mode 100644 index 000000000..ebfd2beec --- /dev/null +++ b/core/modules/parsers/binaryparser.js @@ -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; + +})(); + diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 0f4219ac3..e73ed8362 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -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; }