mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-17 17:59:45 +00:00
d338a54370
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...
45 lines
906 B
JavaScript
45 lines
906 B
JavaScript
/*\
|
|
title: $:/core/modules/widgets/view/viewers/link.js
|
|
type: application/javascript
|
|
module-type: newfieldviewer
|
|
|
|
A viewer for viewing tiddler fields as a link
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
var LinkViewer = function(viewWidget,tiddler,field,value) {
|
|
this.viewWidget = viewWidget;
|
|
this.tiddler = tiddler;
|
|
this.field = field;
|
|
this.value = value;
|
|
};
|
|
|
|
LinkViewer.prototype.render = function() {
|
|
var parseTree = [];
|
|
if(this.value === undefined) {
|
|
parseTree.push({type: "text", text: ""});
|
|
} else {
|
|
parseTree.push({
|
|
type: "widget",
|
|
tag: "link",
|
|
attributes: {
|
|
to: {type: "string", value: this.value}
|
|
},
|
|
children: [{
|
|
type: "text",
|
|
text: this.value
|
|
}]
|
|
})
|
|
}
|
|
return this.viewWidget.renderer.renderTree.createRenderers(this.viewWidget.renderer.renderContext,parseTree);
|
|
};
|
|
|
|
exports.link = LinkViewer;
|
|
|
|
})();
|