Files
ROCm/docs/extension/rocm_docs_custom/utils.py
Peter Park a32210fa7e Add ROCm 7.9.0 documentation
Add release notes

Add install instructions

Add PyTorch + ComfyUI instructions

Add custom selector directives

Add JS and CSS for selector

Add custom icon directive and utils

Clean up conf.py
2025-10-20 12:17:50 -04:00

31 lines
851 B
Python

import json
import html
def normalize_key(key):
return key.replace(" ", "_").lower().strip()
def kv_to_data_attr(name, kv_str, separator="="):
"""
Convert key=value pairs delimited by spaces to stringified JSON.
Format it as an HTML data attribute.
Args:
name: Name of the data attribute; it will be prefixed with "data-".
condition_str: String in format "key=value os=ubuntu".
Example output:
'data-show-when="{"os": "ubuntu"}"'
"""
pairs = {}
for token in kv_str.split():
token = token.strip()
if not token or separator not in token:
continue
key, value = token.split(separator, 1)
if key and value:
pairs.setdefault(key, []).append(value.strip())
return f'data-{name}="{html.escape(json.dumps(pairs))}"' if pairs else ""