File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 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';
66
77const CODEBLOCK = '```' ;
88
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+
917export class TwoslashModule extends Module {
1018 @command ( {
1119 single : true ,
@@ -47,7 +55,7 @@ export class TwoslashModule extends Module {
4755
4856 await sendWithMessageOwnership (
4957 msg ,
50- `${ CODEBLOCK } typescript\n${ value . text } ${ CODEBLOCK } ` ,
58+ `${ CODEBLOCK } typescript\n${ escapeCode ( value . text ) } ${ CODEBLOCK } ` ,
5159 ) ;
5260 }
5361
@@ -138,7 +146,7 @@ export class TwoslashModule extends Module {
138146 const output = resultLines . join ( '\n' ) ;
139147 return sendWithMessageOwnership (
140148 msg ,
141- `${ CODEBLOCK } ts\n${ output } ${ CODEBLOCK } \n` ,
149+ `${ CODEBLOCK } ts\n${ escapeCode ( output ) } ${ CODEBLOCK } \n` ,
142150 ) ;
143151 }
144152}
You can’t perform that action at this time.
0 commit comments