Closed shapiromatron closed 8 months ago
I hope you don't mind that I used ChatGPT to answer your question. Its answer is quite useful:
djhtml -
To pipe the contents of the current open file in Visual Studio Code (VSCode) through the external command djhtml -
, follow these steps:
Install the Code Runner Extension:
Ctrl+Shift+X
on Windows/Linux, Cmd+Shift+X
on macOS), then searching for "Code Runner" and installing it.Configure Code Runner to Use the Terminal:
Ctrl+Shift+P
on Windows/Linux, Cmd+Shift+P
on macOS) and type Preferences: Open Settings (JSON)
. Select it to open the settings file."code-runner.executorMap": {
"html": "cat $fullFileName | djhtml - > $fullFileName.temp && mv $fullFileName.temp $fullFileName"
},
"code-runner.runInTerminal": true
cat $fullFileName | djhtml - > $fullFileName.temp && mv $fullFileName.temp $fullFileName
for HTML files. The command uses cat
to output the content of the file, pipes it through djhtml
, and writes the output to a temporary file, which is then moved to replace the original file.Ensure djhtml
is Installed:
djhtml
is installed on your system. You can install it via pip if it's not already installed:
pip install djhtml
Run the Command:
Ctrl+Alt+N
(or Cmd+Option+N
on macOS) to run the code using Code Runner. This will execute the command specified in the settings and replace the content of your current file with the formatted output.Check the Output:
Optional: Key Binding for the Operation:
Preferences: Open Keyboard Shortcuts (JSON)
. Select it to open the keybindings file.{
"key": "ctrl+shift+h",
"command": "code-runner.run",
"when": "editorLangId == 'html'"
}
Ctrl+Shift+H
(or a key combination of your choice) to format the HTML file when it's open in the editor.By following these steps, you can seamlessly format HTML using djhtml
directly within VSCode, improving your workflow and productivity.
Thanks! That's a nice tutorial. We ended up using the pre-commit hook instead; I didn't want to install a 3rd Code Runner plugin in VS Code.
Black and Ruff have nice integrations with VSCode so that when edits are made to a python file, the file is formatted on save. Is there a pattern that can be used to auto-format HTML using this project as well? I could submit a PR to add to the readme if there is a pattern, but instead of trying to figured it out myself, I figured I could ask to see if there's something available.
Thanks! Great project.