Răsfoiți Sursa

don't break lists

MarkusRost 4 ani în urmă
părinte
comite
2ca18b7b3e
1 a modificat fișierele cu 6 adăugiri și 2 ștergeri
  1. 6 2
      util/functions.js

+ 6 - 2
util/functions.js

@@ -163,7 +163,11 @@ function htmlToPlain(html) {
 			if ( tagname === 'span' && attribs.class === 'smwttcontent' ) ignoredTag = 'span';
 		},
 		ontext: (htmltext) => {
-			if ( !ignoredTag ) text += escapeFormatting(htmltext);
+			if ( !ignoredTag ) {
+				htmltext = htmltext.replace( /[\r\n\t ]+/g, ' ' );
+				if ( text.endsWith( ' ' ) && htmltext.startsWith( ' ' ) ) htmltext = htmltext.replace( /^ +/, '' );
+				text += escapeFormatting(htmltext);
+			}
 		},
 		onclosetag: (tagname) => {
 			if ( tagname === ignoredTag ) ignoredTag = '';
@@ -305,7 +309,7 @@ function htmlToDiscord(html, pagelink = '', ...escapeArgs) {
 				if ( code ) text += htmltext.replace( /`/g, 'ˋ' );
 				else {
 					htmltext = htmltext.replace( /[\r\n\t ]+/g, ' ' );
-					if ( text.endsWith( ' ' ) && htmltext.startsWith( ' ' ) ) text = text.replace( / +$/, '' );
+					if ( text.endsWith( ' ' ) && htmltext.startsWith( ' ' ) ) htmltext = htmltext.replace( /^ +/, '' );
 					text += escapeFormatting(htmltext, ...escapeArgs);
 				}
 			}