mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-21 08:50:05 +00:00
Make it easier to subclass the wikitext parser with a custom rule set
We can now pass arrays of rule classes to the parser constructor, overriding the rules that would normally be used by the parser. This allows us to create custom variants of the wikitext parser with their own content type. It could also provide a basis for a new Markdown parser based on our existing wikitext parser but with new rules.
This commit is contained in:
+14
-7
@@ -892,6 +892,19 @@ $tw.modules.applyMethods = function(moduleType,targetObject) {
|
||||
return targetObject;
|
||||
};
|
||||
|
||||
/*
|
||||
Return a class created from a modules. The module should export the properties to be added to those of the optional base class
|
||||
*/
|
||||
$tw.modules.createClassFromModule = function(moduleExports,baseClass) {
|
||||
var newClass = function() {};
|
||||
if(baseClass) {
|
||||
newClass.prototype = new baseClass();
|
||||
newClass.prototype.constructor = baseClass;
|
||||
}
|
||||
$tw.utils.extend(newClass.prototype,moduleExports);
|
||||
return newClass;
|
||||
};
|
||||
|
||||
/*
|
||||
Return an array of classes created from the modules of a specified type. Each module should export the properties to be added to those of the optional base class
|
||||
*/
|
||||
@@ -899,13 +912,7 @@ $tw.modules.createClassesFromModules = function(moduleType,subType,baseClass) {
|
||||
var classes = Object.create(null);
|
||||
$tw.modules.forEachModuleOfType(moduleType,function(title,moduleExports) {
|
||||
if(!subType || moduleExports.types[subType]) {
|
||||
var newClass = function() {};
|
||||
if(baseClass) {
|
||||
newClass.prototype = new baseClass();
|
||||
newClass.prototype.constructor = baseClass;
|
||||
}
|
||||
$tw.utils.extend(newClass.prototype,moduleExports);
|
||||
classes[moduleExports.name] = newClass;
|
||||
classes[moduleExports.name] = $tw.modules.createClassFromModule(moduleExports,baseClass);
|
||||
}
|
||||
});
|
||||
return classes;
|
||||
|
||||
Reference in New Issue
Block a user