Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to get rid of newlines with tidy/trim
I have a list of column names like this, one item per line for readability:
ID,
Type,
SKU,
Name,
Short description,
Description,
Brands,
...
I want to return that as a simple comma-separated list without spaces where the newlines occur. Can I use trim/replace to do that? All my efforts so far have failed. I’ve tried wrapping it in:
<txp:evaluate escape="tidy, trim">
ID,
Type,
SKU,
Name,
Short description,
Description,
Brands
</txp:evaluate>
<txp:evaluate escape="tidy" trim="/,\s/gm" replace=",">
ID,
Type,
SKU,
Name,
Short description,
Description,
Brands
</txp:evaluate>
<txp:evaluate escape="tidy" trim=",
" replace=",">
ID,
Type,
SKU,
Name,
Short description,
Description,
Brands
</txp:evaluate>
And various other permutations (e.g. \r
or \n
). I always get back:
ID, Type, SKU, Name, Short description, Description, Brands,
with spaces between the terms. Any tricks? Running 4.9.0-dev.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: How to get rid of newlines with tidy/trim
Try:
<txp:evaluate breakby="," break="," escape="tidy, trim">
ID,
Type,
SKU,
Name,
Short description,
Description,
Brands
</txp:evaluate>
TXP Builders – finely-crafted code, design and txp
Online
Re: How to get rid of newlines with tidy/trim
Or this:
<txp:evaluate trim="/,\s+/s" replace="," />
Offline
Re: How to get rid of newlines with tidy/trim
jakob wrote #339694:
Try:
<txp:evaluate breakby="," break="," escape="tidy, trim">...
Winner! I didn’t try both break
and breakby
. No idea why both are needed but it works a treat, thank you.
etc wrote #339695:
<txp:evaluate trim="/,\s+/s" replace="," />...
Oooft, sooo close. It works but it also outputs an extra blank row beneath the headings in the resulting CSV file. My guess is escape="tidy"
will fix that. Thank you. I wouldn’t have considered using /s
as I foolishly went with /m
since I thought, “Hey, it’s multi-line content…”
Edit: yep, adding escape="tidy"
fixes that. Woot. Two solutions. You guys rock.
Last edited by Bloke (Today 16:40:19)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: How to get rid of newlines with tidy/trim
Bloke wrote #339696:
Winner! I didn’t try both
break
andbreakby
. No idea why both are needed but it works a treat, thank you.
Because a lone break
had broken some ancient (and actually meaningless) pattern. Actually, break
always worked as ‘join’.
I wouldn’t have considered using
/s
as I foolishly went with/m
since I thought, “Hey, it’s multi-line content…”
You probably don’t need a modifier at all here, it was a blind shot.
Offline
Re: How to get rid of newlines with tidy/trim
etc wrote #339697:
Actually,
break
always worked as ‘join’.
Ah, yes of course. Naming conventions steeped in history…
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline