Skip to content

Commit cee5901

Browse files
committed
only strip newlines when parsing strings
1 parent bc64dc2 commit cee5901

File tree

2 files changed

+189
-77
lines changed

2 files changed

+189
-77
lines changed

fasthtml/components.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,14 @@ def _f(*c, target_id=None, **kwargs): return ft_hx(tag, *c, target_id=target_id,
207207
def html2ft(html, attr1st=False):
208208
"""Convert HTML to an `ft` expression"""
209209
rev_map = {'class': 'cls', 'for': 'fr'}
210-
210+
211211
def _parse(elm, lvl=0, indent=4):
212-
if isinstance(elm, str): return repr(elm.strip()) if elm.strip() else ''
212+
if isinstance(elm, str): return repr(elm.strip("\n")) if elm.strip() else ''
213213
if isinstance(elm, list): return '\n'.join(_parse(o, lvl) for o in elm)
214214
tag_name = elm.name.capitalize().replace("-", "_")
215215
if tag_name=='[document]': return _parse(list(elm.children), lvl)
216216
cts = elm.contents
217-
cs = [repr(c.strip()) if isinstance(c, str) else _parse(c, lvl+1)
217+
cs = [repr(c.strip("\n")) if isinstance(c, str) else _parse(c, lvl+1)
218218
for c in cts if str(c).strip()]
219219
attrs, exotic_attrs = [], {}
220220
for key, value in sorted(elm.attrs.items(), key=lambda x: x[0]=='class'):

0 commit comments

Comments
 (0)