[pug] add auto indent
See original GitHub issue- VSCode Version: 1.30.0
- OS Version: Windows 10 x64 (1803)
The auto indentation when using pug is not working. Here is an example of VSCode (1.30.0) vs Sublime Text (3.1.1) and Atom (1.33.0) showing the expected behavior:
And here a gif showing what happen in each one while typing (the tab and space keys were not used):
Steps to Reproduce:
- Open a tab and select Pug syntax
- Type some tags like the next example without using tab or space keys:
h1 test
.example
ul
li
Does this issue occur when all extensions are disabled?: Yes
Extensions enabled:
- advanced-new-file
- Bookmarks
- Bracket Pair Colorizer
- Code Spell Checker
- colorize
- Identical Sublime Monokai C# theme and colorizer
- Path Autocomplete
- Relative Path
- Sublime Text Keymap and Settings Importer
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to make the generated HTML file auto-indent in ...
Ctrl + Alt + L on Windows and Linux. Option + Command + L on Mac OS X. See Reformatting Source Code. Updated....
Read more >Attributes - Pug.js
If passing in attributes from a mixin call, this is done automatically. Get an update when we release new features.
Read more >Pug autoformat breaks template : WEB-53742
WEB-32975 Pug: line after buffered code loses its indent on formatting. Consider the following pug/jade ... Thanks for taking the time to create...
Read more >@prettier/plugin-pug - npm
If you have tags at the top/root that are indented, they will lose indentation due to a technical limitation of pug. Please check...
Read more >Pug HTML Template Engine: A Beginner's Guide - SitePoint
CodePen, for example, has Pug support baked right in. Simply create a new pen, then select Settings > HTML and choose Pug as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, so I found a complete regex pattern for pug in the original repo that vscode’s pug extension is based on: davidrios/pug-tmbundle. This is the relevant file: /Preferences/Miscellaneous.tmPreferences
Here’s the the original regex definition for increaseIndentPattern:
and for decreaseIndentPattern:
and here are the reformatted regex definitions:
I reformatted the regex pattern, removing the comments, newlines, and free-spacing mode modifier, and properly escaped everything. It appears to be working correctly based on my testing. Anyone else care to try it out?
I made a pull request with the incorporated changes: https://github.com/Microsoft/vscode/pull/66099
I made a really hacky fix for myself with the following addition to /extensions/pug/language-configuration.json:
Ideally, these rules would filter for tags which are not self closing, so that if an element cannot have any children adding a newline doesn’t auto-indent.