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 elements rendered with linebreak? #139

Closed
allefeld opened this issue Feb 24, 2021 · 1 comment
Closed

inline elements rendered with linebreak? #139

allefeld opened this issue Feb 24, 2021 · 1 comment

Comments

@allefeld
Copy link

Example: I'm trying to create a p element that contains the text "goodbye cruel world", i.e. with an inline i element:

par = dominate.tags.p('goodbye ', dominate.tags.i('cruel'), ' world')
print(par.render())

Result:

<p>goodbye 
  <i>cruel</i> world
</p>

Why is there a linebreak '\n' inserted before (but not after) the i element? (Which can amount to the addition of whitespace.)

Alternatively, is there a way to directly specify the innerHTML of the p element? Something like

dominate.tags.p(inner_html='goodbye <i>cruel</i> world')
@Knio
Copy link
Owner

Knio commented Feb 24, 2021

This seems to be a bug in the i element not specifying inline (see: https://github.com/Knio/dominate/blob/master/dominate/tags.py#L703-L704)

As a workaround, you can pass .render(pretty=False) , or set the is_pretty property to False on par (ie if you want to maintain the pretty formatting for the rest of the document):

>>> par.render(pretty=False)
'<p>goodbye <i>cruel</i> world</p>'

>>> par.is_pretty = False
>>> par.render()
'<p>goodbye <i>cruel</i> world</p>'

Knio added a commit that referenced this issue Jul 25, 2022
@Knio Knio closed this as completed in 842759b Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants