Remove white space in plain text formatter

Created on 30 August 2023, about 1 year ago

Problem/Motivation

When generating HTML with a plain text formatter, without any class/div/span information, there are still additional spaces in the output.

Steps to reproduce

Create a Views view with Title, ID, office_hours fields;
- under Format/Format/Format, set to 'Unformatted list' of 'Fields'
- under Format/Format/Settings, unset 'Add views row classes'
- under Format/Show, set to 'Fields',
- Under Format/Show/Settings, set 'Provide default field wrapper elements' to be able to set all fields to 'Inline', adding ';' as a separator;
-- Then, unset 'Provide default field wrapper elements'. See 🐛 inline fields and field wrapper elements: UI unexpected behavior Needs work
- under Fields, set Office_hours formatter to 'plain text'. Set the days separator to ';', removing the default line break. Set other formatting options.

Now, for all fields, set the Views options to make the View as clean as possible:
- unset Link label to the referenced entity
- unset Style settings / Add default classes
- set Rewrite results / Strip HTML tags
- set Rewrite results / Remove whitespace (if needed)

Proposed resolution

The twig manual contains several options:
1. {% spaceless %} tag, which is outdated
2. {% apply spaceless %} filter
3. whitespace trimming using '-'
Some blogs:
https://symfony.com/blog/better-white-space-control-in-twig-templates
http://vvv.tobiassjosten.net/symfony/trim-and-remove-twig-whitespace/

API changes

after some testing, the {% apply spaceless %} filter is applied to the twig file

🐛 Bug report
Status

Fixed

Version

1.11

Component

Code - formatter

Created by

🇳🇱Netherlands johnv

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024