Improve quality of Discord formatted output

legacy
Charlotte Som 2021-09-13 20:10:22 +01:00
parent 06f7fb729a
commit 079efa5095
1 changed files with 14 additions and 2 deletions

View File

@ -48,7 +48,16 @@ pub fn format_discord(message_content: &[MessageComponent]) -> String {
.map(|component| match component { .map(|component| match component {
MessageComponent::Plain(text) => text.to_string(), // TODO: Escape MessageComponent::Plain(text) => text.to_string(), // TODO: Escape
MessageComponent::Link { target, .. } => target.to_string(), // TODO: Link text MessageComponent::Link { target, text } => {
let formatted_text = format_discord(text);
// TODO: Maybe tolerate a missing http(s) URL scheme?
if &formatted_text == target {
formatted_text
} else {
format!("{} ({})", formatted_text, target)
}
}
MessageComponent::Italic(inner) => format!("*{}*", format_discord(inner)), MessageComponent::Italic(inner) => format!("*{}*", format_discord(inner)),
MessageComponent::Bold(inner) => format!("**{}**", format_discord(inner)), MessageComponent::Bold(inner) => format!("**{}**", format_discord(inner)),
@ -69,7 +78,10 @@ pub fn format_discord(message_content: &[MessageComponent]) -> String {
MessageComponent::Spoiler { content, .. } => format!("||{}||", format_discord(content)), // TODO: Spoiler reason MessageComponent::Spoiler { content, .. } => format!("||{}||", format_discord(content)), // TODO: Spoiler reason
MessageComponent::HardBreak => "\n".to_string(), MessageComponent::HardBreak => "\n".to_string(),
MessageComponent::BlockQuote(inner) => format!("> {}", format_discord(inner)), MessageComponent::BlockQuote(inner) => format_discord(inner)
.lines()
.map(|l| format!("> {}\n", l))
.collect(),
}) })
.collect() .collect()
} }