Skip to content

Commit

Permalink
fix(formatter): fixed speed on formatter
Browse files Browse the repository at this point in the history
closes #601
  • Loading branch information
christopherpickering committed Apr 19, 2023
1 parent 846330b commit 57cf98d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 42 deletions.
53 changes: 26 additions & 27 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +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: sylius
repo: https://github.com/Sylius/Sylius
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:
Expand All @@ -52,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: |
Expand All @@ -77,17 +77,16 @@ 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"
export DJ_VERSION=$(poetry version --short)
git add .
git commit -m "formatted with djLint $DJ_VERSION"
git push origin "${{ matrix.tool }}-source":"${{ matrix.tool }}-djlint"
3 changes: 2 additions & 1 deletion src/djlint/formatter/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
11 changes: 3 additions & 8 deletions src/djlint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,18 +560,13 @@ def __init__(
"""
)

self.html_tag_regex = (
r"""
self.html_tag_regex = r"""
(</?(?:!(?!--))?) # an opening bracket (< or </ or <!), but not a comment
([^\s>!]+\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"

Expand Down
9 changes: 3 additions & 6 deletions tests/test_html/test_doctype_declarations.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"</html>\n"
),
(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"\n'
'"http://www.w3.org/TR/html4/frameset.dtd">\n'
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">\n'
"<html>\n"
" <head>\n"
" <title>An HTML standard template</title>\n"
Expand Down Expand Up @@ -62,8 +61,7 @@
"</html>\n"
),
(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n'
'"http://www.w3.org/TR/html4/strict.dtd">\n'
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n'
"<html>\n"
" <head>\n"
" <title>An HTML standard template</title>\n"
Expand Down Expand Up @@ -91,8 +89,7 @@
"</html>\n"
),
(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n'
'"http://www.w3.org/TR/html4/loose.dtd">\n'
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n'
"<html>\n"
" <head>\n"
" <title>An HTML standard template</title>\n"
Expand Down

0 comments on commit 57cf98d

Please sign in to comment.