mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-01-25 20:33:41 +00:00
Compare commits
2 Commits
improved-s
...
add-jsrepl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8663dd51d6 | ||
|
|
215bd4e015 |
46
core/modules/commands/jsrepl.js
Normal file
46
core/modules/commands/jsrepl.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/commands/jsrepl.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: command
|
||||||
|
|
||||||
|
Command to launch node.js REPL with access to $tw
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.info = {
|
||||||
|
name: "jsrepl",
|
||||||
|
synchronous: true
|
||||||
|
};
|
||||||
|
|
||||||
|
var Command = function(params,commander,callback) {
|
||||||
|
var self = this;
|
||||||
|
this.params = params;
|
||||||
|
this.commander = commander;
|
||||||
|
this.callback = callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
Command.prototype.execute = function() {
|
||||||
|
var self = this;
|
||||||
|
var repl = require("repl");
|
||||||
|
this.runtime = repl.start({
|
||||||
|
prompt: this.params.length ? this.params[0] : "$tw-jsrepl> ",
|
||||||
|
useColors: true,
|
||||||
|
ignoreUndefined: true
|
||||||
|
});
|
||||||
|
// If REPL is reset (.clear) - context needs resetting
|
||||||
|
this.runtime.on("reset", function() {
|
||||||
|
self.runtime.context.$tw = $tw;
|
||||||
|
});
|
||||||
|
// Initial context settings
|
||||||
|
this.runtime.context.$tw = $tw;
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.Command = Command;
|
||||||
|
|
||||||
|
})();
|
||||||
@@ -194,6 +194,7 @@ Parse any pragmas at the beginning of a block of parse text
|
|||||||
WikiParser.prototype.parsePragmas = function() {
|
WikiParser.prototype.parsePragmas = function() {
|
||||||
var currentTreeBranch = this.tree;
|
var currentTreeBranch = this.tree;
|
||||||
while(true) {
|
while(true) {
|
||||||
|
var savedPos = this.pos;
|
||||||
// Skip whitespace
|
// Skip whitespace
|
||||||
this.skipWhitespace();
|
this.skipWhitespace();
|
||||||
// Check for the end of the text
|
// Check for the end of the text
|
||||||
@@ -204,6 +205,7 @@ WikiParser.prototype.parsePragmas = function() {
|
|||||||
var nextMatch = this.findNextMatch(this.pragmaRules,this.pos);
|
var nextMatch = this.findNextMatch(this.pragmaRules,this.pos);
|
||||||
// If not, just exit
|
// If not, just exit
|
||||||
if(!nextMatch || nextMatch.matchIndex !== this.pos) {
|
if(!nextMatch || nextMatch.matchIndex !== this.pos) {
|
||||||
|
this.pos = savedPos;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Process the pragma rule
|
// Process the pragma rule
|
||||||
|
|||||||
Reference in New Issue
Block a user