mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-08 15:10:02 +00:00
Text-slicer: Improvements to image handling
This commit is contained in:
parent
1fef272388
commit
e2d63a03b2
File diff suppressed because one or more lines are too long
@ -50,6 +50,18 @@ Slicer.prototype.addToList = function(parent,child) {
|
|||||||
this.addTiddler($tw.utils.extend({title: parent},parentTiddler,{list: parentList}));
|
this.addTiddler($tw.utils.extend({title: parent},parentTiddler,{list: parentList}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Slicer.prototype.insertBeforeListItem = function(parent,child,beforeSibling) {
|
||||||
|
var parentTiddler = this.tiddlers[parent] || {},
|
||||||
|
parentList = parentTiddler.list || [],
|
||||||
|
parentListSiblingPosition = parentList.indexOf(beforeSibling);
|
||||||
|
if(parentListSiblingPosition !== -1) {
|
||||||
|
parentList.splice(parentListSiblingPosition,0,child)
|
||||||
|
this.addTiddler($tw.utils.extend({title: parent},parentTiddler,{list: parentList}));
|
||||||
|
}
|
||||||
|
|
||||||
|
else {debugger;}
|
||||||
|
};
|
||||||
|
|
||||||
Slicer.prototype.popParentStackUntil = function(type) {
|
Slicer.prototype.popParentStackUntil = function(type) {
|
||||||
// Pop the stack to remove any entries at the same or lower level
|
// Pop the stack to remove any entries at the same or lower level
|
||||||
var newLevel = this.convertTypeToLevel(type),
|
var newLevel = this.convertTypeToLevel(type),
|
||||||
@ -173,7 +185,7 @@ Slicer.prototype.processNode = function(domNode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!hasProcessed) {
|
if(!hasProcessed) {
|
||||||
if(domNode.hasChildNodes()) {
|
if(nodeType === 1 && domNode.hasChildNodes()) {
|
||||||
this.processNodeList(domNode.childNodes);
|
this.processNodeList(domNode.childNodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,42 @@ exports.processImageNode = function(domNode,tagName) {
|
|||||||
var src = domNode.getAttribute("src");
|
var src = domNode.getAttribute("src");
|
||||||
if(src && src.substr(0,5) === "data:") {
|
if(src && src.substr(0,5) === "data:") {
|
||||||
var parts = src.toString().substr(5).split(";base64,"),
|
var parts = src.toString().substr(5).split(";base64,"),
|
||||||
|
type = parts[0],
|
||||||
|
text = parts[1],
|
||||||
|
contentTypeInfo = $tw.config.contentTypeInfo[type],
|
||||||
containerTitle = this.getTopContainer(),
|
containerTitle = this.getTopContainer(),
|
||||||
title = this.makeUniqueTitle("image",containerTitle);
|
containerTiddler = this.tiddlers[containerTitle],
|
||||||
this.addTiddler({
|
title = this.makeUniqueTitle("image",containerTitle) + contentTypeInfo.extension,
|
||||||
title: title,
|
tiddler = {
|
||||||
type: parts[0],
|
title: title,
|
||||||
text: parts[1]
|
type: parts[0],
|
||||||
});
|
text: parts[1],
|
||||||
this.appendToCurrentContainer("[img[" + title + "]]");
|
"toc-type": "image"
|
||||||
|
};
|
||||||
|
switch(containerTiddler["toc-type"]) {
|
||||||
|
case "document":
|
||||||
|
// Make the image be the next child of the document
|
||||||
|
this.addToList(containerTitle,title);
|
||||||
|
break;
|
||||||
|
case "heading":
|
||||||
|
// Make the image be the older sibling of the heading
|
||||||
|
var parentTitle = this.parentStack[this.parentStack.length - 2].title;
|
||||||
|
this.insertBeforeListItem(parentTitle,title,containerTitle);
|
||||||
|
break;
|
||||||
|
case "paragraph":
|
||||||
|
// Make the image be the older sibling of the paragraph
|
||||||
|
var parentTitle = this.parentStack[this.parentStack.length - 1].title;
|
||||||
|
this.insertBeforeListItem(parentTitle,title,containerTitle);
|
||||||
|
break;
|
||||||
|
case "item":
|
||||||
|
// Create a new older sibling item to contain the image
|
||||||
|
var parentTitle = this.parentStack[this.parentStack.length - 1].title;
|
||||||
|
tiddler["toc-type"] = "item";
|
||||||
|
this.insertBeforeListItem(parentTitle,title,containerTitle);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.addTiddler(tiddler);
|
||||||
|
// this.appendToCurrentContainer("[img[" + title + "]]");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
title: $:/plugins/tiddlywiki/text-slicer/templates/interactive/image
|
||||||
|
|
||||||
|
\define body()
|
||||||
|
<$link tag="div" class="tc-document-tiddler-link tc-document-tiddler">
|
||||||
|
|
||||||
|
<$list filter="""[all[current]] $(tv-exclude-filter)$ +[limit[1]]""" variable="item">
|
||||||
|
|
||||||
|
<$transclude/>
|
||||||
|
|
||||||
|
</$list>
|
||||||
|
|
||||||
|
</$link>
|
||||||
|
\end
|
||||||
|
|
||||||
|
<<body>>
|
@ -23,3 +23,7 @@ title: $:/plugins/tiddlywiki/text-slicer/templates/interactive/tiddler
|
|||||||
<$reveal type="match" state="!!toc-type" text="item">
|
<$reveal type="match" state="!!toc-type" text="item">
|
||||||
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/interactive/item" mode="block"/>
|
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/interactive/item" mode="block"/>
|
||||||
</$reveal>
|
</$reveal>
|
||||||
|
|
||||||
|
<$reveal type="match" state="!!toc-type" text="image">
|
||||||
|
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/interactive/image" mode="block"/>
|
||||||
|
</$reveal>
|
||||||
|
3
plugins/tiddlywiki/text-slicer/templates/plain/image.tid
Normal file
3
plugins/tiddlywiki/text-slicer/templates/plain/image.tid
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
title: $:/plugins/tiddlywiki/text-slicer/templates/plain/image
|
||||||
|
|
||||||
|
<$transclude/>
|
@ -22,4 +22,8 @@ title: $:/plugins/tiddlywiki/text-slicer/templates/plain/tiddler
|
|||||||
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/plain/item" mode="block"/>
|
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/plain/item" mode="block"/>
|
||||||
</$list>
|
</$list>
|
||||||
|
|
||||||
|
<$list filter="[<toc-type>prefix[image]]" variable="item">
|
||||||
|
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/plain/image" mode="block"/>
|
||||||
|
</$list>
|
||||||
|
|
||||||
</$vars>
|
</$vars>
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
title: $:/plugins/tiddlywiki/text-slicer/templates/static/image
|
||||||
|
|
||||||
|
`<img src="data:`<$view format="text" field="type"/>`;base64,`<$view format="text" field="text"/>`">`
|
@ -32,4 +32,10 @@ title: $:/plugins/tiddlywiki/text-slicer/templates/static/tiddler
|
|||||||
|
|
||||||
</$list>
|
</$list>
|
||||||
|
|
||||||
|
<$list filter="[<toc-type>prefix[image]]" variable="item">
|
||||||
|
|
||||||
|
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/static/image" mode="block"/>
|
||||||
|
|
||||||
|
</$list>
|
||||||
|
|
||||||
</$vars>
|
</$vars>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user