Problem/Motivation
When using a NID as class token for a table view display both row and table cell, the first digit of the NID gets replaced with an underscore.
Setup used for testing:
Drupal Version: 9.3.0-dev (The issue was also noted on 9.2.x)

Steps to reproduce
1. Create a view for any content type, with the following setup:
- List content
- Format: Table.
- Under Fields, add the node ID and node Title (or any other field, just for visualization.
- In the Format, Table setting. Add {{ nid }} as the Row class:

- In the fields settings, check the "Customize field HTML" and " Create a CSS class" options and add {{nid}} and the CSS Class. Apply the changes

- Inspect the table and check that the first digit on the ID is replaced with an underscore:

Proposed resolution
The actual NID gets rendered correctly, without the underscore.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| Screenshot from 2021-12-13 07-56-52.png | 70.11 KB | barone | |
| Screenshot from 2021-12-13 07-50-19.png | 126.95 KB | barone | |
| Screenshot from 2021-12-13 07-48-03.png | 59.96 KB | barone | |
| Screenshot from 2021-12-13 07-45-48.png | 51.32 KB | barone |
Comments
Comment #2
larowlanPretty sure you can't use numbers as classes in html
Try using node-{{nid}}
Comment #3
lendudeYes as @larowlan points out, classes cannot start on a number.
In Views this is assured in
\Drupal\views\Plugin\views\field\FieldPluginBase::elementClassesby a call to\Drupal\Component\Utility\Html::cleanCssIdentifierwhich states :So this works as designed.