1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-26 01:50:28 +00:00
TiddlyWiki5/plugins/tiddlywiki/text-slicer/modules/commands/slice.js
Jermolene e344c38349 Major updates to text-slicer plugin
* 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
2017-12-14 14:16:54 +00:00

59 lines
1.2 KiB
JavaScript

/*\
title: $:/plugins/tiddlywiki/text-slicer/modules/commands/slice.js
type: application/javascript
module-type: command
Command to slice a specified tiddler
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var widget = require("$:/core/modules/widgets/widget.js"),
textSlicer = require("$:/plugins/tiddlywiki/text-slicer/modules/slicer.js");
exports.info = {
name: "slice",
synchronous: false
};
var Command = function(params,commander,callback) {
this.params = params;
this.commander = commander;
this.callback = callback;
};
Command.prototype.execute = function() {
if(this.params.length < 1) {
return "Missing parameters";
}
var self = this,
wiki = this.commander.wiki,
sourceTitle = this.params[0],
destTitle = this.params[1],
slicerRules = this.params[2],
outputMode = this.params[3],
slicer = new textSlicer.Slicer({
sourceTiddlerTitle: sourceTitle,
baseTiddlerTitle: destTitle,
slicerRules: slicerRules,
outputMode: outputMode,
wiki: wiki,
callback: function(err,tiddlers) {
if(err) {
return self.callback(err);
}
wiki.addTiddlers(tiddlers);
self.callback();
}
});
return null;
};
exports.Command = Command;
})();