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

WIP | Fix handling for table_style to prevent repeated re-splitting #1

Closed
wants to merge 2 commits into from

Conversation

kdipippo
Copy link

@kdipippo kdipippo commented May 29, 2024

TODO for me:

  • Migrate tests to use existing test.py file, remove pytest dependencies.
  • Sanitize HTML input and commit to this directory
  • Update README for setting table style
  • Test for invalid table style, returns the following long error:
File "/opt/homebrew/lib/python3.12/site-packages/html4docx/h4d.py", line 355, in handle_table
    self.table.style = self.table_style
    ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/docx/table.py", line 123, in style
    style_id = self.part.get_style_id(style_or_name, WD_STYLE_TYPE.TABLE)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/docx/parts/document.py", line 78, in get_style_id
    return self.styles.get_style_id(style_or_name, style_type)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/docx/styles/styles.py", line 101, in get_style_id
    return self._get_style_id_from_name(style_or_name, style_type)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/docx/styles/styles.py", line 130, in _get_style_id_from_name
    return self._get_style_id_from_style(self[style_name], style_type)
                                         ~~~~^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/docx/styles/styles.py", line 50, in __getitem__
    raise KeyError("no style with name '%s'" % key)
KeyError: "no style with name 'Plain Table 1'"

Copy link
Owner

Choose a reason for hiding this comment

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

Hello @kdipippo! Thanks for contribute with this project! Could you explain why create a separated unitttest file instead add this test to tests/test.py? There you don't need to setup and clean because there is already methods to do this for you.

Copy link
Author

Choose a reason for hiding this comment

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

Oh sweet! Thanks for the comment! I'll rework to use test.py. My bad, I missed that this repo has unit testing set up.

@kdipippo kdipippo changed the title Fix handling for table_style to prevent repeated re-splitting WIP | Fix handling for table_style to prevent repeated re-splitting May 31, 2024
@kdipippo
Copy link
Author

kdipippo commented Jun 4, 2024

Going to close this and re-open as an issue first and then re-make the PR correctly

@kdipippo kdipippo closed this Jun 4, 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