1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-07 20:44:23 +00:00
TiddlyWiki5/plugins/tiddlywiki/classictools/modules/stripcomments.js
Jeremy Ruston c54faeecd8 Merge tw2 related plugins and templates
Now all the plugins and templates needed are in the plugin
`tiddlywiki/classictools`
2013-08-04 22:06:36 +01:00

55 lines
1.3 KiB
JavaScript

/*\
title: $:/plugins/tiddlywiki/classictools/stripcomments.js
type: application/javascript
module-type: fieldviewer
Special viewer for cooking old versions of TiddlyWiki. It removes JavaScript comments formatted as `//#`
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var stripComments = function(text) {
var lines = text.split("\n"),
out = [];
for(var line=0; line<lines.length; line++) {
var text = lines[line];
if(!/^\s*\/\/#/.test(text)) {
out.push(text);
}
}
return out.join("\n");
};
var StripCommentsViewer = function(viewWidget,tiddler,field,value) {
this.viewWidget = viewWidget;
this.tiddler = tiddler;
this.field = field;
this.value = value;
};
StripCommentsViewer.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 = stripComments(this.value);
}
// Set the element details
this.viewWidget.tag = "span";
this.viewWidget.attributes = {};
this.viewWidget.children = this.viewWidget.renderer.renderTree.createRenderers(this.viewWidget.renderer,[{
type: "text",
text: value
}]);
};
exports.stripcomments = StripCommentsViewer;
})();