mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-04-30 21:46:51 +00:00
Introduce refactored wiki parser and renderer
This is a half-way through a big refactoring of the parsing and rendering infrastructure. The main change is to separate the parse and render trees, which makes the code a lot cleaner. The new parser isn't yet functional enough to replace the existing parser so for the moment you have to manually invoke it with `$tw.testNewParser()` in your browser console. I really ought to use branches for this kind of thing...
This commit is contained in:
41
core/modules/widgets/view/viewers/wikified.js
Normal file
41
core/modules/widgets/view/viewers/wikified.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/*\
|
||||
title: $:/core/modules/widgets/view/viewers/wikified.js
|
||||
type: application/javascript
|
||||
module-type: newfieldviewer
|
||||
|
||||
A viewer for viewing tiddler fields as wikified text
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var WikifiedViewer = function(viewWidget,tiddler,field,value) {
|
||||
this.viewWidget = viewWidget;
|
||||
this.tiddler = tiddler;
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
};
|
||||
|
||||
WikifiedViewer.prototype.render = function() {
|
||||
var parseTree;
|
||||
// If we're viewing the text field of a tiddler then we'll transclude it
|
||||
if(this.tiddler && this.field === "text") {
|
||||
parseTree = [{
|
||||
type: "widget",
|
||||
tag: "transclude",
|
||||
attributes: {
|
||||
target: {type: "string", value: this.tiddler.fields.title}
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
parseTree = this.viewWidget.renderer.renderTree.wiki.new_parseText("text/vnd.tiddlywiki",this.value).tree;
|
||||
}
|
||||
return this.viewWidget.renderer.renderTree.createRenderers(this.viewWidget.renderer.renderContext,parseTree);
|
||||
};
|
||||
|
||||
exports.wikified = WikifiedViewer;
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user