mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Text-slicer: Improve image support
Previously we only worked with base64 data URI images; now we work with relative URLs as well.
This commit is contained in:
parent
112a8d95c5
commit
d9fd722e50
@ -15,20 +15,23 @@ Handle slicing img nodes
|
|||||||
exports.processImageNode = function(domNode,tagName) {
|
exports.processImageNode = function(domNode,tagName) {
|
||||||
if(domNode.nodeType === 1 && tagName === "img") {
|
if(domNode.nodeType === 1 && tagName === "img") {
|
||||||
var src = domNode.getAttribute("src");
|
var src = domNode.getAttribute("src");
|
||||||
if(src && src.substr(0,5) === "data:") {
|
if(src) {
|
||||||
var parts = src.toString().substr(5).split(";base64,"),
|
var containerTitle = this.getTopContainer(),
|
||||||
type = parts[0],
|
|
||||||
text = parts[1],
|
|
||||||
contentTypeInfo = $tw.config.contentTypeInfo[type],
|
|
||||||
containerTitle = this.getTopContainer(),
|
|
||||||
containerTiddler = this.getTiddler(containerTitle),
|
containerTiddler = this.getTiddler(containerTitle),
|
||||||
title = this.makeUniqueTitle("image " + containerTitle) + contentTypeInfo.extension,
|
title, tiddler = {
|
||||||
tiddler = {
|
|
||||||
title: title,
|
|
||||||
type: parts[0],
|
|
||||||
text: parts[1],
|
|
||||||
"toc-type": "image"
|
"toc-type": "image"
|
||||||
};
|
};
|
||||||
|
if(src.substr(0,5) === "data:") {
|
||||||
|
var parts = src.toString().substr(5).split(";base64,");
|
||||||
|
tiddler.type = parts[0];
|
||||||
|
tiddler.text = parts[1];
|
||||||
|
var contentTypeInfo = $tw.config.contentTypeInfo[tiddler.type] || {extension: ""};
|
||||||
|
title = this.makeUniqueTitle("image " + containerTitle) + contentTypeInfo.extension;
|
||||||
|
tiddler.title = title;
|
||||||
|
this.addTiddler(tiddler);
|
||||||
|
} else {
|
||||||
|
title = $tw.utils.resolvePath(src,this.baseTiddlerTitle);
|
||||||
|
}
|
||||||
switch(containerTiddler["toc-type"]) {
|
switch(containerTiddler["toc-type"]) {
|
||||||
case "document":
|
case "document":
|
||||||
// Make the image be the next child of the document
|
// Make the image be the next child of the document
|
||||||
@ -58,10 +61,9 @@ exports.processImageNode = function(domNode,tagName) {
|
|||||||
this.insertBeforeListItem(parentTitle,itemTitle,containerTitle);
|
this.insertBeforeListItem(parentTitle,itemTitle,containerTitle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.addTiddler(tiddler);
|
|
||||||
// this.appendToCurrentContainer("[img[" + title + "]]");
|
// this.appendToCurrentContainer("[img[" + title + "]]");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user