1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Added support for JPEG and PNG bitmap tiddlers

This commit is contained in:
Jeremy Ruston 2012-01-12 21:48:24 +00:00
parent ecabcd676b
commit ecfbaaa564
7 changed files with 56 additions and 1 deletions

View File

@ -16,6 +16,7 @@ var WikiStore = require("./WikiStore.js").WikiStore,
WikiTextParser = require("./WikiTextParser.js").WikiTextParser, WikiTextParser = require("./WikiTextParser.js").WikiTextParser,
JavaScriptParser = require("./JavaScriptParser.js").JavaScriptParser, JavaScriptParser = require("./JavaScriptParser.js").JavaScriptParser,
SVGParser = require("./SVGParser.js").SVGParser, SVGParser = require("./SVGParser.js").SVGParser,
BitmapParser = require("./BitmapParser.js").BitmapParser,
Navigators = require("./Navigators.js").Navigators, Navigators = require("./Navigators.js").Navigators,
StoryNavigator = require("./StoryNavigator.js").StoryNavigator; StoryNavigator = require("./StoryNavigator.js").StoryNavigator;
@ -30,6 +31,10 @@ var App = function() {
store: this.store store: this.store
})); }));
this.store.registerParser("image/svg+xml",new SVGParser()); this.store.registerParser("image/svg+xml",new SVGParser());
var bitmapParser = new BitmapParser();
this.store.registerParser("image/jpg",bitmapParser);
this.store.registerParser("image/jpeg",bitmapParser);
this.store.registerParser("image/png",bitmapParser);
// Register the standard tiddler serializers and deserializers // Register the standard tiddler serializers and deserializers
tiddlerInput.register(this.store); tiddlerInput.register(this.store);
tiddlerOutput.register(this.store); tiddlerOutput.register(this.store);

34
js/BitmapParser.js Normal file
View File

@ -0,0 +1,34 @@
/*\
title: js/BitmapParser.js
Compiles bitmap images into JavaScript functions that render them in HTML
\*/
(function(){
/*jslint node: true */
"use strict";
// The parse tree is degenerate
var BitmapParseTree = function() {
this.dependencies = [];
};
BitmapParseTree.prototype.compile = function(type) {
if(type === "text/html") {
return "(function (tiddler,store,utils) {return '<img src=\"data:' + tiddler.fields.type + ';base64,' + tiddler.fields.text + '\">';})";
} else {
return null;
}
};
var BitmapParser = function() {
};
BitmapParser.prototype.parse = function() {
return new BitmapParseTree();
};
exports.BitmapParser = BitmapParser;
})();

View File

@ -19,7 +19,17 @@ var fs = require("fs"),
var FileRetriever = exports; var FileRetriever = exports;
var fileRequest = function fileRequest(filepath,callback) { var fileRequest = function fileRequest(filepath,callback) {
fs.readFile(filepath,"utf8", callback); fs.readFile(filepath, function (err,data) {
if(err) {
callback(err);
} else {
if([".jpg",".jpeg",".png"].indexOf(path.extname(filepath)) !== -1) {
callback(err,data.toString("base64"));
} else {
callback(err,data.toString("utf8"));
}
}
});
}; };
var httpRequest = function(fileurl,callback) { var httpRequest = function(fileurl,callback) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -0,0 +1,3 @@
title: Motovun Jack.jpg
type: image/jpg
source: http://www.flickr.com/photos/jermy/6292279493/in/photostream

View File

@ -7,6 +7,8 @@ tiddler: TiddlyWikiArchitecture.tid
tiddler: TiddlyWikiInternals.tid tiddler: TiddlyWikiInternals.tid
tiddler: NewWikiTextFeatures.tid tiddler: NewWikiTextFeatures.tid
tiddler: Motovun Jack.jpg
tiddler: SiteTitle.tid tiddler: SiteTitle.tid
tiddler: SiteSubtitle.tid tiddler: SiteSubtitle.tid

View File

@ -18,6 +18,7 @@ jsmodule: ../js/TiddlerInput.js
jsmodule: ../js/TiddlerOutput.js jsmodule: ../js/TiddlerOutput.js
jsmodule: ../js/WikiStore.js jsmodule: ../js/WikiStore.js
jsmodule: ../js/SVGParser.js jsmodule: ../js/SVGParser.js
jsmodule: ../js/BitmapParser.js
jsmodule: ../js/WikiTextParser.js jsmodule: ../js/WikiTextParser.js
jsmodule: ../js/WikiTextRules.js jsmodule: ../js/WikiTextRules.js
jsmodule: ../js/WikiTextParseTree.js jsmodule: ../js/WikiTextParseTree.js