Skip to content

Commit d5e690a

Browse files
committed
First pass at global disabling of parser rules
This is to address #1875 more quickly than via #345. This commit only includes a partial implementation of the UI - see the ticket for details.
1 parent 9e1741a commit d5e690a

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*\
2+
title: $:/core/modules/filters/wikiparserrules.js
3+
type: application/javascript
4+
module-type: filteroperator
5+
6+
Filter operator for returning the names of the wiki parser rules in this wiki
7+
8+
\*/
9+
(function(){
10+
11+
/*jslint node: true, browser: true */
12+
/*global $tw: false */
13+
"use strict";
14+
15+
/*
16+
Export our filter function
17+
*/
18+
exports.wikiparserrules = function(source,operator,options) {
19+
var results = [];
20+
$tw.utils.each($tw.modules.types.wikirule,function(mod) {
21+
var exp = mod.exports;
22+
if(exp.types[operator.operand]) {
23+
results.push(exp.name);
24+
}
25+
});
26+
results.sort();
27+
return results;
28+
};
29+
30+
})();

core/modules/parsers/wikiparser/wikiparser.js

+15
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ var WikiParser = function(type,text,options) {
2929
// Initialise the classes if we don't have them already
3030
if(!this.pragmaRuleClasses) {
3131
WikiParser.prototype.pragmaRuleClasses = $tw.modules.createClassesFromModules("wikirule","pragma",$tw.WikiRuleBase);
32+
this.setupRules(WikiParser.prototype.pragmaRuleClasses,"$:/config/WikiParserRules/Pragmas/");
3233
}
3334
if(!this.blockRuleClasses) {
3435
WikiParser.prototype.blockRuleClasses = $tw.modules.createClassesFromModules("wikirule","block",$tw.WikiRuleBase);
36+
this.setupRules(WikiParser.prototype.blockRuleClasses,"$:/config/WikiParserRules/Block/");
3537
}
3638
if(!this.inlineRuleClasses) {
3739
WikiParser.prototype.inlineRuleClasses = $tw.modules.createClassesFromModules("wikirule","inline",$tw.WikiRuleBase);
40+
this.setupRules(WikiParser.prototype.inlineRuleClasses,"$:/config/WikiParserRules/Inline/");
3841
}
3942
// Save the parse text
4043
this.type = type || "text/vnd.tiddlywiki";
@@ -59,6 +62,18 @@ var WikiParser = function(type,text,options) {
5962
// Return the parse tree
6063
};
6164

65+
/*
66+
*/
67+
WikiParser.prototype.setupRules = function(proto,configPrefix) {
68+
var self = this;
69+
$tw.utils.each(proto,function(object,name) {
70+
if(self.wiki.getTiddlerText(configPrefix + name,"enable") !== "enable") {
71+
delete proto[name];
72+
console.log("deleting",name)
73+
}
74+
});
75+
};
76+
6277
/*
6378
Instantiate an array of parse rules
6479
*/

core/ui/ControlPanel/Parsing.tid

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
title: $:/core/ui/ControlPanel/Parsing
2+
tags: $:/tags/ControlPanel
3+
caption: Parsing
4+
5+
\define parsing-inner(typeCap)
6+
<li>
7+
<$checkbox tiddler="""$:/config/WikiParserRules/$typeCap$/$(currentTiddler)$""" field="text" checked="enable" unchecked="disable" default="enable"> ''<$text text=<<currentTiddler>>/>'': </$checkbox>
8+
</li>
9+
\end
10+
11+
\define parsing-outer(typeLower,typeCap)
12+
<ul>
13+
<$list filter="[wikiparserrules[$typeLower$]]">
14+
<<parsing-inner typeCap:"$typeCap$">>
15+
</$list>
16+
</ul>
17+
\end
18+
19+
! Pragma Parse Rules
20+
21+
<<parsing-outer typeLower:"pragma" typeCap:"Pragma">>
22+
23+
! Inline Parse Rules
24+
25+
<<parsing-outer typeLower:"inline" typeCap:"Inline">>
26+
27+
! Block Parse Rules
28+
29+
<<parsing-outer typeLower:"block" typeCap:"Block">>

core/wiki/config/wikilink.tid

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title: $:/config/WikiParserRules/Inline/wikilink
2+
3+
enable

0 commit comments

Comments
 (0)