1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-22 21:33:14 +00:00

Text-slicer: Add support for definition lists

This commit is contained in:
Evolena 2015-10-14 20:25:11 +02:00
parent 26d0029746
commit 0a220a09da
17 changed files with 298 additions and 0 deletions

View File

@ -104,6 +104,13 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor i
Dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<dl>
<dt>Term being defined</dt>
<dd>Definition of that term</dd>
<dt>Another term</dt>
<dd>Another definition</dd>
</dl>
<h3>Story</h3>
<ul class="intro">

View File

@ -144,6 +144,32 @@ The tiddlers representing items within the list have the following fields:
* ''text'': the text of the list item
* ''tags'': any CSS classes found in the HTML are converted into tags
!!! Definition lists
Definition lists are represented by several tiddlers: one for the definition list itself, and one for each term and definition in the list.
The tiddler representing the definition list itself has the following fields:
* ''toc-type'': the text "def-list"
* ''toc-list-filter'': the default filter used to generate the titles of the list-items
* ''title'': an automatically generated unique title
* ''list'': ordered list of titles of tiddlers representing the items (terms and/or definition) in the definition list
* ''tags'': any CSS classes found in the HTML are converted into tags
The tiddlers representing terms within the definition list have the following fields:
* ''toc-type'': the text "term"
* ''title'': an automatically generated unique title
* ''text'': the text of the definition list term
* ''tags'': any CSS classes found in the HTML are converted into tags
The tiddlers representing definitions within the definition list have the following fields:
* ''toc-type'': the text "definition"
* ''title'': an automatically generated unique title
* ''text'' : the text of the definition list definition
* ''tags'': any CSS classes found in the HTML are converted into tags
!!! Images
Tiddlers representing images have the following fields:

View File

