Skip to content

Instantly share code, notes, and snippets.

@therealbenpai
Created March 20, 2023 18:28
Show Gist options
  • Save therealbenpai/1f95f4237982e182f60e05b918dd43b9 to your computer and use it in GitHub Desktop.
Save therealbenpai/1f95f4237982e182f60e05b918dd43b9 to your computer and use it in GitHub Desktop.
Reddit Text Formatter
class TextFormatter {
static bold = (text) => `**${text}**`;
static italic = (text) => `*${text}*`;
static strikethrough = (text) => `~~${text}~~`;
static spoiler = (text) => `>!${text}!<`;
static code = (text) => `\`${text}\``;
static codeBlock = (text) => text.split('\n').unshift('').push('').map(line => ` ${line}`).join('\n');
static quote = (text) => `> ${text}`;
static quoteBlock = (text) => `>>> ${text}`;
static link = (text, url) => `[${text}](${url})`;
static list = (...items) => (items.map((item, index) => `${index + 1}) ${item}`)).join('\n');
}
export default TextFormatter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment