mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Text-slicer update
* Improved docs on the created structure * Added support for converting CSS classes as tags * Added display of tags within the toolbar
This commit is contained in:
parent
f443719223
commit
46087fd270
@ -1,8 +1,8 @@
|
||||
title: $:/plugins/tiddlywiki/text-slicer/docs
|
||||
|
||||
!! Text Slicing Approach
|
||||
!! Introduction
|
||||
|
||||
Individual tiddlers are created for each heading, paragraph and list item. They are linked together using TiddlyWiki's tagging mechanism.
|
||||
Individual tiddlers are created for each heading, paragraph and list item. They are linked together into a hierarchical outline using TiddlyWiki's tagging mechanism.
|
||||
|
||||
For example, consider a tiddler titled ''Example'' containing this simple text:
|
||||
|
||||
@ -24,3 +24,54 @@ It will be sliced up into:
|
||||
**** and a tiddler for each list item
|
||||
|
||||
These tiddlers are bound together using tagging: child tiddlers are tagged with the title of their parent, and the parent tiddler has a ''list'' field that lists each child in the correct order.
|
||||
|
||||
!! Slicing Process
|
||||
|
||||
Slicing generates the following component tiddlers:
|
||||
|
||||
!!! Headings
|
||||
|
||||
Tiddlers representing headings have the following fields:
|
||||
|
||||
* ''title'': the text of the heading (which must be unique)
|
||||
* ''text'': the text `<<display-heading-tiddler level:'h1'>>`, with the appropriate heading number
|
||||
* ''list'': ordered list of tiddlers tagged with this heading (i.e. the child headings, paragraphs and lists displayed under this heading)
|
||||
* ''tags'': tagged with the title of the parent heading
|
||||
** In addition, any CSS classes found in the HTML are converted into tags
|
||||
|
||||
!!! Paragraphs
|
||||
|
||||
Tiddlers representing paragraphs have the following fields:
|
||||
|
||||
* ''title'': an automatically generated unique title. See below
|
||||
* ''text'': the text of the paragraph
|
||||
* ''tags'': tagged with the title of the parent heading
|
||||
** In addition, any CSS classes found in the HTML are converted into tags
|
||||
|
||||
The automatically generated title is made up of concatenating the following elements:
|
||||
|
||||
* the word ''para''
|
||||
* a dash ''-''
|
||||
* the first few words of the paragraph (up to 40 characters), separated with dashes ''-''
|
||||
* if necessary, a space and a numerical index to make the title unique
|
||||
|
||||
For example, ''para-how-to-use-pentagonal-tiles 23''.
|
||||
|
||||
!!! Lists
|
||||
|
||||
Lists are represented by several tiddlers: one for the list itself, and one for each item in the list.
|
||||
|
||||
The tiddler representing the list itself has the following fields:
|
||||
|
||||
* ''title'': an automatically generated unique title
|
||||
* ''text'': the text `<<display-list-tiddler type:'ul'>>` with the appropriate list type ("ul" or "ol")
|
||||
* ''list'': ordered list of titles of tiddlers representing the items in this list
|
||||
* ''tags'': tagged with the title of the parent heading
|
||||
** In addition, any CSS classes found in the HTML are converted into tags
|
||||
|
||||
The tiddlers representing items within the list have the following fields:
|
||||
|
||||
* ''title'': an automatically generated unique title
|
||||
* ''text'': the text of the list item
|
||||
* ''tags'': tagged with the title of the tiddler representing the list itself
|
||||
|
||||
|
@ -95,7 +95,7 @@ Slicer.prototype.makeParagraphTitle = function(title,text) {
|
||||
// Accumulate the number of words that will fit
|
||||
var c = 0,
|
||||
s = "";
|
||||
while(c < words.length && (s.length + words[c].length + 1) < 20) {
|
||||
while(c < words.length && (s.length + words[c].length + 1) < 50) {
|
||||
s += "-" + words[c++];
|
||||
}
|
||||
return this.wiki.generateNewTitle("para" + s);
|
||||
@ -146,7 +146,7 @@ Slicer.prototype.sliceTiddler = function(title) {
|
||||
},
|
||||
processNodeList = function(domNodeList) {
|
||||
$tw.utils.each(domNodeList,function(domNode) {
|
||||
var parentTitle,
|
||||
var parentTitle, tags,
|
||||
text = domNode.textContent,
|
||||
nodeType = domNode.nodeType;
|
||||
if(nodeType === 1) {
|
||||
@ -154,23 +154,31 @@ Slicer.prototype.sliceTiddler = function(title) {
|
||||
if(tagName === "h1" || tagName === "h2" || tagName === "h3" || tagName === "h4") {
|
||||
if(!isBlank(text)) {
|
||||
parentTitle = popParentStackUntil(tagName);
|
||||
tags = [parentTitle];
|
||||
if(domNode.className.trim() !== "") {
|
||||
tags = tags.concat(domNode.className.split(" "));
|
||||
}
|
||||
addToList(parentTitle,text);
|
||||
parentStack.push({type: tagName, title: addTiddler({
|
||||
title: text,
|
||||
text: "<<display-heading-tiddler level:'" + tagName + "'>>",
|
||||
list: [],
|
||||
tags: [parentTitle]
|
||||
tags: tags
|
||||
})});
|
||||
}
|
||||
} else if(tagName === "ul" || tagName === "ol") {
|
||||
var listTitle = title + "-list-" + self.nextId();
|
||||
parentTitle = parentStack[parentStack.length - 1].title;
|
||||
tags = [parentTitle];
|
||||
if(domNode.className.trim() !== "") {
|
||||
tags = tags.concat(domNode.className.split(" "));
|
||||
}
|
||||
addToList(parentTitle,listTitle);
|
||||
parentStack.push({type: tagName, title: addTiddler({
|
||||
title: listTitle,
|
||||
text: "<<display-list-tiddler type:'" + tagName + "'>>",
|
||||
list: [],
|
||||
tags: [parentTitle]
|
||||
tags: tags
|
||||
})});
|
||||
processNodeList(domNode.childNodes);
|
||||
parentStack.pop();
|
||||
@ -178,21 +186,29 @@ Slicer.prototype.sliceTiddler = function(title) {
|
||||
if(!isBlank(text)) {
|
||||
var listItemTitle = title + "-listitem-" + self.nextId();
|
||||
parentTitle = parentStack[parentStack.length - 1].title;
|
||||
tags = [parentTitle];
|
||||
if(domNode.className.trim() !== "") {
|
||||
tags = tags.concat(domNode.className.split(" "));
|
||||
}
|
||||
addToList(parentTitle,listItemTitle);
|
||||
addTiddler({
|
||||
title: listItemTitle,
|
||||
text: text,
|
||||
list: [],
|
||||
tags: [parentTitle]
|
||||
tags: tags
|
||||
});
|
||||
}
|
||||
} else if(tagName === "p") {
|
||||
if(!isBlank(text)) {
|
||||
parentTitle = parentStack[parentStack.length - 1].title;
|
||||
tags = [parentTitle];
|
||||
if(domNode.className.trim() !== "") {
|
||||
tags = tags.concat(domNode.className.split(" "));
|
||||
}
|
||||
addToList(parentTitle,addTiddler({
|
||||
title: self.makeParagraphTitle(title,text),
|
||||
text: text,
|
||||
tags: [parentTitle]
|
||||
tags: tags
|
||||
}));
|
||||
}
|
||||
} else if(domNode.hasChildNodes()) {
|
||||
|
@ -1,3 +1,3 @@
|
||||
title: $:/tags/TextSlicerToolbar
|
||||
list: $:/plugins/tiddlywiki/text-slicer/toolbar/title $:/plugins/tiddlywiki/text-slicer/toolbar/rename $:/plugins/tiddlywiki/text-slicer/toolbar/edit $:/plugins/tiddlywiki/text-slicer/toolbar/cancel $:/plugins/tiddlywiki/text-slicer/toolbar/done
|
||||
list: $:/plugins/tiddlywiki/text-slicer/toolbar/title $:/plugins/tiddlywiki/text-slicer/toolbar/tags $:/plugins/tiddlywiki/text-slicer/toolbar/rename $:/plugins/tiddlywiki/text-slicer/toolbar/edit $:/plugins/tiddlywiki/text-slicer/toolbar/cancel $:/plugins/tiddlywiki/text-slicer/toolbar/done
|
||||
|
||||
|
4
plugins/tiddlywiki/text-slicer/toolbar-tags.tid
Normal file
4
plugins/tiddlywiki/text-slicer/toolbar-tags.tid
Normal file
@ -0,0 +1,4 @@
|
||||
title: $:/plugins/tiddlywiki/text-slicer/toolbar/tags
|
||||
tags: $:/tags/TextSlicerToolbar
|
||||
|
||||
<span class="tc-tags-wrapper"><$list filter="[all[current]tags[]sort[title]]" template="$:/core/ui/TagTemplate" storyview="pop"/></span>
|
Loading…
Reference in New Issue
Block a user