-
Notifications
You must be signed in to change notification settings - Fork 150
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
Trim Markdown code block syntax #1275
Conversation
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.
Heading in the right direction 👍 . The formatter looks good. Overall I wish our Matrix->IRC formatting code was less clunky (I would favour a pipeline of sorts) but I don't think we should go for a grand refactor here.
src/bridge/MatrixHandler.ts
Outdated
@@ -956,6 +975,11 @@ export class MatrixHandler { | |||
return; | |||
} | |||
|
|||
const potentialCodeText = trimCodeMessages(text); |
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.
Agreed that this isn't the best function to be doing this on. My wish is that we refactor this function to act as a pipeline of statements that modify a given event into an IRC message in a stateless context. Perhaps a better place would be IrcAction.fromMatrixAction
, which is intended to be the point where we format a Matrix Event into an IRC action.
Known issues that remain:
|
This is surprising, because I believe we have our own reply format which only includes a truncated form of the original message. Would it be possible to fix that? |
src/bridge/MatrixHandler.ts
Outdated
} | ||
|
||
let cacheBody = text; | ||
let cacheBody = event.content.body; |
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.
This changes the code so that we now cache the body, rather than trimCodeMessages(body)
, which seems like a potentially dangerous change? Maybe we should cache the text that we would be sending to IRC.
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.
Some more thoughts
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.
Couple of nits, otherwise okay. CI looks unhappy btw
src/bridge/MatrixHandler.ts
Outdated
@@ -964,8 +964,13 @@ export class MatrixHandler { | |||
cacheBody = reply.reply; | |||
} | |||
} | |||
let body = cacheBody.trim().substr(0, REPLY_SOURCE_MAX_LENGTH); |
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.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr is technically deprecated in favour of substring.
src/bridge/MatrixHandler.ts
Outdated
@@ -964,8 +964,13 @@ export class MatrixHandler { | |||
cacheBody = reply.reply; | |||
} | |||
} | |||
let body = cacheBody.trim().substr(0, REPLY_SOURCE_MAX_LENGTH); | |||
const nextNewLine = body.indexOf('\n'); |
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.
We tend to use " quotes here.
0494cba
to
f9373e6
Compare
Thanks! |
Fixes #1271
Removes the code block syntax and adds the monospace character
\x11
to the beginning of each line.If the trimmed message is longer than the
lineLimit
, it still gets uploaded instead of posted directly.