{"record":{"id":"48de3d8c54f49ad7","repo":"siyuan-note/siyuan","slug":"inline-style-name-exceeds-the-d-character-limit","errorCode":null,"errorMessage":"inline style name exceeds the %d character limit","messagePattern":"inline style name exceeds the (.+?) character limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":676,"sourceCode":"\t\t\t\tif _, exists := ids[id]; !exists {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif !ast.IsNodeIDPattern(id) {\n\t\t\treturn nil, fmt.Errorf(\"invalid inline style ID [%s]\", id)\n\t\t}\n\t\tif _, exists := ids[id]; exists {\n\t\t\treturn nil, fmt.Errorf(\"duplicate inline style ID [%s]\", id)\n\t\t}\n\t\tids[id] = struct{}{}\n\n\t\tname := strings.TrimSpace(style.Name)\n\t\tif name == \"\" {\n\t\t\treturn nil, errors.New(\"inline style name must not be empty\")\n\t\t}\n\t\tif maxInlineStyleNameRunes < utf8.RuneCountInString(name) {\n\t\t\treturn nil, fmt.Errorf(\"inline style name exceeds the %d character limit\", maxInlineStyleNameRunes)\n\t\t}\n\t\tif style.Light == nil || style.Dark == nil {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must define light and dark themes\", id)\n\t\t}\n\n\t\tlight, err := normalizeInlineStyleTheme(style.Light)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid light theme of inline style [%s]: %w\", id, err)\n\t\t}\n\t\tdark, err := normalizeInlineStyleTheme(style.Dark)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid dark theme of inline style [%s]: %w\", id, err)\n\t\t}\n\t\tlightColor, lightBackground := light.Color != \"\", light.BackgroundColor != \"\"\n\t\tdarkColor, darkBackground := dark.Color != \"\", dark.BackgroundColor != \"\"\n\t\tif !lightColor && !lightBackground {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must define color or backgroundColor\", id)\n\t\t}","sourceCodeStart":658,"sourceCodeEnd":694,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L658-L694","documentation":"Inline style names are capped at maxInlineStyleNameRunes (64) runes (not bytes), so CJK and emoji count fairly. normalizeInlineStyles measures the trimmed name with utf8.RuneCountInString and rejects the save/load when it exceeds the limit, keeping picker labels and the styles JSON tidy.","triggerScenarios":"Calling model.SetInlineStyles / model.SetInlineStylesData with a style whose trimmed Name is longer than 64 runes; pasting long text (a sentence, URL, or Markdown snippet) into the style name; loading a config whose entry has an oversized name from an external writer that never enforced the cap.","commonSituations":"Using an AI/clipboard tool that pastes a long description as the style name; a script generating names from block content; international text where a 64-byte check elsewhere misleads authors into thinking longer CJK names fit.","solutions":["Shorten the style name to 64 runes or fewer before saving","Truncate client-side: for _, r := range name { if i >= 64 { break }; ... } counting runes, not bytes","Trim redundant whitespace first (the check runs on the trimmed value), which may bring the count under the limit","If loading fails, edit the config JSON to shorten the offending name"],"exampleFix":"// before\nname := \"Very long style name generated from selected text that goes on and on and clearly exceeds sixty-four runes in total\"\n// after\nname := truncateRunes(strings.TrimSpace(longName), 64) // max 64 runes","handlingStrategy":"validation","validationCode":"func namesWithinLimit(styles []*InlineStyle, max int) bool {\n\tfor _, s := range styles {\n\t\tif utf8.RuneCountInString(strings.TrimSpace(s.Name)) > max {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true // max = 64 (maxInlineStyleNameRunes)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"character limit\") {\n\t// truncate names to 64 runes and retry once\n}","preventionTips":["Count runes (utf8.RuneCountInString), not bytes, when enforcing the 64 limit client-side","Truncate pasted names instead of rejecting them","Cap the name input field length in the UI"],"tags":["go","validation","length-limit","inline-styles"],"backgroundTag":"value-out-of-range","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}