Skip to content

Commit

Permalink
Merge pull request #57 from prettier/issue-52
Browse files Browse the repository at this point in the history
Indent interpolated-code after outdent
  • Loading branch information
Shinigami92 authored Jan 4, 2020
2 parents 219ea3d + 7a513a9 commit e29fe84
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ export const plugin: Plugin = {
break;
case 'indent':
case 'newline':
case 'outdent':
result = printIndent(previousToken, result, indent, indentLevel);
result += '| ';
break;
Expand Down
8 changes: 8 additions & 0 deletions test/issues/issue-52/formatted.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- const variableWithHtmlString = '<span></span>';
div
| !{variableWithHtmlString}

div
a(href="")
h6 A
| !{veranstaltung.renderedPresseText()}
14 changes: 14 additions & 0 deletions test/issues/issue-52/issue-52.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { format } from 'prettier';
import { plugin } from './../../../src/index';

describe('Issues', () => {
test('should handle literal line', () => {
const expected: string = readFileSync(resolve(__dirname, 'formatted.pug'), 'utf8');
const code: string = readFileSync(resolve(__dirname, 'unformatted.pug'), 'utf8');
const actual: string = format(code, { parser: 'pug' as any, plugins: [plugin] });

expect(actual).toBe(expected);
});
});
8 changes: 8 additions & 0 deletions test/issues/issue-52/unformatted.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- const variableWithHtmlString = '<span></span>';
div
| !{variableWithHtmlString}

div
a(href="")
h6 A
| !{veranstaltung.renderedPresseText()}

0 comments on commit e29fe84

Please sign in to comment.