diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index eaf78ef42..b46933c66 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -11,21 +11,24 @@ jobs: matrix: tool: [django, wagtail, pallets, apostrophe, bolt] include: - - tool: django - repo: https://github.com/django/django - profile: django - - tool: wagtail - repo: https://github.com/wagtail/wagtail - profile: django - - tool: pallets - repo: https://github.com/pallets/website - profile: jinja - - tool: apostrophe - repo: https://github.com/apostrophecms/apostrophe - profile: nunjucks - - tool: bolt - repo: https://github.com/bolt/core - profile: nunjucks + - tool: django + repo: https://github.com/django/django + profile: django + - tool: wagtail + repo: https://github.com/wagtail/wagtail + profile: django + - tool: pallets + repo: https://github.com/pallets/website + profile: jinja + - tool: apostrophe + repo: https://github.com/apostrophecms/apostrophe + profile: nunjucks + - tool: bolt + repo: https://github.com/bolt/core + profile: nunjucks + - tool: sylius + repo: https://github.com/Sylius/Sylius + profile: nunjucks name: format runs-on: ubuntu-latest steps: @@ -49,23 +52,23 @@ jobs: mkdir "${{ matrix.tool }}_raw"; mkdir "${{ matrix.tool }}_source" cd "${{ matrix.tool }}_raw"; git clone --depth 1 "${{ matrix.repo }}" .; cd .. find "${{ matrix.tool }}_raw" -iname '*.html*' -exec mv '{}' "${{ matrix.tool }}_source/" \; - + - name: publish source uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: "./${{ matrix.tool }}_source" - publish_branch: "${{ matrix.tool }}-source" + publish_dir: ./${{ matrix.tool }}_source + publish_branch: ${{ matrix.tool }}-source enable_jekyll: true force_orphan: true - + - name: cleanup source run: rm -r "${{ matrix.tool }}_source"; rm -r "${{ matrix.tool }}_raw" - uses: actions/checkout@v3 with: - path: "${{ matrix.tool }}-source" - ref: "${{ matrix.tool }}-source" + path: ${{ matrix.tool }}-source + ref: ${{ matrix.tool }}-source - name: setup branch run: | @@ -74,12 +77,12 @@ jobs: git config user.email "$(git log -n 1 --pretty=format:%ae)" git branch --unset-upstream git push --force origin "${{ matrix.tool }}-source":"${{ matrix.tool }}-djlint" - + - name: format run: | cd src poetry run python -m djlint "../${{ matrix.tool }}-source" --profile=${{ matrix.profile }} --reformat --warn --quiet - + - name: publish foramtted run: | cd "${{ matrix.tool }}-source" @@ -87,4 +90,3 @@ jobs: git add . git commit -m "formatted with djLint $DJ_VERSION" git push origin "${{ matrix.tool }}-source":"${{ matrix.tool }}-djlint" - diff --git a/docs/src/docs/languages/twig.md b/docs/src/docs/languages/twig.md index 5a2623ea1..ff676c64b 100644 --- a/docs/src/docs/languages/twig.md +++ b/docs/src/docs/languages/twig.md @@ -33,3 +33,5 @@ profile="{{ tool }}" ## Real Life Examples! - [bolt](https://github.com/bolt/core) source code [reformatted](https://github.com/Riverside-Healthcare/djLint/compare/bolt-source...Riverside-Healthcare:djLint:bolt-djlint) + +- [Sylius](https://github.com/Sylius/Sylius) source code [reformatted](https://github.com/Riverside-Healthcare/djLint/compare/sylius-source...Riverside-Healthcare:djLint:sylius-djlint) diff --git a/src/djlint/formatter/compress.py b/src/djlint/formatter/compress.py index 08ee91d5c..378bd7898 100644 --- a/src/djlint/formatter/compress.py +++ b/src/djlint/formatter/compress.py @@ -36,13 +36,14 @@ def _clean_tag(match: re.Match) -> str: open_braket = match.group(1) tag = _fix_case(match.group(2)) + attributes = ( (" " + " ".join(x.strip() for x in match.group(3).strip().splitlines())) if match.group(3) else "" ) close_braket = ( - match.group(7) if "/" not in match.group(7) else f" {match.group(7)}" + match.group(4) if "/" not in match.group(4) else f" {match.group(4)}" ) return f"{open_braket}{tag}{attributes}{close_braket}" diff --git a/src/djlint/settings.py b/src/djlint/settings.py index e1afbed95..01226b555 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -560,18 +560,13 @@ def __init__( """ ) - self.html_tag_regex = ( - r""" + self.html_tag_regex = r""" (!]+\b) # a tag name - # ((?:\s*?(?:\"[^\"]*\"|'[^']*'|{{(?:(?!}}).)*}}|{%(?:(?!%}).)*%}|[^'\">{}/\s]|/(?!>)))+)? # any attributes - ((?:\s*?""" - + self.attribute_pattern - + r""")+)? + ([^\s>!\[]+\b) # a tag name + ((?:\s*?(?:\"[^\"]*\"|'[^']*'|{{(?:(?!}}).)*}}|{%(?:(?!%}).)*%}|[^'\">{}/\s]|/(?!>)))+)? # any attributes \s*? # potentially some whitespace (/?>) # a closing braket (/> or >) """ - ) self.attribute_style_pattern: str = r"^(.*?)(style=)([\"|'])(([^\"']+?;)+?)\3" diff --git a/tests/test_html/test_doctype_declarations.py b/tests/test_html/test_doctype_declarations.py index 2365c0de5..7c6839432 100644 --- a/tests/test_html/test_doctype_declarations.py +++ b/tests/test_html/test_doctype_declarations.py @@ -33,8 +33,7 @@ "\n" ), ( - '\n' + '\n' "\n" " \n" " An HTML standard template\n" @@ -62,8 +61,7 @@ "\n" ), ( - '\n' + '\n' "\n" " \n" " An HTML standard template\n" @@ -91,8 +89,7 @@ "\n" ), ( - '\n' + '\n' "\n" " \n" " An HTML standard template\n"