1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 13:29:56 +00:00

Refactor parser rule architecture to allow individual parsers to function as both block and inline parsers

This commit is contained in:
Jeremy Ruston 2012-12-20 16:02:03 +00:00
parent 2f091fefda
commit 42945789e9
24 changed files with 67 additions and 43 deletions

View File

@ -444,23 +444,6 @@ $tw.modules.applyMethods = function(moduleType,targetObject) {
return targetObject;
};
/*
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
*/
$tw.modules.createClassesFromModules = function(moduleType,baseClass) {
var classes = {};
$tw.modules.forEachModuleOfType(moduleType,function(title,moduleExports) {
var newClass = function() {};
if(baseClass) {
newClass.prototype = new baseClass();
newClass.prototype.constructor = baseClass;
}
$tw.utils.extend(newClass.prototype,moduleExports);
classes[moduleExports.name] = newClass;
});
return classes;
};
/////////////////////////// Barebones tiddler object
/*

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/block/classblock.js
type: application/javascript
module-type: wiki-block-rule
module-type: wikirule
Wiki text block rule for assigning classes to paragraphs and other blocks. For example:
@ -25,6 +25,7 @@ Note that the opening and closing braces both must be immediately followed by a
"use strict";
exports.name = "classblock";
exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/block/codeblock.js
type: application/javascript
module-type: wiki-block-rule
module-type: wikirule
Wiki text rule for code blocks. For example:
@ -21,6 +21,7 @@ Note that the opening curly braces and the closing curly braces must each be on
"use strict";
exports.name = "codeblock";
exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/block/heading.js
type: application/javascript
module-type: wiki-block-rule
module-type: wikirule
Wiki text block rule for headings
@ -13,6 +13,7 @@ Wiki text block rule for headings
"use strict";
exports.name = "heading";
exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/block/list.js
type: application/javascript
module-type: wiki-block-rule
module-type: wikirule
Wiki text block rule for lists. For example:
@ -47,6 +47,7 @@ A CSS class can be applied to a list item as follows:
"use strict";
exports.name = "list";
exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/block/rule.js
type: application/javascript
module-type: wiki-block-rule
module-type: wikirule
Wiki text block rule for rules. For example:
@ -17,6 +17,7 @@ Wiki text block rule for rules. For example:
"use strict";
exports.name = "rule";
exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/block/table.js
type: application/javascript
module-type: wiki-block-rule
module-type: wikirule
Wiki text block rule for tables.
@ -13,6 +13,7 @@ Wiki text block rule for tables.
"use strict";
exports.name = "table";
exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/block/transcludeblock.js
type: application/javascript
module-type: wiki-block-rule
module-type: wikirule
Wiki text rule for block-level transclusion. For example:
@ -19,6 +19,7 @@ Wiki text rule for block-level transclusion. For example:
"use strict";
exports.name = "transclude";
exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/classinline.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text inline rule for assigning classes to runs of text. For example:
@ -22,6 +22,7 @@ List item 2}}}
"use strict";
exports.name = "classinline";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/codeinline.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text inline rule for code runs. For example:
@ -17,6 +17,7 @@ Wiki text inline rule for code runs. For example:
"use strict";
exports.name = "codeinline";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/comment.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text inline rule for HTML comments. For example:
@ -17,6 +17,7 @@ Wiki text inline rule for HTML comments. For example:
"use strict";
exports.name = "comment";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/dash.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text inline rule for dashes. For example:
@ -19,6 +19,7 @@ This is an em-dash: ---
"use strict";
exports.name = "dash";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/emphasis.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text inline rule for emphasis. For example:
@ -27,6 +27,7 @@ Wiki text inline rule for emphasis. For example:
"use strict";
exports.name = "emphasis";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/entity.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text inline rule for HTML entities. For example:
@ -17,6 +17,7 @@ Wiki text inline rule for HTML entities. For example:
"use strict";
exports.name = "entity";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/extlink.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text inline rule for external links. For example:
@ -21,6 +21,7 @@ External links can be suppressed by preceding them with `~`.
"use strict";
exports.name = "extlink";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/html.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki rule for HTML elements and widgets. For example:
@ -24,6 +24,7 @@ This is a widget invocation
"use strict";
exports.name = "html";
exports.types = {inline: true};
var voidElements = "area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",");

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/macrocall.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki rule for macro calls
@ -17,6 +17,7 @@ Wiki rule for macro calls
"use strict";
exports.name = "macrocall";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/prettylink.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text inline rule for pretty links. For example:
@ -19,6 +19,7 @@ Wiki text inline rule for pretty links. For example:
"use strict";
exports.name = "prettylink";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/transcludeinline.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text rule for inline-level transclusion. For example:
@ -19,6 +19,7 @@ Wiki text rule for inline-level transclusion. For example:
"use strict";
exports.name = "transclude";
exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/inline/wikilink.js
type: application/javascript
module-type: wiki-inline-rule
module-type: wikirule
Wiki text inline rule for wiki links. For example:
@ -21,6 +21,7 @@ Precede a camel case word with `~` to prevent it from being recognised as a link
"use strict";
exports.name = "wikilink";
exports.types = {inline: true};
var textPrimitives = {
upperLetter: "[A-Z\u00c0-\u00de\u0150\u0170]",

View File

@ -1,7 +1,7 @@
/*\
title: $:/core/modules/parsers/wikiparser/rules/pragma/macrodef.js
type: application/javascript
module-type: wiki-pragma-rule
module-type: wikirule
Wiki pragma rule for macro definitions
@ -19,6 +19,7 @@ definition text, including $param$ markers
"use strict";
exports.name = "macrodef";
exports.types = {pragma: true};
/*
Instantiate parse rule

View File

@ -28,7 +28,8 @@ WikifiedViewer.prototype.render = function() {
tag: "transclude",
attributes: {
target: {type: "string", value: this.tiddler.fields.title}
}
},
isBlock: this.viewWidget.renderer.parseTreeNode.isBlock
}];
} else {
parseTree = this.viewWidget.renderer.renderTree.wiki.new_parseText("text/vnd.tiddlywiki",this.value).tree;

View File

@ -13,13 +13,32 @@ module-type: global
var WikiVocabulary = function(options) {
this.wiki = options.wiki;
// Hashmaps of the various parse rule classes
this.pragmaRuleClasses = $tw.modules.createClassesFromModules("wiki-pragma-rule",$tw.WikiRuleBase);
this.blockRuleClasses = $tw.modules.createClassesFromModules("wiki-block-rule",$tw.WikiRuleBase);
this.inlineRuleClasses = $tw.modules.createClassesFromModules("wiki-inline-rule",$tw.WikiRuleBase);
this.pragmaRuleClasses = this.createClassesFromModules("wikirule","pragma",$tw.WikiRuleBase);
this.blockRuleClasses = this.createClassesFromModules("wikirule","block",$tw.WikiRuleBase);
this.inlineRuleClasses = this.createClassesFromModules("wikirule","inline",$tw.WikiRuleBase);
// Hashmap of the various renderer classes
this.rendererClasses = $tw.modules.applyMethods("wikirenderer");
// Hashmap of the available widgets
this.widgetClasses = $tw.modules.createClassesFromModules("widget",$tw.WidgetBase);
this.widgetClasses = this.createClassesFromModules("widget",null,$tw.WidgetBase);
};
/*
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
*/
WikiVocabulary.prototype.createClassesFromModules = function(moduleType,subType,baseClass) {
var classes = {};
$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;
}
});
return classes;
};
/*

View File

@ -12,5 +12,6 @@ modifier: JeremyRuston
</div>
<div class="body">
<_view field="text" format="wikified"/>
<_view field="text" format="wikified">
</_view>
</div>