Sfoglia il codice sorgente

Parse html whitespace better (maybe?)

MarkusRost 4 anni fa
parent
commit
d5c12d4a79
1 ha cambiato i file con 5 aggiunte e 1 eliminazioni
  1. 5 1
      util/functions.js

+ 5 - 1
util/functions.js

@@ -303,7 +303,11 @@ function htmlToDiscord(html, pagelink = '', ...escapeArgs) {
 			if ( !ignoredTag ) {
 				if ( href && !code ) htmltext = htmltext.replace( /[\[\]]/g, '\\$&' );
 				if ( code ) text += htmltext.replace( /`/g, 'ˋ' );
-				else text += escapeFormatting(htmltext, ...escapeArgs);
+				else {
+					htmltext = htmltext.replace( /[\r\n\t ]+/g, ' ' );
+					if ( text.endsWith( ' ' ) && htmltext.startsWith( ' ' ) ) text = text.replace( / +$/, '' );
+					text += escapeFormatting(htmltext, ...escapeArgs);
+				}
 			}
 		},
 		onclosetag: (tagname) => {