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

inline_fragment not worked for python #388

Open
PAvel00m opened this issue Oct 7, 2024 · 6 comments
Open

inline_fragment not worked for python #388

PAvel00m opened this issue Oct 7, 2024 · 6 comments

Comments

@PAvel00m
Copy link

PAvel00m commented Oct 7, 2024

Hi, when passing valid html to a function, an empty string is returned

Python 3.8.18
MacOS Sequoia 15.0

template = """
        <html>
            <head></head>
            <body>
                <table>
                    </tbody>
                        <tr>
                            <th>Test</th>
                            <td>text</td>
                        </tr>
                    </tbody>
                </table>
            </body>
        </html>
"""

rendered_content = css_inline.inline_fragment(
    template,
    """
    body {
        font-family: Arial, sans-serif;
    }
    
    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
    }
    """
)
@Stranger6667
Copy link
Owner

Thanks for the report!

I haven't anticipated this use case as template in your example is not a fragment, but a complete HTML. However, returning an empty string is confusing indeed. Not sure if it would be better to return an error on non-fragment inputs or just fall back to something like this automatically:

css_inline.inline(template, extra_css="""
    body {
        font-family: Arial, sans-serif;
    }
    
    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
    }
    """)
# <html><head></head>
#            <body style="font-family: Arial, sans-serif;">
#                <table style="border: 1px solid black;border-collapse: collapse;">
#
#                        <tbody><tr>
#                             <th style="border: 1px solid black;border-collapse: collapse;">Test</th>
#                            <td style="border: 1px solid black;border-collapse: collapse;">text</td>
#                        </tr>
#                    </tbody>
#                </table>
#
#
# </body></html>

In any event, I think the behavior of inline_fragment should be changed + docs should be updated to reflect this case.

@PAvel00m
Copy link
Author

PAvel00m commented Oct 7, 2024

it's just that I use inline_fragment after rendering the jinja2 template and not always the template is html and I then don't have to wrap in tags like BeautifulSoup does

@Stranger6667
Copy link
Owner

Makes sense! Then, I'd add some fallback for non-fragments to avoid whitespace-only output

@PAvel00m
Copy link
Author

PAvel00m commented Oct 7, 2024

I did, it's just the blank line is really confusing. thanks for the reply!

@Stranger6667
Copy link
Owner

I did, it's just the blank line is really confusing. thanks for the reply!

You are very welcome! To clarify, I meant that I am going to implement it directly in css-inline, so there is no need to put such conditions in your code. I don't have an ETA, but it should be a relatively simple change, so maybe in a few weeks I'll make a patch release :)

@PAvel00m
Copy link
Author

PAvel00m commented Oct 7, 2024

Great, thank you!

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

No branches or pull requests

2 participants