File tree 1 file changed +10
-2
lines changed
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,14 @@ import { sendWithMessageOwnership } from '../util/send';
6
6
7
7
const CODEBLOCK = '```' ;
8
8
9
+ // Custom escape function instead of using discord.js Util.escapeCodeBlock because this
10
+ // produces better results with template literal types. Discord's markdown handling is pretty
11
+ // bad. It doesn't properly handle escaping back ticks, so we instead insert zero width spaces
12
+ // so that users cannot escape our code block.
13
+ function escapeCode ( code : string ) {
14
+ return code . replace ( / ` ` ` / g, '`\u200B`\u200B`' ) ;
15
+ }
16
+
9
17
export class TwoslashModule extends Module {
10
18
@command ( {
11
19
single : true ,
@@ -47,7 +55,7 @@ export class TwoslashModule extends Module {
47
55
48
56
await sendWithMessageOwnership (
49
57
msg ,
50
- `${ CODEBLOCK } typescript\n${ value . text } ${ CODEBLOCK } ` ,
58
+ `${ CODEBLOCK } typescript\n${ escapeCode ( value . text ) } ${ CODEBLOCK } ` ,
51
59
) ;
52
60
}
53
61
@@ -138,7 +146,7 @@ export class TwoslashModule extends Module {
138
146
const output = resultLines . join ( '\n' ) ;
139
147
return sendWithMessageOwnership (
140
148
msg ,
141
- `${ CODEBLOCK } ts\n${ output } ${ CODEBLOCK } \n` ,
149
+ `${ CODEBLOCK } ts\n${ escapeCode ( output ) } ${ CODEBLOCK } \n` ,
142
150
) ;
143
151
}
144
152
}
You can’t perform that action at this time.
0 commit comments