How to use discord-markdown - 9 common examples

To help you get started, we’ve selected a few discord-markdown examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Half-Shot / matrix-appservice-discord / src / discordmessageprocessor.ts View on Github external
`<a href="${escapeHtml(embed.url)}">${escapeHtml(embed.title)}</a>`
                : (embed.title ? escapeHtml(embed.title) : undefined);
            if (embedTitle) {
                embedContent += `<h5>${embedTitle}</h5>`; // h5 is probably best.
            }
            if (embed.description) {
                embedContent += "<p>";
                embedContent += markdown.toHTML(embed.description, {
                    discordCallback: this.getDiscordParseCallbacksHTML(msg),
                    embed: true,
                }) + "</p>";
            }
            if (embed.fields) {
                for (const field of embed.fields) {
                    embedContent += `<p><strong>${escapeHtml(field.name)}</strong><br>`;
                    embedContent += markdown.toHTML(field.value, {
                        discordCallback: this.getDiscordParseCallbacks(msg),
                        embed: true,
                    }) + "</p>";
                }
            }
            if (embed.image) {
                const imgUrl = escapeHtml(embed.image.url);
                embedContent += `<p>Image: <a href="${imgUrl}">${imgUrl}</a></p>`;
            }
            if (embed.footer) {
                embedContent += "<p>";
                embedContent += markdown.toHTML(embed.footer.text, {
                    discordCallback: this.getDiscordParseCallbacksHTML(msg),
                    embed: true,
                }) + "</p>";
            }
github Half-Shot / matrix-appservice-discord / src / discordmessageprocessor.ts View on Github external
let embedContent = "\n\n----"; // Horizontal rule. Two to make sure the content doesn't become a title.
            const embedTitle = embed.url ? `[${embed.title}](${embed.url})` : embed.title;
            if (embedTitle) {
                embedContent += "\n##### " + embedTitle; // h5 is probably best.
            }
            if (embed.description) {
                embedContent += "\n" + markdown.toHTML(embed.description, {
                    discordCallback: this.getDiscordParseCallbacks(msg),
                    discordOnly: true,
                    escapeHTML: false,
                });
            }
            if (embed.fields) {
                for (const field of embed.fields) {
                    embedContent += `\n**${field.name}**\n`;
                    embedContent += markdown.toHTML(field.value, {
                        discordCallback: this.getDiscordParseCallbacks(msg),
                        discordOnly: true,
                        escapeHTML: false,
                    });
                }
            }
            if (embed.image) {
                embedContent += "\nImage: " + embed.image.url;
            }
            if (embed.footer) {
                embedContent += "\n" + markdown.toHTML(embed.footer.text, {
                    discordCallback: this.getDiscordParseCallbacks(msg),
                    discordOnly: true,
                    escapeHTML: false,
                });
            }
