mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 07:32:59 +00:00 
			
		
		
		
	Refactor link handling to use a link macro
Instead of the special case handling for <a> tags
This commit is contained in:
		
							
								
								
									
										35
									
								
								js/macros/link.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								js/macros/link.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| /*\ | ||||
| title: js/macros/link.js | ||||
|  | ||||
| \*/ | ||||
| (function(){ | ||||
|  | ||||
| /*jslint node: true */ | ||||
| "use strict"; | ||||
|  | ||||
| var utils = require("../Utils.js"); | ||||
|  | ||||
| exports.macro = { | ||||
| 	name: "link", | ||||
| 	wrapperTag: "span", | ||||
| 	types: ["text/html","text/plain"], | ||||
| 	params: { | ||||
| 		target: {byName: "default", type: "tiddler", optional: false}, | ||||
| 		text: {byName: true, type: "text", optional: true} | ||||
| 	}, | ||||
| 	handler: function(type,tiddler,store,params) { | ||||
| 		var text = params.text || params.target; | ||||
| 		if(type === "text/html") { | ||||
| 			return utils.stitchElement("a",{ | ||||
| 				href: params.target | ||||
| 			},{ | ||||
| 				content: utils.htmlEncode(text), | ||||
| 				classNames: store.adjustClassesForLink([],params.target) | ||||
| 			}); | ||||
| 		} else if (type === "text/plain") { | ||||
| 			return text;	 | ||||
| 		} | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| })(); | ||||
		Reference in New Issue
	
	Block a user
	 Jeremy Ruston
					Jeremy Ruston