Closed Archmonger closed 2 years ago
Hi there, and thanks for your suggestion!
I think the following pre-commit config will accomplish what you want:
repos:
- repo: https://github.com/rtts/djhtml
rev: 'main' # replace with the latest tag on GitHub
hooks:
- id: djhtml
exclude: ^docs/
Could you try this and see if it works?
Alternatively, if you're not using pre-commit, you can combine find
and xargs
to accomplish the desired behavior, with the added benefit that you can specify more advanced inclusion/exclusion rules as needed:
find -name *.html -not -path "./docs/*" | xargs djhtml -i
find
or xargs
?For anyone who also stumbles across this one this is how I solved it.
Create an extra python script which invokes djhtml
(requires .venv)`:
import subprocess
import sys
def main():
filepath = sys.argv[1]
if "templates" in filepath and filepath.endswith(".html"):
args = [".\\.venv\\scripts\\djhtml.exe", "-i", filepath]
ret = subprocess.Popen(args).wait()
exit(ret)
if __name__ == "__main__":
main()
Afterwards I created an external tool in Pycharm so that I can use djhtml
safely as on save-hook in my IDE.
Unfertunately I did not find another way under Windows without using pre-commit
. Always running djhtml
on save is not working since it breaks (it itendends incorreclty) for instance .toml
files.
Currently running into some issues where djhtml is formatting my
mkdocs
documentation directory, causing unnecessary html code modifications.Ideally I'd like to be able to exclude my
./docs/*
to prevent that.