github Half-Shot / matrix-appservice-discord / src / discordmessageprocessor.ts View on Github external
public async FormatMessage(msg: Discord.Message): Promise {
        const result = new DiscordMessageProcessorResult();

        let content = msg.content;

        // for the formatted body we need to parse markdown first
        // as else it'll HTML escape the result of the discord syntax
        let contentPostmark = markdown.toHTML(content, {
            discordCallback: this.getDiscordParseCallbacksHTML(msg),
        });

        // parse the plain text stuff
        content = markdown.toHTML(content, {
            discordCallback: this.getDiscordParseCallbacks(msg),
            discordOnly: true,
            escapeHTML: false,
        });
        content = this.InsertEmbeds(content, msg);
        content = await this.InsertMxcImages(content, msg);
        content = await this.InsertChannelPills(content, msg);

        // parse postmark stuff
        contentPostmark = this.InsertEmbedsPostmark(contentPostmark, msg);
        contentPostmark = await this.InsertMxcImages(contentPostmark, msg, true);
github Half-Shot / matrix-appservice-discord / src / discordmessageprocessor.ts View on Github external
public async FormatMessage(msg: Discord.Message): Promise {
        const result = new DiscordMessageProcessorResult();

        let content = msg.content;

        // for the formatted body we need to parse markdown first
        // as else it'll HTML escape the result of the discord syntax
        let contentPostmark = markdown.toHTML(content, {
            discordCallback: this.getDiscordParseCallbacksHTML(msg),
        });

        // parse the plain text stuff
        content = markdown.toHTML(content, {
            discordCallback: this.getDiscordParseCallbacks(msg),
            discordOnly: true,
            escapeHTML: false,
        });
        content = this.InsertEmbeds(content, msg);
        content = await this.InsertMxcImages(content, msg);
        content = await this.InsertChannelPills(content, msg);

        // parse postmark stuff
        contentPostmark = this.InsertEmbedsPostmark(contentPostmark, msg);
        contentPostmark = await this.InsertMxcImages(contentPostmark, msg, true);
        contentPostmark = await this.InsertChannelPills(contentPostmark, msg, true);

        result.body = content;
        result.formattedBody = contentPostmark;
        result.msgtype = msg.author.bot ? "m.notice" : "m.text";
github Half-Shot / matrix-appservice-discord / src / discordmessageprocessor.ts View on Github external
public InsertEmbeds(content: string, msg: Discord.Message): string {
        for (const embed of msg.embeds) {
            if (embed.title === undefined && embed.description === undefined) {
                continue;
            }
            if (this.isEmbedInBody(msg, embed)) {
                continue;
            }
            let embedContent = "\n\n----"; // Horizontal rule. Two to make sure the content doesn't become a title.
            const embedTitle = embed.url ? `[${embed.title}](${embed.url})` : embed.title;
            if (embedTitle) {
                embedContent += "\n##### " + embedTitle; // h5 is probably best.
            }
            if (embed.description) {
                embedContent += "\n" + markdown.toHTML(embed.description, {
                    discordCallback: this.getDiscordParseCallbacks(msg),
                    discordOnly: true,
                    escapeHTML: false,
                });
            }
            if (embed.fields) {
                for (const field of embed.fields) {
                    embedContent += `\n**${field.name}**\n`;
                    embedContent += markdown.toHTML(field.value, {
                        discordCallback: this.getDiscordParseCallbacks(msg),
                        discordOnly: true,
                        escapeHTML: false,
                    });
                }
            }
            if (embed.image) {
github Half-Shot / matrix-appservice-discord / src / discordmessageprocessor.ts View on Github external
if (embed.title === undefined &amp;&amp; embed.description === undefined) {
                continue;
            }
            if (this.isEmbedInBody(msg, embed)) {
                continue;
            }
            let embedContent = "<hr>"; // Horizontal rule. Two to make sure the content doesn't become a title.
            const embedTitle = embed.url ?
                `<a href="${escapeHtml(embed.url)}">${escapeHtml(embed.title)}</a>`
                : (embed.title ? escapeHtml(embed.title) : undefined);
            if (embedTitle) {
                embedContent += `<h5>${embedTitle}</h5>`; // h5 is probably best.
            }
            if (embed.description) {
                embedContent += "<p>";
                embedContent += markdown.toHTML(embed.description, {
                    discordCallback: this.getDiscordParseCallbacksHTML(msg),
                    embed: true,
                }) + "</p>";
            }
            if (embed.fields) {
                for (const field of embed.fields) {
                    embedContent += `<p><strong>${escapeHtml(field.name)}</strong><br>`;
                    embedContent += markdown.toHTML(field.value, {
                        discordCallback: this.getDiscordParseCallbacks(msg),
                        embed: true,
                    }) + "</p>";
                }
            }
            if (embed.image) {
                const imgUrl = escapeHtml(embed.image.url);
                embedContent += `<p>Image: <a href="${imgUrl}">${imgUrl}</a></p>`;
github Half-Shot / matrix-appservice-discord / src / matrixcommandhandler.ts View on Github external
const permissionCheck: CommandPermissonCheck = async (permission) => {
            if (permission.selfService && !this.config.bridge.enableSelfServiceBridging) {
                return "The owner of this bridge does not permit self-service bridging.";
            }
            return await Util.CheckMatrixPermission(
                this.bridge.getIntent().getClient(),
                event.sender,
                event.room_id,
                permission.level,
                permission.cat,
                permission.subcat,
            );
        };

        const reply = await Util.ParseCommand("!discord", event.content!.body!, actions, parameters, permissionCheck);
        const formattedReply = markdown.toHTML(reply);

        await this.bridge.getIntent().sendMessage(event.room_id, {
            body: reply,
            format: "org.matrix.custom.html",
            formatted_body: formattedReply,
            msgtype: "m.notice",
        });
    }
github Half-Shot / matrix-appservice-discord / src / discordmessageprocessor.ts View on Github external
}
            if (embed.fields) {
                for (const field of embed.fields) {
                    embedContent += `\n**${field.name}**\n`;
                    embedContent += markdown.toHTML(field.value, {
                        discordCallback: this.getDiscordParseCallbacks(msg),
                        discordOnly: true,
                        escapeHTML: false,
                    });
                }
            }
            if (embed.image) {
                embedContent += "\nImage: " + embed.image.url;
            }
            if (embed.footer) {
                embedContent += "\n" + markdown.toHTML(embed.footer.text, {
                    discordCallback: this.getDiscordParseCallbacks(msg),
                    discordOnly: true,
                    escapeHTML: false,
                });
            }
            content += embedContent;
        }
        return content;
    }
github Half-Shot / matrix-appservice-discord / src / discordmessageprocessor.ts View on Github external
if (embed.fields) {
                for (const field of embed.fields) {
                    embedContent += `<p><strong>${escapeHtml(field.name)}</strong><br>`;
                    embedContent += markdown.toHTML(field.value, {
                        discordCallback: this.getDiscordParseCallbacks(msg),
                        embed: true,
                    }) + "</p>";
                }
            }
            if (embed.image) {
                const imgUrl = escapeHtml(embed.image.url);
                embedContent += `<p>Image: <a href="${imgUrl}">${imgUrl}</a></p>`;
            }
            if (embed.footer) {
                embedContent += "<p>";
                embedContent += markdown.toHTML(embed.footer.text, {
                    discordCallback: this.getDiscordParseCallbacksHTML(msg),
                    embed: true,
                }) + "</p>";
            }
            content += embedContent;
        }
        return content;
    }

discord-markdown

A markdown parser for Discord messages

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular discord-markdown functions