mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 15:42:59 +00:00 
			
		
		
		
	Move stripcomments from the classictools plugin into the core
It's a bit of a hack for the moment. The plan is to implement stripcomments via the macro mechanism, at which point it can move back into the plugin.
This commit is contained in:
		| @@ -61,6 +61,9 @@ ViewWidget.prototype.execute = function() { | |||||||
| 		case "relativedate": | 		case "relativedate": | ||||||
| 			this.text = this.getValueAsRelativeDate(); | 			this.text = this.getValueAsRelativeDate(); | ||||||
| 			break; | 			break; | ||||||
|  | 		case "stripcomments": | ||||||
|  | 			this.text = this.getValueAsStrippedComments(); | ||||||
|  | 			break; | ||||||
| 		default: // "text" | 		default: // "text" | ||||||
| 			this.text = this.getValueAsText(); | 			this.text = this.getValueAsText(); | ||||||
| 			break; | 			break; | ||||||
| @@ -138,6 +141,18 @@ ViewWidget.prototype.getValueAsRelativeDate = function(format) { | |||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | ViewWidget.prototype.getValueAsStrippedComments = function() { | ||||||
|  | 	var lines = this.getValueAsText().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"); | ||||||
|  | }; | ||||||
|  |  | ||||||
| /* | /* | ||||||
| Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering | Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering | ||||||
| */ | */ | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								nbld.sh
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								nbld.sh
									
									
									
									
									
								
							| @@ -53,6 +53,17 @@ node ./tiddlywiki.js \ | |||||||
| 	--new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/codemirrordemo.html text/plain \ | 	--new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/codemirrordemo.html text/plain \ | ||||||
| 	|| exit 1 | 	|| exit 1 | ||||||
|  |  | ||||||
|  | # cook the TiddlyWiki 2.x.x index file | ||||||
|  |  | ||||||
|  | node ./tiddlywiki.js \ | ||||||
|  | 	editions/tw2 \ | ||||||
|  | 	--verbose \ | ||||||
|  | 	--load editions/tw2/source/tiddlywiki.com/index.html.recipe \ | ||||||
|  | 	--new_rendertiddler $:/core/templates/tiddlywiki2.template.html ./tmp/tw2/index.html text/plain \ | ||||||
|  | 	|| exit 1 | ||||||
|  |  | ||||||
|  | opendiff tmp/tw2/index.html editions/tw2/target/pre-widgetredux2.html | ||||||
|  |  | ||||||
| # Run tests | # Run tests | ||||||
|  |  | ||||||
| ./test.sh | ./test.sh | ||||||
|   | |||||||
| @@ -1,54 +0,0 @@ | |||||||
| /*\ |  | ||||||
| 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; |  | ||||||
|  |  | ||||||
| })(); |  | ||||||
		Reference in New Issue
	
	Block a user
	 Jeremy Ruston
					Jeremy Ruston