node-ts-dedent icon indicating copy to clipboard operation
node-ts-dedent copied to clipboard

Backticks (possibly) cause no dedent

Open shellscape opened this issue 2 years ago • 1 comments

I've got a weird one for you, one that seems to be a problem in the older dedent package as well (https://github.com/dmnd/dedent/issues/26). Escaped backticks result in no dedent-ing.

const content = '    [APBannerManager showBannerWithTitle:@"Title"\n' +
    '                                          subtitle:@"Subtitle"\n' +
    '                                          body:@"Body"\n' +
    '                                          image:[UIImage imageNamed:@"myPicture"]\n' +
    '                                          actionBlock:^(APBannerActionType type) {\n' +
    '                                            switch (type) {\n' +
    '                                              case APBannerActionTypeTap:\n' +
    '                                                NSLog(@"TAP");\n' +
    '                                                break;\n' +
    '                                              case APBannerActionTypeDismiss:\n' +
    '                                                NSLog(@"DISMISS");\n' +
    '                                                break;\n' +
    '                                            }\n' +
    '                                          }];';
   dedent(`\`\`\`
${content}
\`\`\``);

What we end up with is:

\`\`\`
    [APBannerManager showBannerWithTitle:@"Title"
                                          subtitle:@"Subtitle"
                                          body:@"Body"
                                          image:[UIImage imageNamed:@"myPicture"]
                                          actionBlock:^(APBannerActionType type) {
                                            switch (type) {
                                              case APBannerActionTypeTap:
                                                NSLog(@"TAP");
                                                break;
                                              case APBannerActionTypeDismiss:
                                                NSLog(@"DISMISS");
                                                break;
                                            }
                                          }];
\`\`\`

shellscape avatar Aug 22 '21 02:08 shellscape

Your string starts with a literal backtick, so there's no leading whitespace, so this library would do nothing, by design. I think.

Drarok avatar Oct 05 '21 00:10 Drarok

Agree to Drarok - as the string starts (and ends) without indentation there is nothing to dedent

tamino-martinius avatar Nov 11 '22 17:11 tamino-martinius