AnswerDotAI / fasthtml

The fastest way to create an HTML app
https://fastht.ml/
Apache License 2.0
5.27k stars 219 forks source link

[FEATURE] Improve spacing between elements #441

Closed pydanny closed 1 week ago

pydanny commented 2 weeks ago

Is your feature request related to a problem? Please describe.

FastHTML no longer includes a space between HTML elements. This can cause issues with lists of A tags and other elements.

Describe the solution you'd like

An concise, easy-to-use method of adding spaces between tags.

Example code

Perhaps simply add this to FastHTML or FastCore:

def S(e):
    return Span(e, ' ')

Should also consider *args and **kwargs, the above approach is arguably simplistic.

Another approach would be tor add a space or s attribute to tags

# Space attribute
A(href='http://fastht.ml', space=True)('FastHTML')

# S shortcut
A(href='http://fastht.ml', S=True)('FastHTML')

Similar implementations

I used the S() function approach in the releases app. You can see the definition of the tag and one of the implementations here.

Problem solved

Makes it easier to format text.

Confirmation Please confirm the following:

dgwyer commented 2 weeks ago

Interesting suggestion. Do you happen to know which PR it was that reverted the spacing? Curious to know how it was originally implemented.

Also, would you be able to provide any examples of HTML markup where you would find spacing around elements useful that's not working anymore due to the FastHTML update? It might help to figure out alternate solutions.

Also, I just tested the following alternatives. Would any of these be useful?

@rt("/")
def get():
    # return Div(A('Link #1'), NotStr(' '), A('Link #2'))
    # return Div(A('Link #1'), NotStr(' '), A('Link #2'))
    #return Div(A('Link #1', style="margin-right: 1rem;"), A('Link #2'))
    return Div(A('Link #1'), ' ', A('Link #2'))
pydanny commented 2 weeks ago

I'm not sure when things changed and tags stopped having breaking HTML between them, I just noted that the headers and footers of my personal site at https://daniel.feldroy.com lost the spaces between them.

pydanny commented 1 week ago

Addressed with Nbsp()