Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert keyword elements correctly #61

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

MattiasRosell
Copy link

@MattiasRosell MattiasRosell commented Sep 25, 2024

I noticed that the <del> tag was not converted into htpy's del_ correctly. The formatters also can not handle importing python's del keyword and would crash. Ruff would not output anything while Black would output the unformatted code.

I fixed these issues by:

  • Replacing div with div_ when converting html using html2htpy.
  • Adding a test checking that div is successfully converted to div_.
  • Adding consistent behaviour between Ruff and Black when the input can not be formatted.

@pelme then found out that htpy did not convert the del_ element to html correctly. So we fixed that as well.

  • Fix the del_ element not converting into <del> correctly.
  • Only remove underscore from elements named after Python's keywords.

@MattiasRosell MattiasRosell changed the title Convert del tags to htpy's del_ element in html2htpy Correctly convert <dev> tags to htpy's del_ element Sep 25, 2024
Copy link
Owner

@pelme pelme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: very nice, fixing annoyances in html2htpy is really helpful and makes it nicer to use!

tests/test_html2htpy.py Show resolved Hide resolved
htpy/html2htpy.py Outdated Show resolved Hide resolved
tests/test_element.py Outdated Show resolved Hide resolved

@pytest.mark.parametrize(
("element", "expected"),
[(imaginary, "<imaginary></imaginary>"), (imaginary_, "<imaginary-></imaginary->")],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should underscore always be replaced with a hyphen like this?

@MattiasRosell MattiasRosell changed the title Correctly convert <dev> tags to htpy's del_ element Convert keyword elements correctly Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants