mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Some new viewers we'll need for cooking TiddlyWiki files
This is all part of getting the new parser able to cook TiddlyWiki files
This commit is contained in:
parent
ac96b13b47
commit
8d185399de
39
core/modules/widgets/view/viewers/htmlencoded.js
Normal file
39
core/modules/widgets/view/viewers/htmlencoded.js
Normal file
@ -0,0 +1,39 @@
|
||||
/*\
|
||||
title: $:/core/modules/widgets/view/viewers/htmlencoded.js
|
||||
type: application/javascript
|
||||
module-type: newfieldviewer
|
||||
|
||||
A viewer for viewing tiddler fields as HTML encoded text
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var HtmlEncodedViewer = function(viewWidget,tiddler,field,value) {
|
||||
this.viewWidget = viewWidget;
|
||||
this.tiddler = tiddler;
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
};
|
||||
|
||||
HtmlEncodedViewer.prototype.render = function() {
|
||||
// Get the value as a string
|
||||
if(this.field !== "text" && this.tiddler) {
|
||||
this.value = this.tiddler.getFieldString(this.field);
|
||||
}
|
||||
var value = "";
|
||||
if(this.value !== undefined && this.value !== null) {
|
||||
value = this.value;
|
||||
}
|
||||
return this.viewWidget.renderer.renderTree.createRenderers(this.viewWidget.renderer.renderContext,[{
|
||||
type: "text",
|
||||
text: $tw.utils.htmlEncode(value)
|
||||
}]);
|
||||
};
|
||||
|
||||
exports.htmlencoded = HtmlEncodedViewer;
|
||||
|
||||
})();
|
39
core/modules/widgets/view/viewers/htmlwikified.js
Normal file
39
core/modules/widgets/view/viewers/htmlwikified.js
Normal file
@ -0,0 +1,39 @@
|
||||
/*\
|
||||
title: $:/core/modules/widgets/view/viewers/htmlwikified.js
|
||||
type: application/javascript
|
||||
module-type: newfieldviewer
|
||||
|
||||
A viewer for viewing tiddler fields as a textual HTML representation of the wikified text
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var HtmlWikifiedViewer = function(viewWidget,tiddler,field,value) {
|
||||
this.viewWidget = viewWidget;
|
||||
this.tiddler = tiddler;
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
};
|
||||
|
||||
HtmlWikifiedViewer.prototype.render = function() {
|
||||
// Parse the field text
|
||||
var text = this.viewWidget.renderer.renderTree.wiki.new_renderText("text/html","text/vnd.tiddlywiki",this.value);
|
||||
// Create a node containing the HTML representation of the field
|
||||
var node = {
|
||||
type: "element",
|
||||
tag: "pre",
|
||||
children: [{
|
||||
type: "text",
|
||||
text: text
|
||||
}]
|
||||
};
|
||||
return this.viewWidget.renderer.renderTree.createRenderers(this.viewWidget.renderer.renderContext,[node]);
|
||||
};
|
||||
|
||||
exports.htmlwikified = HtmlWikifiedViewer;
|
||||
|
||||
})();
|
39
core/modules/widgets/view/viewers/jsencoded.js
Normal file
39
core/modules/widgets/view/viewers/jsencoded.js
Normal file
@ -0,0 +1,39 @@
|
||||
/*\
|
||||
title: $:/core/modules/widgets/view/viewers/jsencoded.js
|
||||
type: application/javascript
|
||||
module-type: newfieldviewer
|
||||
|
||||
A viewer for viewing tiddler fields as JavaScript stringified text
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var JsEncodedViewer = function(viewWidget,tiddler,field,value) {
|
||||
this.viewWidget = viewWidget;
|
||||
this.tiddler = tiddler;
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
};
|
||||
|
||||
JsEncodedViewer.prototype.render = function() {
|
||||
// Get the value as a string
|
||||
if(this.field !== "text" && this.tiddler) {
|
||||
this.value = this.tiddler.getFieldString(this.field);
|
||||
}
|
||||
var value = "";
|
||||
if(this.value !== undefined && this.value !== null) {
|
||||
value = this.value;
|
||||
}
|
||||
return this.viewWidget.renderer.renderTree.createRenderers(this.viewWidget.renderer.renderContext,[{
|
||||
type: "text",
|
||||
text: $tw.utils.stringify(value)
|
||||
}]);
|
||||
};
|
||||
|
||||
exports.jsencoded = JsEncodedViewer;
|
||||
|
||||
})();
|
Loading…
Reference in New Issue
Block a user