2015-09-15 12:37:12 +00:00
|
|
|
/*\
|
|
|
|
title: $:/plugins/tiddlywiki/text-slicer/modules/slicers/heading.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: slicer
|
|
|
|
|
|
|
|
Handle slicing heading nodes
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.processHeadingNode = function(domNode,tagName) {
|
2015-09-17 07:41:21 +00:00
|
|
|
if(domNode.nodeType === 1 && (tagName === "h1" || tagName === "h2" || tagName === "h3" || tagName === "h4")) {
|
2015-09-15 12:37:12 +00:00
|
|
|
var text = $tw.utils.htmlEncode(domNode.textContent);
|
2015-09-17 07:41:21 +00:00
|
|
|
var title = this.makeUniqueTitle("heading",text),
|
|
|
|
parentTitle = this.popParentStackUntil(tagName),
|
|
|
|
tags = [];
|
2016-02-01 21:22:55 +00:00
|
|
|
if(domNode.className && domNode.className.trim() !== "") {
|
2015-09-17 07:41:21 +00:00
|
|
|
tags = tags.concat(domNode.className.split(" "));
|
2015-09-15 12:37:12 +00:00
|
|
|
}
|
2015-09-17 07:41:21 +00:00
|
|
|
this.addToList(parentTitle,title);
|
|
|
|
this.parentStack.push({type: tagName, title: this.addTiddler({
|
|
|
|
"toc-type": "heading",
|
|
|
|
"toc-heading-level": tagName,
|
|
|
|
title: title,
|
|
|
|
text: "",
|
|
|
|
list: [],
|
|
|
|
tags: tags
|
|
|
|
})});
|
|
|
|
this.currentTiddler = title;
|
|
|
|
this.containerStack.push(title);
|
|
|
|
this.processNodeList(domNode.childNodes);
|
|
|
|
this.containerStack.pop();
|
|
|
|
return true;
|
2015-09-15 12:37:12 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|