Browse Source

minor changes

Markus-Rost 4 years ago
parent
commit
68b01bdffa

+ 0 - 8
cmds/eval.js

@@ -163,14 +163,6 @@ function checkWiki(wiki) {
 	} );
 }
 
-/**
- * Update the list of all sites.
- * @returns {Promise<Object[]>}
- */
-function updateAllSites() {
-	return require('../util/allSites.js').update();
-}
-
 /**
  * Removes the patreon features for a guild.
  * @param {String} guild - The guild ID.

+ 2 - 18
cmds/settings.js

@@ -6,10 +6,6 @@ const allLangs = Lang.allLangs();
 const Wiki = require('../util/wiki.js');
 var db = require('../util/database.js');
 
-var allSites = [];
-const getAllSites = require('../util/allSites.js');
-getAllSites.then( sites => allSites = sites );
-
 /**
  * Processes the "settings" command.
  * @param {Lang} lang - The user language.
@@ -19,7 +15,6 @@ getAllSites.then( sites => allSites = sites );
  * @param {Wiki} wiki - The wiki for the message.
  */
 function cmd_settings(lang, msg, args, line, wiki) {
-	if ( !allSites.length ) getAllSites.update();
 	if ( !msg.isAdmin() ) return msg.reactEmoji('❌');
 	
 	db.all( 'SELECT channel, wiki, lang, role, inline, prefix FROM discord WHERE guild = ? ORDER BY channel DESC', [msg.guild.id], (error, rows) => {
@@ -97,16 +92,9 @@ function cmd_settings(lang, msg, args, line, wiki) {
 			var wikinew = Wiki.fromInput(args[1]);
 			if ( !wikinew ) {
 				var text = lang.get('settings.wikiinvalid') + wikihelp;
-				var sites = allSites.filter( site => site.wiki_display_name.toLowerCase().includes( args[1] ) );
-				if ( 0 < sites.length && sites.length < 21 ) {
-					text += '\n\n' + lang.get('settings.foundwikis') + '\n' + sites.map( site => site.wiki_display_name + ': `' + site.wiki_domain + '`' ).join('\n');
-				}
+				//text += '\n\n' + lang.get('settings.foundwikis') + '\n' + sites.map( site => site.wiki_display_name + ': `' + site.wiki_domain + '`' ).join('\n');
 				return msg.replyMsg( text, {split:true}, true );
 			}
-			if ( wikinew.isGamepedia() && !isForced ) {
-				let site = allSites.find( site => site.wiki_domain === wikinew.hostname );
-				if ( site ) wikinew = new Wiki('https://' + ( site.wiki_crossover || site.wiki_domain ) + '/');
-			}
 			return msg.reactEmoji('⏳', true).then( reaction => {
 				got.get( wikinew + 'api.php?&action=query&meta=allmessages|siteinfo&ammessages=custom-GamepediaNotice|custom-FandomMergeNotice&amenableparser=true&siprop=general|extensions&format=json' ).then( response => {
 					if ( !isForced && response.statusCode === 404 && typeof response.body === 'string' ) {
@@ -126,11 +114,7 @@ function cmd_settings(lang, msg, args, line, wiki) {
 						return msg.replyMsg( lang.get('settings.wikiinvalid') + wikihelp, {}, true );
 					}
 					if ( !isForced ) wikinew.updateWiki(body.query.general);
-					if ( wikinew.isGamepedia() && !isForced ) {
-						let site = allSites.find( site => site.wiki_domain === wikinew.hostname );
-						if ( site ) wikinew = new Wiki('https://' + ( site.wiki_crossover || site.wiki_domain ) + '/');
-					}
-					else if ( wikinew.isFandom(false) && !isForced ) {
+					if ( wikinew.isFandom(false) && !isForced ) {
 						let crossover = '';
 						if ( body.query.allmessages[0]['*'] ) {
 							crossover = 'https://' + body.query.allmessages[0]['*'] + '.gamepedia.com/';

+ 3 - 3
cmds/wiki/diff.js

@@ -1,7 +1,7 @@
 const {MessageEmbed} = require('discord.js');
 const logging = require('../../util/logging.js');
 const {timeoptions} = require('../../util/default.json');
-const {toFormatting, htmlToPlain} = require('../../util/functions.js');
+const {toFormatting, htmlToDiscord} = require('../../util/functions.js');
 const diffParser = require('../../util/edit_diff.js');
 
 /**
@@ -197,7 +197,7 @@ function gamepedia_diff_send(lang, msg, args, wiki, reaction, spoiler, compare)
 				}
 				if ( editor[1] === lang.get('diff.hidden') ) editorlink = editor[1];
 				var embed = new MessageEmbed().setAuthor( body.query.general.sitename ).setTitle( ( title + '?diff=' + diff + '&oldid=' + oldid ).escapeFormatting() ).setURL( pagelink ).addField( editor[0], editorlink, true ).addField( size[0], size[1], true ).addField( comment[0], comment[1] ).setFooter( timestamp[1] );
-				if ( tags ) embed.addField( tags[0], htmlToPlain(tags[1]) );
+				if ( tags ) embed.addField( tags[0], htmlToDiscord(tags[1]) );
 				
 				var more = '\n__' + lang.get('diff.info.more') + '__';
 				var whitespace = '__' + lang.get('diff.info.whitespace') + '__';
@@ -267,7 +267,7 @@ function gamepedia_diff_send(lang, msg, args, wiki, reaction, spoiler, compare)
 			else {
 				var embed = {};
 				var text = '<' + pagelink + '>\n\n' + editor.join(' ') + '\n' + timestamp.join(' ') + '\n' + size.join(' ') + '\n' + comment.join(' ');
-				if ( tags ) text += htmlToPlain( '\n' + tags.join(' ') );
+				if ( tags ) text += htmlToDiscord( '\n' + tags.join(' ') );
 				
 				msg.sendChannel( spoiler + text + spoiler, {embed} );
 				

+ 3 - 3
cmds/wiki/fandom/diff.js

@@ -1,7 +1,7 @@
 const {MessageEmbed} = require('discord.js');
 const logging = require('../../../util/logging.js');
 const {timeoptions} = require('../../../util/default.json');
-const {toFormatting, htmlToPlain} = require('../../../util/functions.js');
+const {toFormatting, htmlToDiscord} = require('../../../util/functions.js');
 const diffParser = require('../../../util/edit_diff.js');
 
 /**
@@ -184,7 +184,7 @@ function fandom_diff_send(lang, msg, args, wiki, reaction, spoiler, compare) {
 					}
 					if ( editor[1] === lang.get('diff.hidden') ) editorlink = editor[1];
 					var embed = new MessageEmbed().setAuthor( body.query.general.sitename ).setTitle( ( title + '?diff=' + diff + '&oldid=' + oldid ).escapeFormatting() ).setURL( pagelink ).addField( editor[0], editorlink, true ).addField( size[0], size[1], true ).addField( comment[0], comment[1] ).setFooter( timestamp[1] );
-					if ( tags ) embed.addField( tags[0], htmlToPlain(tags[1]) );
+					if ( tags ) embed.addField( tags[0], htmlToDiscord(tags[1]) );
 					
 					var more = '\n__' + lang.get('diff.info.more') + '__';
 					var whitespace = '__' + lang.get('diff.info.whitespace') + '__';
@@ -244,7 +244,7 @@ function fandom_diff_send(lang, msg, args, wiki, reaction, spoiler, compare) {
 				else {
 					var embed = {};
 					var text = '<' + pagelink + '>\n\n' + editor.join(' ') + '\n' + timestamp.join(' ') + '\n' + size.join(' ') + '\n' + comment.join(' ');
-					if ( tags ) text += htmlToPlain( '\n' + tags.join(' ') );
+					if ( tags ) text += htmlToDiscord( '\n' + tags.join(' ') );
 					
 					msg.sendChannel( spoiler + text + spoiler, {embed} );
 					

+ 3 - 16
cmds/wiki/fandom/overview.js

@@ -2,10 +2,6 @@ const {MessageEmbed} = require('discord.js');
 const logging = require('../../../util/logging.js');
 const {timeoptions} = require('../../../util/default.json');
 
-var allSites = [];
-const getAllSites = require('../../../util/allSites.js');
-getAllSites.then( sites => allSites = sites );
-
 /**
  * Sends a Fandom wiki overview.
  * @param {import('../../../util/i18n.js')} lang - The user language.
@@ -15,7 +11,6 @@ getAllSites.then( sites => allSites = sites );
  * @param {String} spoiler - If the response is in a spoiler.
  */
 function fandom_overview(lang, msg, wiki, reaction, spoiler) {
-	if ( !allSites.length ) getAllSites.update();
 	got.get( wiki + 'api.php?action=query&meta=allmessages|siteinfo&ammessages=custom-Wiki_Manager|custom-GamepediaNotice|custom-FandomMergeNotice&amenableparser=true&siprop=general|statistics|wikidesc&titles=Special:Statistics&format=json' ).then( response => {
 		var body = response.body;
 		if ( body && body.warnings ) log_warn(body.warnings);
@@ -74,7 +69,7 @@ function fandom_overview(lang, msg, wiki, reaction, spoiler) {
 				var pagelink = wiki.toLink(title);
 				if ( msg.showEmbed() ) {
 					var text = '<' + pagelink + '>';
-					var embed = new MessageEmbed().setAuthor( body.query.general.sitename ).setTitle( title.escapeFormatting() ).setURL( pagelink ).setThumbnail( ( site.wordmark.startsWith( 'data:' ) ? wiki.toLink('Special:FilePath/Wiki-wordmark.png') : site.wordmark ) ).addField( vertical[0], vertical[1], true );
+					var embed = new MessageEmbed().setAuthor( body.query.general.sitename ).setTitle( title.escapeFormatting() ).setURL( pagelink ).setThumbnail( ( site.wordmark?.startsWith( 'data:' ) ? wiki.toLink('Special:FilePath/Wiki-wordmark.png') : site.wordmark ) ).addField( vertical[0], vertical[1], true );
 					if ( topic[1] ) embed.addField( topic[0], topic[1], true );
 				}
 				else {
@@ -102,11 +97,7 @@ function fandom_overview(lang, msg, wiki, reaction, spoiler) {
 						embed.addField( founder[0], founder[1], true );
 						if ( manager[1] ) embed.addField( manager[0], '[' + manager[1] + '](' + wiki.toLink('User:' + manager[1], '', '', true) + ') ([' + lang.get('overview.talk') + '](' + wiki.toLink('User talk:' + manager[1], '', '', true) + '))', true );
 						embed.addField( created[0], created[1], true ).addField( articles[0], articles[1], true ).addField( pages[0], pages[1], true ).addField( edits[0], edits[1], true ).addField( users[0], users[1], true ).setFooter( lang.get('overview.inaccurate') );
-						if ( crossover[1] ) {
-							var crossoverSite = allSites.find( site => '<https://' + site.wiki_domain + '/>' === crossover[1] );
-							if ( crossoverSite ) embed.addField( crossover[0], '[' + crossoverSite.wiki_display_name + '](' + crossover[1] + ')', true );
-							else embed.addField( crossover[0], crossover[1], true );
-						}
+						if ( crossover[1] ) embed.addField( crossover[0], crossover[1], true );
 						if ( description[1] ) embed.addField( description[0], description[1] );
 						if ( image[1] ) embed.addField( image[0], image[1] ).setImage( image[1] );
 					}
@@ -129,11 +120,7 @@ function fandom_overview(lang, msg, wiki, reaction, spoiler) {
 					founder[1] = lang.get('overview.none');
 					if ( msg.showEmbed() ) {
 						embed.addField( founder[0], founder[1], true ).addField( created[0], created[1], true ).addField( articles[0], articles[1], true ).addField( pages[0], pages[1], true ).addField( edits[0], edits[1], true ).addField( users[0], users[1], true ).setFooter( lang.get('overview.inaccurate') );
-						if ( crossover[1] ) {
-							var crossoverSite = allSites.find( site => '<https://' + site.wiki_domain + '/>' === crossover[1] );
-							if ( crossoverSite ) embed.addField( crossover[0], '[' + crossoverSite.wiki_display_name + '](' + crossover[1] + ')', true );
-							else embed.addField( crossover[0], crossover[1], true );
-						}
+						if ( crossover[1] ) embed.addField( crossover[0], crossover[1], true );
 						if ( description[1] ) embed.addField( description[0], description[1] );
 						if ( image[1] ) embed.addField( image[0], image[1] ).setImage( image[1] );
 					}

+ 2 - 2
cmds/wiki/fandom/user.js

@@ -2,7 +2,7 @@ const htmlparser = require('htmlparser2');
 const {MessageEmbed} = require('discord.js');
 const global_block = require('../../../functions/global_block.js');
 const {timeoptions, usergroups} = require('../../../util/default.json');
-const {toMarkdown, toPlaintext, htmlToPlain} = require('../../../util/functions.js');
+const {toMarkdown, toPlaintext} = require('../../../util/functions.js');
 
 /**
  * Processes a Fandom user.
@@ -306,7 +306,7 @@ function fandom_user(lang, msg, namespace, username, wiki, querystring, fragment
 							var avatarfield = profile.find( field => field.name === 'avatar' );
 							var biofield = profile.find( field => field.name === 'bio' );
 							if ( discordfield && discordfield.value ) {
-								discordfield.value = htmlToPlain( discordfield.value ).replace( /^\s*([^@#:]{2,32}?)\s*#(\d{4,6})\s*$/u, '$1#$2' );
+								discordfield.value = discordfield.value.replace( /^\s*([^@#:]{2,32}?)\s*#(\d{4,6})\s*$/u, '$1#$2' );
 								if ( discordfield.value.length > 100 ) discordfield.value = discordfield.value.substring(0, 100) + '\u2026';
 								if ( msg.channel.isGuild() ) var discordmember = msg.guild.members.cache.find( member => {
 									return member.user.tag.escapeFormatting() === discordfield.value;

+ 4 - 4
cmds/wiki/general.js

@@ -2,7 +2,7 @@ const {MessageEmbed} = require('discord.js');
 const parse_page = require('../../functions/parse_page.js');
 const phabricator = require('../../functions/phabricator.js');
 const logging = require('../../util/logging.js');
-const {parse_infobox, htmlToPlain, htmlToDiscord, partialURIdecode} = require('../../util/functions.js');
+const {parse_infobox, htmlToDiscord, partialURIdecode} = require('../../util/functions.js');
 const extract_desc = require('../../util/extract_desc.js');
 const {limit: {interwiki: interwikiLimit}, wikiProjects} = require('../../util/default.json');
 const Wiki = require('../../util/wiki.js');
@@ -223,7 +223,7 @@ function gamepedia_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '
 					}
 				}
 				if ( querypage.pageprops && querypage.pageprops.description ) {
-					var description = htmlToPlain( querypage.pageprops.description );
+					var description = htmlToDiscord( querypage.pageprops.description );
 					if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
 					embed.backupDescription = description;
 				}
@@ -328,7 +328,7 @@ function gamepedia_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '
 				}
 			}
 			if ( querypage.pageprops && querypage.pageprops.description ) {
-				var description = htmlToPlain( querypage.pageprops.description );
+				var description = htmlToDiscord( querypage.pageprops.description );
 				if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
 				embed.backupDescription = description;
 			}
@@ -451,7 +451,7 @@ function gamepedia_check_wiki(lang, msg, title, wiki, cmd, reaction, spoiler = '
 				}
 			}
 			if ( querypage.pageprops && querypage.pageprops.description ) {
-				var description = htmlToPlain( querypage.pageprops.description );
+				var description = htmlToDiscord( querypage.pageprops.description );
 				if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
 				embed.backupDescription = description;
 			}

+ 2 - 2
cmds/wiki/random.js

@@ -2,7 +2,7 @@ const {MessageEmbed} = require('discord.js');
 const fandom_random = require('./fandom/random.js').run;
 const parse_page = require('../../functions/parse_page.js');
 const logging = require('../../util/logging.js');
-const {parse_infobox, htmlToPlain, htmlToDiscord} = require('../../util/functions.js');
+const {parse_infobox, htmlToDiscord} = require('../../util/functions.js');
 const extract_desc = require('../../util/extract_desc.js');
 
 /**
@@ -43,7 +43,7 @@ function gamepedia_random(lang, msg, wiki, reaction, spoiler) {
 			embed.setTitle( displaytitle );
 		}
 		if ( querypage.pageprops && querypage.pageprops.description ) {
-			var description = htmlToPlain( querypage.pageprops.description );
+			var description = htmlToDiscord( querypage.pageprops.description );
 			if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
 			embed.backupDescription = description;
 		}

+ 5 - 5
cmds/wiki/user.js

@@ -4,7 +4,7 @@ const parse_page = require('../../functions/parse_page.js');
 const logging = require('../../util/logging.js');
 const extract_desc = require('../../util/extract_desc.js');
 const {timeoptions, usergroups} = require('../../util/default.json');
-const {parse_infobox, toMarkdown, toPlaintext, htmlToPlain, htmlToDiscord} = require('../../util/functions.js');
+const {parse_infobox, toMarkdown, toPlaintext, htmlToDiscord} = require('../../util/functions.js');
 
 var allSites = [];
 const getAllSites = require('../../util/allSites.js');
@@ -54,7 +54,7 @@ function gamepedia_user(lang, msg, namespace, username, wiki, querystring, fragm
 						}
 					}
 					if ( querypage.pageprops && querypage.pageprops.description ) {
-						var description = htmlToPlain( querypage.pageprops.description );
+						var description = htmlToDiscord( querypage.pageprops.description );
 						if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
 						embed.backupDescription = description;
 					}
@@ -147,7 +147,7 @@ function gamepedia_user(lang, msg, namespace, username, wiki, querystring, fragm
 				var text = '<' + pagelink + '>';
 				var embed = new MessageEmbed().setAuthor( body.query.general.sitename ).setTitle( username ).setURL( pagelink ).addField( editcount[0], '[' + editcount[1] + '](' + wiki.toLink(contribs + username, '', '', true) + ')' );
 				if ( querypage.pageprops && querypage.pageprops.description ) {
-					var description = htmlToPlain( querypage.pageprops.description );
+					var description = htmlToDiscord( querypage.pageprops.description );
 					if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
 					embed.setDescription( description );
 				}
@@ -223,7 +223,7 @@ function gamepedia_user(lang, msg, namespace, username, wiki, querystring, fragm
 					}
 				}
 				if ( querypage.pageprops && querypage.pageprops.description ) {
-					var description = htmlToPlain( querypage.pageprops.description );
+					var description = htmlToDiscord( querypage.pageprops.description );
 					if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
 					embed.backupDescription = description;
 				}
@@ -367,7 +367,7 @@ function gamepedia_user(lang, msg, namespace, username, wiki, querystring, fragm
 				embed.addField( gender[0], gender[1], true ).addField( registration[0], registration[1], true );
 				
 				if ( querypage.pageprops && querypage.pageprops.description ) {
-					var description = htmlToPlain( querypage.pageprops.description );
+					var description = htmlToDiscord( querypage.pageprops.description );
 					if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
 					embed.setDescription( description );
 				}

+ 2 - 2
functions/special_page.js

@@ -1,7 +1,7 @@
 const {Util} = require('discord.js');
 const logging = require('../util/logging.js');
 const {timeoptions} = require('../util/default.json');
-const {toPlaintext} = require('../util/functions.js');
+const {toMarkdown} = require('../util/functions.js');
 
 const overwrites = {
 	randompage: (fn, lang, msg, wiki, reaction, spoiler) => {
@@ -140,7 +140,7 @@ function special_page(lang, msg, title, specialpage, embed, wiki, reaction, spoi
 		}
 		else {
 			if ( body.query.allmessages[0]['*'] ) {
-				var description = toPlaintext(body.query.allmessages[0]['*'], true);
+				var description = toMarkdown(body.query.allmessages[0]['*'], wiki, title, true);
 				if ( description.length > 1000 ) description = description.substring(0, 1000) + '\u2026';
 				embed.setDescription( description );
 			}

+ 12 - 89
util/functions.js

@@ -142,7 +142,7 @@ function toMarkdown(text = '', wiki, title = '', fullWikitext = false) {
 function toPlaintext(text = '', fullWikitext = false) {
 	text = text.replace( /\[\[(?:[^\|\]]+\|)?([^\]]+)\]\]/g, '$1' ).replace( /\/\*\s*([^\*]+?)\s*\*\//g, '→$1:' );
 	if ( fullWikitext ) {
-		return htmlToPlain( text.replace( /\[(?:https?:)?\/\/(?:[^ ]+) ([^\]]+)\]/g, '$1' ) );
+		return htmlToDiscord( text.replace( /\[(?:https?:)?\/\/(?:[^ ]+) ([^\]]+)\]/g, '$1' ) );
 	}
 	else return escapeFormatting(text);
 };
@@ -155,100 +155,15 @@ function toPlaintext(text = '', fullWikitext = false) {
 function htmlToPlain(html) {
 	var text = '';
 	var reference = false;
-	var listlevel = -1;
 	var parser = new htmlparser.Parser( {
 		onopentag: (tagname, attribs) => {
 			if ( tagname === 'sup' && attribs.class === 'reference' ) reference = true;
-			if ( tagname === 'br' ) {
-				text += '\n';
-				if ( listlevel > -1 ) text += '\u200b '.repeat(4 * listlevel + 3);
-			}
-			if ( tagname === 'hr' ) {
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				text += '─'.repeat(10) + '\n';
-			}
-			if ( tagname === 'p' && !text.endsWith( '\n' ) ) text += '\n';
-			if ( tagname === 'ul' ) listlevel++;
-			if ( tagname === 'li' ) {
-				text = text.replace( / +$/, '' );
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				if ( attribs.class !== 'mw-empty-elt' ) {
-					if ( listlevel > -1 ) text += '\u200b '.repeat(4 * listlevel);
-					text += '• ';
-				}
-			}
-			if ( tagname === 'dl' ) listlevel++;
-			if ( tagname === 'dt' ) {
-				text = text.replace( / +$/, '' );
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				if ( listlevel > -1 && attribs.class !== 'mw-empty-elt' ) text += '\u200b '.repeat(4 * listlevel);
-			}
-			if ( tagname === 'dd' ) {
-				text = text.replace( / +$/, '' );
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				if ( listlevel > -1 && attribs.class !== 'mw-empty-elt' ) text += '\u200b '.repeat(4 * (listlevel + 1));
-			}
-			if ( tagname === 'img' ) {
-				if ( attribs.alt && attribs.src && !reference ) {
-					let showAlt = true;
-					if ( attribs['data-image-name'] === attribs.alt ) showAlt = false;
-					else {
-						let regex = new RegExp( '/([\\da-f])/\\1[\\da-f]/' + attribs.alt.replace( / /g, '_' ).replace( /\W/g, '\\$&' ) + '(?:/|\\?|$)' );
-						if ( attribs.src.startsWith( 'data:' ) && attribs['data-src'] ) attribs.src = attribs['data-src'];
-						if ( regex.test(attribs.src.replace( /(?:%[\dA-F]{2})+/g, partialURIdecode )) ) showAlt = false;
-					}
-					if ( showAlt ) text += escapeFormatting(attribs.alt);
-				}
-			}
-			if ( tagname === 'h1' ) {
-				text = text.replace( / +$/, '' );
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				text += '***__';
-			}
-			if ( tagname === 'h2' ) {
-				text = text.replace( / +$/, '' );
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				text += '**__';
-			}
-			if ( tagname === 'h3' ) {
-				text = text.replace( / +$/, '' );
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				text += '**';
-			}
-			if ( tagname === 'h4' ) {
-				text = text.replace( / +$/, '' );
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				text += '__';
-			}
-			if ( tagname === 'h5' ) {
-				text = text.replace( / +$/, '' );
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				text += '*';
-			}
-			if ( tagname === 'h6' ) {
-				text = text.replace( / +$/, '' );
-				if ( !text.endsWith( '\n' ) ) text += '\n';
-				text += '';
-			}
 		},
 		ontext: (htmltext) => {
-			if ( !reference ) {
-				text += escapeFormatting(htmltext);
-			}
+			if ( !reference ) text += escapeFormatting(htmltext);
 		},
 		onclosetag: (tagname) => {
 			if ( tagname === 'sup' ) reference = false;
-			if ( tagname === 'ul' ) listlevel--;
-			if ( tagname === 'dl' ) listlevel--;
-			if ( tagname === 'h1' ) text += '__***';
-			if ( tagname === 'h2' ) text += '__**';
-			if ( tagname === 'h3' ) text += '**';
-			if ( tagname === 'h4' ) text += '__';
-			if ( tagname === 'h5' ) text += '*';
-			if ( tagname === 'h6' ) text += '';
-		},
-		oncomment: (commenttext) => {
-			if ( /^LINK'" \d+:\d+$/.test(commenttext) ) text += '*UNKNOWN LINK*';
 		}
 	} );
 	parser.write( html );
@@ -276,11 +191,14 @@ function htmlToDiscord(html, serverpath = '', ...escapeArgs) {
 				code = true;
 				text += '`';
 			}
+			if ( tagname === 'pre' ) {
+				code = true;
+				text += '```\n';
+			}
 			if ( tagname === 'b' ) text += '**';
 			if ( tagname === 'i' ) text += '*';
 			if ( tagname === 's' ) text += '~~';
 			if ( tagname === 'u' ) text += '__';
-			if ( !serverpath ) return;
 			if ( tagname === 'sup' && attribs.class === 'reference' ) reference = true;
 			if ( tagname === 'br' ) {
 				text += '\n';
@@ -361,6 +279,7 @@ function htmlToDiscord(html, serverpath = '', ...escapeArgs) {
 				if ( !text.endsWith( '\n' ) ) text += '\n';
 				text += '';
 			}
+			if ( !serverpath ) return;
 			if ( tagname === 'a' && attribs.href && attribs.class !== 'new' && /^(?:(?:https?:)?\/)?\//.test(attribs.href) ) {
 				href = new URL(attribs.href, serverpath).href;
 				text += '[';
@@ -379,13 +298,16 @@ function htmlToDiscord(html, serverpath = '', ...escapeArgs) {
 					code = false;
 					text += '`';
 				}
+				if ( tagname === 'pre' ) {
+					code = false;
+					text += '\n```';
+				}
 				return;
 			}
 			if ( tagname === 'b' ) text += '**';
 			if ( tagname === 'i' ) text += '*';
 			if ( tagname === 's' ) text += '~~';
 			if ( tagname === 'u' ) text += '__';
-			if ( !serverpath ) return;
 			if ( tagname === 'sup' ) reference = false;
 			if ( tagname === 'ul' ) listlevel--;
 			if ( tagname === 'dl' ) listlevel--;
@@ -396,6 +318,7 @@ function htmlToDiscord(html, serverpath = '', ...escapeArgs) {
 			if ( tagname === 'h4' ) text += '__';
 			if ( tagname === 'h5' ) text += '*';
 			if ( tagname === 'h6' ) text += '';
+			if ( !serverpath ) return;
 			if ( tagname === 'a' && href ) {
 				if ( text.endsWith( '[' ) ) text = text.substring(0, text.length - 1);
 				else text += '](<' + href.replace( /[()]/g, '\\$&' ) + '>)';