mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-10 22:39:43 +00:00
![Jermolene](/assets/img/avatar_default.png)
* In the interests of performance and expressiveness, switched to using a Sax parser instead of a DOM implementation. * Use extensible declarative rules to control the slicing process * Added new optional set of rules for slicing by heading, where the paragraphs underneath a heading are packed into the same tiddler as the heading * Added a modal dialogue for specifying parameters when slicing in the browser
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
/*\
|
|
title: $:/plugins/tiddlywiki/text-slicer/modules/startup/slicer-startup.js
|
|
type: application/javascript
|
|
module-type: startup
|
|
|
|
Setup the root widget event handlers
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
var textSlicer = require("$:/plugins/tiddlywiki/text-slicer/modules/slicer.js");
|
|
|
|
// Export name and synchronous status
|
|
exports.name = "slicer";
|
|
exports.platforms = ["browser"];
|
|
exports.after = ["startup"];
|
|
exports.synchronous = true;
|
|
|
|
// Install the root widget event handlers
|
|
exports.startup = function() {
|
|
// Check sax is installed
|
|
if(!$tw.utils.hop($tw.modules.titles,"$:/plugins/tiddlywiki/sax/sax.js")) {
|
|
// Make a logger
|
|
var logger = new $tw.utils.Logger("text-slicer");
|
|
logger.alert("The plugin 'text-slicer' requires the 'sax' plugin to be installed");
|
|
}
|
|
// Add tm-slice-tiddler event handler
|
|
$tw.rootWidget.addEventListener("tm-slice-tiddler",function(event) {
|
|
var slicer = new textSlicer.Slicer({
|
|
sourceTiddlerTitle: event.param,
|
|
slicerRules: event.paramObject && event.paramObject.slicerRules,
|
|
outputMode: event.paramObject && event.paramObject.outputMode,
|
|
baseTiddlerTitle: event.paramObject && event.paramObject.destTitle,
|
|
role: event.paramObject && event.paramObject.role,
|
|
wiki: $tw.wiki,
|
|
callback: function(err,tiddlers) {
|
|
if(err) {
|
|
logger.alert("Slicer error: " + err);
|
|
} else {
|
|
$tw.wiki.addTiddlers(tiddlers);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
})();
|