From 674123619d931e4e258523d39b173b7b963fdac8 Mon Sep 17 00:00:00 2001 From: anekos Date: Tue, 13 Jan 2009 11:26:36 +0000 Subject: utf-8 指定の追加 リンクをちゃんとするように git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@28388 d0d07461-0603-4401-acd4-de1884942a52 --- PMWriter.js | 167 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 103 insertions(+), 64 deletions(-) (limited to 'PMWriter.js') diff --git a/PMWriter.js b/PMWriter.js index f9e7ed9..89a66d0 100644 --- a/PMWriter.js +++ b/PMWriter.js @@ -7,9 +7,12 @@ (function(){ + const U = liberator.plugins.libly.$U; + let pluginDirPath = liberator.globalVariables.pmwriter_plugin_dir; let outputDir = liberator.globalVariables.pmwriter_output_dir; + if (!(pluginDirPath && outputDir)) return; @@ -26,113 +29,149 @@ teramako: 'http://d.hatena.ne.jp/teramako/', }; + if (!liberator.plugins.pmwriter) + liberator.plugins.pmwriter = {}; + + // make を改造 + { + let makeLink = liberator.eval('makeLink', liberator.plugins.pluginManager.list); + if (!liberator.plugins.pmwriter.makeLink) { + liberator.plugins.pmwriter.makeLink = function (str) makeLink(str, true); + liberator.eval('makeLink = liberator.plugins.pmwriter.makeLink ', liberator.plugins.pluginManager.list); + } + let WikiParser = liberator.eval('WikiParser', liberator.plugins.pluginManager.list); + WikiParser.prototype.inlineParse = function (str) { + function replacer(_, s) + ({ '<': '<', '>': '>', '&': '&' })[s] || + '' + s + ''; + try { + return XMLList(str.replace(/(>|<|&|(?:https?:\/\/|mailto:)\S+)/g, replacer)); + } catch (e) { + return XMLList(str); + } + }; + } function action () { - liberator.plugins.pmwriter = {}; - let U = liberator.plugins.libly.$U; + const IOService = services.get('io'); + const DOCUMENT_TITLE = 'Vimperator Plugins in CodeRepos'; + const CodeRepos = 'http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/'; + + function Context (file) { + this.NAME = file.leafName.replace(/\..*/, '') + .replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()); + }; let myname = __context__.NAME; let otags = liberator.eval('tags', liberator.plugins.pluginManager.list); let template = liberator.eval('template', liberator.plugins.pluginManager.list); - // makeLink を無理矢理修正 - let makeLink = liberator.eval('makeLink', liberator.plugins.pluginManager.list); - liberator.plugins.pmwriter.makeLink = function (str) makeLink(str, true); - liberator.log(makeLink) - liberator.eval('makeLink = liberator.plugins.pmwriter.makeLink ', liberator.plugins.pluginManager.list); - let linkTo; let tags = { __proto__: otags, name: function () {otags.name.apply(otags, arguments)} }; - let ioService = services.get("io"); let files = io.readDirectory(pluginDirPath); - let i = 0; - let xml_index = <>>; + let indexHtml = <>>; files.forEach(function (file) { if (!/\.js$/.test(file.path)) return; - let src = io.readFile(file.path); - if (!/PLUGIN_INFO/.test(src)) - return; - //if (i++ > 0) return; - let uri = ioService.newFileURI(file); + if (!/PLUGIN_INFO/.test(io.readFile(file.path))) + return; - function Context (file) { - this.NAME = file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()); - }; let context = new Context(file); - let PLUGIN_INFO; - let detailFilename = context.NAME + '.html'; + let pluginName = file.leafName.replace(/\..*$/, ''); + let pluginFilename = file.leafName; if (context.NAME == myname) return; - context.watch('PLUGIN_INFO', function (n,N,O) { PLUGIN_INFO = O; throw 'STOP';}); + let pluginInfo; + let htmlFilename = pluginName + '.html'; - try { services.get("subscriptLoader").loadSubScript(uri.spec, context); } catch (e) {} + context.watch('PLUGIN_INFO', function (n, O, N) { pluginInfo = N; throw 'STOP';}); + + try { + services.get("subscriptLoader").loadSubScript(IOService.newFileURI(file).spec, context); + } catch (e) { + /* DO NOTHING */ + } - let info = PLUGIN_INFO; tags.name = function () {otags.name.apply(otags, arguments)}; - let plugin = [ ]; - plugin['name'] = context.NAME; - plugin['info'] = {}; - plugin['orgInfo'] = {}; - - for (let tag in tags){ - plugin.orgInfo[tag] = info[tag]; - let value = tags[tag](info); - if (value && value.toString().length > 0){ - plugin.push([tag, value]); - plugin.info[tag] = value; + let plugin = []; + let (info = pluginInfo) { + plugin['name'] = pluginName; + plugin['info'] = {}; + plugin['orgInfo'] = {}; + + for (let tag in tags){ + plugin.orgInfo[tag] = info[tag]; + let value = tags[tag](info); + if (value && value.toString().length > 0){ + plugin.push([tag, value]); + plugin.info[tag] = value; + } } } - let xml = -
-