From 37338b13e4392cc053e3670a2dbb5f09bc2db901 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Thu, 13 Jun 2024 01:23:31 +0800 Subject: [PATCH] refactor: extract a new $tw.wiki.getParser --- core/modules/wiki.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 2850dec5f..e53b0d387 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -1035,6 +1035,18 @@ Options include: exports.parseText = function(type,text,options) { text = text || ""; options = options || {}; + var Parser = this.getParser(type,options) + // Return the parser instance + return new Parser(type,text,{ + parseAsInline: options.parseAsInline, + wiki: this, + _canonical_uri: options._canonical_uri, + configTrimWhiteSpace: options.configTrimWhiteSpace + }); +}; + +exports.getParser = function(type,options) { + options = $tw.utils.extend({},options); // Select a parser var Parser = $tw.Wiki.parsers[type]; if(!Parser && $tw.utils.getFileExtensionInfo(type)) { @@ -1046,13 +1058,7 @@ exports.parseText = function(type,text,options) { if(!Parser) { return null; } - // Return the parser instance - return new Parser(type,text,{ - parseAsInline: options.parseAsInline, - wiki: this, - _canonical_uri: options._canonical_uri, - configTrimWhiteSpace: options.configTrimWhiteSpace - }); + return Parser; }; /*