# Authors: The scikit-learn developers
# SPDX-License-Identifier: BSD-3-Clause
import html
def _features_html(features, is_fitted_css_class=""):
"""Generate HTML representation of feature names.
Creates a collapsible HTML details element containing a table of feature
names with a summary line showing the total count. Includes a copy-to-clipboard
button for all feature names.
"""
FEATURES_TABLE_TEMPLATE = """
"""
FEATURES_ROW_TEMPLATE = """
| {feature} |
"""
total_features = len(features)
total_features_line = (
f"{total_features} {'feature' if total_features == 1 else 'features'}"
)
rows = [
FEATURES_ROW_TEMPLATE.format(feature=html.escape(feature))
for feature in features
]
return FEATURES_TABLE_TEMPLATE.format(
total_features_line=total_features_line,
is_fitted_css_class=html.escape(is_fitted_css_class),
rows="".join(rows),
)