-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert text styles between IRC/Discord #205
Convert text styles between IRC/Discord #205
Conversation
…italics and underlining will now be converted between discord and IRC.
…support colorized text.
Ah hell, there's some inconsistent conversion from irc->discord if you do some nested styles. |
Nevermind! Took a different approach to IRC->discord formatting with the same package that should have less weird results. |
I don't think this is relevant, but I was poking around at doing a configuration to allow stripping of mIRC formatting and I think I found a bug in how |
Good to know. This PR only uses But the funny coincidence is that I was the one who added the stripping functions in |
lib/formatting.js
Outdated
|
||
function mdNodeToIRC(node) { | ||
let content = node.content; | ||
if (_.isArray(content)) content = content.map(mdNodeToIRC).join(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just use Array.isArray
I guess?
lib/formatting.js
Outdated
export function formatFromIRCToDiscord(text) { | ||
const blocks = ircFormatting.parse(text).map(block => | ||
// Consider reverse as italic, some IRC clients use that | ||
_.assign({}, block, { italic: block.italic || block.reverse }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package has a Node >6 requirement anyway, since discord.js enforces that, so could do
{
...block,
{ italic: block.italic || block.reverse }
}
Thanks! This seems useful, and the implementation looks clean. |
Ah my bad, not sure how I overlooked the babel config and node requirements. |
I'll cut a release when we've got the last two outstanding PRs merged. |
Released in 2.3.0! |
Got a question about this, is it possible to have IRC colors show in Discord, or is it only formatting like bold and underline? |
Only formatting, discord markdown doesn't have any coloring option (except for syntax highlighting) |
for (let i = 0; i <= blocks.length; i += 1) { | ||
// Default to unstyled blocks when index out of range | ||
const block = blocks[i] || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When can blocks[i]
ever be undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, i <= blocks.length
not i < blocks.length
. Sneaky code.
This is a continuation of #97, but instead of manually parsing the text ourselves, I've opted to use the
irc-formatter
,irc-colors
, andsimple-markdown
packages to keep this project's code clean. (I thinksimple-markdown
is the parser Discord uses but I assume that only because they have their own fork of it on github.)Resolves #195