Skip to content
Extraits de code Groupes Projets
Valider 805e4719 rédigé par Andrew Morgan andrew@amorgan.xyz's avatar Andrew Morgan andrew@amorgan.xyz
Parcourir les fichiers

Proper markdown parsing, new test for markdown edits

parent a6ea8897
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -73,14 +73,8 @@ export class MessageProcessor { ...@@ -73,14 +73,8 @@ export class MessageProcessor {
public async FormatEdit(oldMsg: Discord.Message, newMsg: Discord.Message): Promise<MessageProcessorMatrixResult> { public async FormatEdit(oldMsg: Discord.Message, newMsg: Discord.Message): Promise<MessageProcessorMatrixResult> {
// TODO: Produce a nice, colored diff between the old and new message content // TODO: Produce a nice, colored diff between the old and new message content
const formattedOldMsg = await this.FormatDiscordMessage(oldMsg); oldMsg.content = "*edit:* ~~" + oldMsg.content + "~~ -> " + newMsg.content;
const formattedNewMsg = await this.FormatDiscordMessage(newMsg); return await this.FormatDiscordMessage(oldMsg);
const msg = new MessageProcessorMatrixResult();
msg.body = "edit: " + formattedOldMsg.body + " -> " + formattedNewMsg.body;
msg.formattedBody = "<i>edit:</i> <del>" + formattedOldMsg.body + "</del> -> " + formattedNewMsg.body;
return msg;
} }
public InsertEmbeds(content: string, msg: Discord.Message): string { public InsertEmbeds(content: string, msg: Discord.Message): string {
......
...@@ -52,7 +52,7 @@ describe("MessageProcessor", () => { ...@@ -52,7 +52,7 @@ describe("MessageProcessor", () => {
}); });
}); });
describe("FormatEdit", () => { describe("FormatEdit", () => {
it("should format edits appropriately", async () => { it("should format basic edits appropriately", async () => {
const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot); const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot);
const oldMsg = new Discord.Message(null, null, null); const oldMsg = new Discord.Message(null, null, null);
const newMsg = new Discord.Message(null, null, null); const newMsg = new Discord.Message(null, null, null);
...@@ -64,9 +64,27 @@ describe("MessageProcessor", () => { ...@@ -64,9 +64,27 @@ describe("MessageProcessor", () => {
newMsg.content = "b"; newMsg.content = "b";
const result = await processor.FormatEdit(oldMsg, newMsg); const result = await processor.FormatEdit(oldMsg, newMsg);
Chai.assert.equal(result.body, "edit: a -> b"); Chai.assert.equal(result.body, "*edit:* ~~a~~ -> b");
Chai.assert.equal(result.formattedBody, "<i>edit:</i> <del>a</del> -> b"); Chai.assert.equal(result.formattedBody, "<p><em>edit:</em> <del>a</del> -&gt; b</p>\n");
}); });
it("should format markdown heavy edits apropriately", async () => {
const processor = new MessageProcessor(new MessageProcessorOpts("localhost"), <DiscordBot> bot);
const oldMsg = new Discord.Message(null, null, null);
const newMsg = new Discord.Message(null, null, null);
oldMsg.embeds = [];
newMsg.embeds = [];
// Content updated but not changed
oldMsg.content = "a slice of **cake**";
newMsg.content = "*a* slice of cake";
const result = await processor.FormatEdit(oldMsg, newMsg);
Chai.assert.equal(result.body, "*edit:* ~~a slice of **cake**~~ -> *a* slice of cake");
Chai.assert.equal(result.formattedBody, "<p><em>edit:</em> <del>a slice of <strong>" +
"cake</strong></del> -&gt; <em>a</em> slice of cake</p>\n");
});
}); });
describe("ReplaceMembers", () => { describe("ReplaceMembers", () => {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter