With some of the TWs I'm using and filling with content I have to deal with file: URIs pasted into the TW from a Windows tool. This tool unfortunately produces file: URIs which do not work on Firefox -- the two-slashes issue. This plugin accepts such URIs and overrides createExternalLink() in order to produce HTML A HREFs which contain five(!) slashes. Other URIs are not touched.
In the hope that this plugin might be useful to others I would like to post it here for others to deploy and comment on it. Any comments appreciated. /*** |''Name''|FixFileUriPlugin| |''Description''|fixes «file:» URIs containing UNC path with only two leading slashes to use the required «file://///...» format in order to access files using UNC paths.| |''Author''|Harald Albrecht| |''Version''|0.9.1| |''Date''|2008-12-03| |''Type''|plugin| |''Status''|beta| |''Copyright''|2008 Harald Albrecht| |''License''|[[Creative Commons Attribution-ShareAlike 3.0 License| http://creativecommons.org/licenses/by-sa/3.0/]]| |''Overrides''|createExternalLink| |''Documentation''|see below| |''Keywords''|file, URI, UNC, path| !Description Certain path copy tools on Windows produce file: ~URIs for UNC paths which Firefox can't make head nor tail of. The reason is that instead of {{{file://UNC-path}}} the URI should look like {{{file://///UNC- path}}}. This plugin fixes such broken UNC file URIs on the fly whenever such an external link is rendered. Thus, it is unnecessary to edit all external file URIs -- no changes to existing links are required, so no daunting URI editing. !Installation Just install this plugin tiddler using the backstage and make sure that the plugin is enabled. Nothing more to do, as there are no options to configure. !Notes Is Firefox broken because it requires five(!) leading slashes in a file: URI in order to get to an UNC path? Actually, it's not broken and has to do it this way in order to be able to handle UNC paths in a proper way without breaking all other existing things. See the detailed explanation of what is going on here in [[comment #38643 for Mozilla bug #38|https://bugzilla.mozilla.org/show_bug.cgi? id=38643#c36]] and the rest of the bug comments. Remember: file: URIs were never properly defined, as they are local matters. Now since a file: URI is of format {{{file://}}}//host//{{{/}}}//path// and we need to distinguish between a real local path (say on Windows {{{/c:/ winnt/format.exe}}}) and an UNC path, we finally end up with encoding the UNC path with its two leading slashes inside the file: URI path -- that is: {{{file://}}}//(no host)//{{{/}}}//(UNC://{{{//UNC- path}}}//)//. !Revision History * v0.9.1 (2008-12-03) Fix for lost first UNC character. * v0.9.0 (2008-12-02) Initial plugin version. !Code ***/ //{{{ // Ensure that this plugin is installed only once. if(!version.extensions.FixFileUriPlugin) { version.extensions.FixFileUriPlugin = { installed: true }; // When at the time this plugin is being initialized (executed) we still have no extensions // established, we set up an empty extensions object within the config object. This is required // up to TW cores 2.4.x, starting with 2.5.0 this is not required anymore. if(!config.extensions) { config.extensions = {}; } // Our plugin populates its own namespace in form of the FixFileUriPlugin object inside // the config.extensions realm (that is, object spanning the realm). config.extensions.FixFileUriPlugin = { // Remember the previous function createExternalLink() that we are going to replace in // order to sneak in the file uri fix functionality. chainCreateExternalLink: createExternalLink, // The file: URI pattern to fix -- tackles only the "two leading slashes" version and keeps off // of the other file: URI patterns. fixFileUriPattern: "file://([^/])", // Our new function for creating external links. It basically just checks for the broken // file URI pattern in form of "file://UNC-path" and fixes it by making sure that such URIs // become "file://///UNC-path". createExternalLink: function(place,url) { var fileUriRegExp = new RegExp (config.extensions.FixFileUriPlugin.fixFileUriPattern,"mg"); url = url.replace(fileUriRegExp, "file://///$1"); return config.extensions.FixFileUriPlugin.chainCreateExternalLink (place,url); }, // Initialize the plugin. Here, we just need to replace the function for // creating an external link with our new version. The old function has been // saved, so we can later chain to it as required. init: function() { createExternalLink = this.createExternalLink; } }; // Get the show running... initialize our little plugin. config.extensions.FixFileUriPlugin.init(); }; // End of install-only-once check //}}} --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/TiddlyWikiDev?hl=en -~----------~----~----~----~------~----~------~--~---