@ -0,0 +1,40 @@
/*\
title: $:/plugins/tiddlywiki/text-slicer/modules/slicers/def-list.js
type: application/javascript
module-type: slicer
Handle slicing definition list nodes
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.processDefListNode = function(domNode,tagName) {
if(domNode.nodeType === 1 && tagName === "dl") {
var title = this.makeUniqueTitle("def-list-" + tagName),
parentTitle = this.parentStack[this.parentStack.length - 1].title,
tags = [];
if(domNode.className.trim() !== "") {
tags = tags.concat(domNode.className.split(" "));
}
this.addToList(parentTitle,title);
this.parentStack.push({type: tagName, title: this.addTiddler({
"toc-type": "def-list",
"toc-list-filter": "[list<currentTiddler>!has[draft.of]]",
text: "",
title: title,
list: [],
tags: tags
})});
this.currentTiddler = title;
this.processNodeList(domNode.childNodes);
this.parentStack.pop();
return true;
}
return false;
};
})();

View File

@ -0,0 +1,44 @@
/*\
title: $:/plugins/tiddlywiki/text-slicer/modules/slicers/definition.js
type: application/javascript
module-type: slicer
Handle slicing definition list definition nodes
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.processDefinitionItemNode = function(domNode,tagName) {
var text = $tw.utils.htmlEncode(domNode.textContent);
if(domNode.nodeType === 1 && tagName === "dd") {
// if(!this.isBlank(text)) {
var title = this.makeUniqueTitle("definition",text),
parentTitle = this.parentStack[this.parentStack.length - 1].title,
tags = [];
if(domNode.className.trim() !== "") {
tags = tags.concat(domNode.className.split(" "));
}
this.addToList(parentTitle,title);
this.addTiddler({
"toc-type": "definition",
title: title,
text: "",
list: [],
tags: tags
});
this.currentTiddler = title;
this.containerStack.push(title);
// this.containerStack.push("Just testing" + new Date());
this.processNodeList(domNode.childNodes);
this.containerStack.pop();
return true;
// }
}
return false;
};
})();

View File

@ -0,0 +1,44 @@
/*\
title: $:/plugins/tiddlywiki/text-slicer/modules/slicers/term.js
type: application/javascript
module-type: slicer
Handle slicing definition list term nodes
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.processTermItemNode = function(domNode,tagName) {
var text = $tw.utils.htmlEncode(domNode.textContent);
if(domNode.nodeType === 1 && tagName === "dt") {
// if(!this.isBlank(text)) {
var title = this.makeUniqueTitle("term",text),
parentTitle = this.parentStack[this.parentStack.length - 1].title,
tags = [];
if(domNode.className.trim() !== "") {
tags = tags.concat(domNode.className.split(" "));
}
this.addToList(parentTitle,title);
this.addTiddler({
"toc-type": "term",
title: title,
text: "",
list: [],
tags: tags
});
this.currentTiddler = title;
this.containerStack.push(title);
// this.containerStack.push("Just testing" + new Date());
this.processNodeList(domNode.childNodes);
this.containerStack.pop();
return true;
// }
}
return false;
};
})();

View File

@ -0,0 +1,11 @@
title: $:/plugins/tiddlywiki/text-slicer/templates/interactive/def-list
\define body()
<dl>
<$list filter="""[all[current]] $(tv-exclude-filter)$ +[limit[1]]""" variable="item">
<$list filter={{!!toc-list-filter}} template="$:/plugins/tiddlywiki/text-slicer/templates/interactive/tiddler"/>
</$list>
</dl>
\end
<<body>>

View File

@ -0,0 +1,11 @@
title: $:/plugins/tiddlywiki/text-slicer/templates/interactive/definition
\define body()
<$link tag="dd" class="tc-document-tiddler-link">
<$transclude/>
</$link>
\end
<<body>>

View File

@ -0,0 +1,11 @@
title: $:/plugins/tiddlywiki/text-slicer/templates/interactive/term
\define body()
<$link tag="dt" class="tc-document-tiddler-link">
<$transclude/>
</$link>
\end
<<body>>

View File

@ -27,3 +27,15 @@ title: $:/plugins/tiddlywiki/text-slicer/templates/interactive/tiddler
<$reveal type="match" state="!!toc-type" text="image">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/interactive/image" mode="block"/>
</$reveal>
<$reveal type="match" state="!!toc-type" text="def-list">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/interactive/def-list" mode="block"/>
</$reveal>
<$reveal type="match" state="!!toc-type" text="term">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/interactive/term" mode="block"/>
</$reveal>
<$reveal type="match" state="!!toc-type" text="definition">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/interactive/definition" mode="block"/>
</$reveal>

View File

@ -0,0 +1,11 @@
title: $:/plugins/tiddlywiki/text-slicer/templates/plain/def-list
\define body()
<dl>
<$list filter="""[all[current]] $(tv-exclude-filter)$ +[limit[1]]""" variable="item">
<$list filter={{!!toc-list-filter}} template="$:/plugins/tiddlywiki/text-slicer/templates/plain/tiddler"/>
</$list>
</dl>
\end
<<body>>

View File

@ -0,0 +1,11 @@
title: $:/plugins/tiddlywiki/text-slicer/templates/plain/definition
\define body()
<dd>
<$transclude/>
</dd>
\end
<<body>>

View File

@ -0,0 +1,11 @@
title: $:/plugins/tiddlywiki/text-slicer/templates/plain/term
\define body()
<dt>
<$transclude/>
</dt>
\end
<<body>>

View File

@ -26,4 +26,16 @@ title: $:/plugins/tiddlywiki/text-slicer/templates/plain/tiddler
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/plain/image" mode="block"/>
</$list>
<$list filter="[<toc-type>prefix[def-list]]" variable="item">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/plain/def-list" mode="block"/>
</$list>
<$list filter="[<toc-type>prefix[term]]" variable="item">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/plain/term" mode="block"/>
</$list>
<$list filter="[<toc-type>prefix[definition]]" variable="item">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/plain/definition" mode="block"/>
</$list>
</$vars>

View File

@ -0,0 +1,11 @@
title: $:/plugins/tiddlywiki/text-slicer/templates/static/def-list
<$list filter="""[all[current]] $(tv-exclude-filter)$ +[limit[1]]""" variable="item">
`<dl class="`{{||$:/plugins/tiddlywiki/text-slicer/templates/static/helpers/classes}}`">`
<$list filter={{!!toc-list-filter}} template="$:/plugins/tiddlywiki/text-slicer/templates/static/tiddler"/>
`</dl>`
</$list>

View File

@ -0,0 +1,9 @@
title: $:/plugins/tiddlywiki/text-slicer/templates/static/definition
`<dd class="`{{||$:/plugins/tiddlywiki/text-slicer/templates/static/helpers/classes}}`">`
<$transclude/>
`</dd>`
<$list filter="[list<currentTiddler>!has[draft.of]]" template="$:/plugins/tiddlywiki/text-slicer/templates/static/tiddler"/>

View File

@ -0,0 +1,9 @@
title: $:/plugins/tiddlywiki/text-slicer/templates/static/term
`<dt class="`{{||$:/plugins/tiddlywiki/text-slicer/templates/static/helpers/classes}}`">`
<$transclude/>
`</dt>`
<$list filter="[list<currentTiddler>!has[draft.of]]" template="$:/plugins/tiddlywiki/text-slicer/templates/static/tiddler"/>

View File

@ -38,4 +38,22 @@ title: $:/plugins/tiddlywiki/text-slicer/templates/static/tiddler
</$list>
<$list filter="[<toc-type>prefix[def-list]]" variable="item">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/static/def-list" mode="block"/>
</$list>
<$list filter="[<toc-type>prefix[term]]" variable="item">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/static/term" mode="block"/>
</$list>
<$list filter="[<toc-type>prefix[definition]]" variable="item">
<$transclude tiddler="$:/plugins/tiddlywiki/text-slicer/templates/static/definition" mode="block"/>
</$list>
</$vars>