浏览代码

simplify href

MarkusRost 4 年之前
父节点
当前提交
56f7792e0f
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      util/functions.js

+ 4 - 4
util/functions.js

@@ -296,9 +296,9 @@ function htmlToDiscord(html, pagelink = '', ...escapeArgs) {
 			}
 			if ( !pagelink ) return;
 			if ( tagname === 'a' && attribs.href && attribs.class !== 'new' && /^(?:(?:https?:)?\/\/|\/|#)/.test(attribs.href) ) {
-				href = new URL(attribs.href, pagelink).href;
-				if ( text.endsWith( '](<' + href.replace( /[()]/g, '\\$&' ) + '>)' ) ) {
-					text = text.substring(0, text.length - ( href.replace( /[()]/g, '\\$&' ).length + 5 ));
+				href = new URL(attribs.href, pagelink).href.replace( /[()]/g, '\\$&' );
+				if ( text.endsWith( '](<' + href + '>)' ) ) {
+					text = text.substring(0, text.length - ( href.length + 5 ));
 				}
 				else text += '[';
 			}
@@ -347,7 +347,7 @@ function htmlToDiscord(html, pagelink = '', ...escapeArgs) {
 			if ( !pagelink ) return;
 			if ( tagname === 'a' && href ) {
 				if ( text.endsWith( '[' ) ) text = text.substring(0, text.length - 1);
-				else text += '](<' + href.replace( /[()]/g, '\\$&' ) + '>)';
+				else text += '](<' + href + '>)';
 				href = '';
 			}
 		},