Skip to content

Commit 1bcb6bb

Browse files
authored
Handle autocloseable tag with trailing text correctly (#183)
1 parent 63a98fd commit 1bcb6bb

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

src/printer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,11 @@ export class PugPrinter {
14181418
}
14191419

14201420
private slash(token: SlashToken): string {
1421-
return '/';
1421+
let result: string = '/';
1422+
if (this.nextToken?.type === 'text') {
1423+
result += ' ';
1424+
}
1425+
return result;
14221426
}
14231427

14241428
//#endregion
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
span Text
2+
br/ more text
3+
4+
div
5+
span Text
6+
br/ more text with very long text text text text text text text text text text
7+
br/ and even more text text text text text text text text text text text text
8+
9+
span Lorem ipsum dolor sit amet, consectetur adipisicing elit.
10+
| Laudantium laborum quod harum fuga ipsum est voluptates assumenda commodi,
11+
br/ nihil dolores recusandae nobis labore
12+
| minus nostrum cumque eum sit similique!
13+
br/
14+
br/ Molestiae! Lorem ipsum dolor sit amet, consectetur adipisicing elit.
15+
br/
16+
| Laudantium laborum quod harum fuga ipsum.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { readFileSync } from 'fs';
2+
import { resolve } from 'path';
3+
import { format } from 'prettier';
4+
import { plugin } from './../../../src/index';
5+
6+
describe('Issues', () => {
7+
test('should handle autocloseable tag with trailing text correctly', () => {
8+
const expected: string = readFileSync(resolve(__dirname, 'formatted.pug'), 'utf8');
9+
const code: string = readFileSync(resolve(__dirname, 'unformatted.pug'), 'utf8');
10+
const actual: string = format(code, { parser: 'pug', plugins: [plugin] });
11+
12+
expect(actual).toBe(expected);
13+
});
14+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
span Text
2+
br/ more text
3+
4+
div
5+
span Text
6+
br/ more text with very long text text text text text text text text text text
7+
br/ and even more text text text text text text text text text text text text
8+
9+
span Lorem ipsum dolor sit amet, consectetur adipisicing elit.
10+
| Laudantium laborum quod harum fuga ipsum est voluptates assumenda commodi,
11+
br/ nihil dolores recusandae nobis labore
12+
| minus nostrum cumque eum sit similique!
13+
br/
14+
br/ Molestiae! Lorem ipsum dolor sit amet, consectetur adipisicing elit.
15+
br/
16+
| Laudantium laborum quod harum fuga ipsum.

0 commit comments

Comments
 (0)