{"record":{"id":"ea01670c060218fe","repo":"siyuan-note/siyuan","slug":"invalid-template-document-attributes","errorCode":null,"errorMessage":"invalid template document attributes","messagePattern":"invalid template document attributes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_export_attrs.go","lineNumber":51,"sourceCode":"\tif tree == nil {\n\t\treturn nil, errors.New(\"parse template tree failed\")\n\t}\n\tnormalizeTree(tree)\n\tif err := applyTemplateDocumentAttributes(tree); err != nil {\n\t\treturn nil, err\n\t}\n\treturn tree, nil\n}\n\n// 独立文档属性保留在原位置求值，渲染完成后再合并到根节点。\nfunc applyTemplateDocumentAttributes(tree *parse.Tree) error {\n\tfor node := tree.Root.FirstChild; node != nil; {\n\t\tnext := node.Next\n\t\tinfo := node.ChildByType(ast.NodeCodeBlockFenceInfoMarker)\n\t\tif node.Type == ast.NodeCodeBlock && info != nil && string(info.CodeBlockInfo) == templateDocumentAttributeMarker {\n\t\t\tcode := node.ChildByType(ast.NodeCodeBlockCode)\n\t\t\tif code == nil {\n\t\t\t\treturn errors.New(\"invalid template document attributes\")\n\t\t\t}\n\t\t\tsource := strings.TrimSpace(string(code.Tokens))\n\t\t\tattrs := parseTemplateDocumentAttributes(source)\n\t\t\tif len(attrs) == 0 {\n\t\t\t\treturn errors.New(\"invalid template document attributes\")\n\t\t\t}\n\t\t\tfor _, attr := range attrs {\n\t\t\t\tif attr[0] == \"id\" || attr[0] == \"updated\" {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\ttree.Root.RemoveIALAttr(attr[0])\n\t\t\t\ttree.Root.KramdownIAL = append(tree.Root.KramdownIAL, attr)\n\t\t\t}\n\t\t\tif next != nil && next.Type == ast.NodeKramdownBlockIAL && parse.IAL2Map(parse.Tokens2IAL(next.Tokens))[\"type\"] != \"doc\" {\n\t\t\t\tial := next\n\t\t\t\tnext = next.Next\n\t\t\t\tial.Unlink()\n\t\t\t}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_export_attrs.go#L33-L69","documentation":"applyTemplateDocumentAttributes processes a fenced code block whose info string is the marker `siyuan-template-doc-attrs-v1`; the fenced body must be a document-attribute IAL of the form {: ... type=\"doc\" ...}. This error is thrown when the fence block has no code-content child node, meaning the marker block is structurally malformed in the parsed tree.","triggerScenarios":"Raised from applyTemplateDocumentAttributes (called by parseTemplateKTree) when a code block marked with siyuan-template-doc-attrs-v1 exists but node.ChildByType(ast.NodeCodeBlockCode) is nil — i.e. the fenced block carries the marker info string yet contains no code body node.","commonSituations":"A template containing an empty or corrupted ```siyuan-template-doc-attrs-v1 fence, or a fence whose content was lost by an editor/export round-trip that stripped the code body.","solutions":["Open the template file and locate the ```siyuan-template-doc-attrs-v1 fenced block","Ensure the block body contains a valid attribute line such as {: type=\"doc\" name=\"value\"}","Remove the marker block entirely if no document attributes are needed","Re-save the template ensuring the fence content is not stripped or left empty"],"exampleFix":"// before\n```siyuan-template-doc-attrs-v1\n```\n// after\n```siyuan-template-doc-attrs-v1\n{: type=\"doc\" title=\"Weekly\"}\n```","handlingStrategy":"validation","validationCode":"// assert marker fence has a body: between ```siyuan-template-doc-attrs-v1 and closing fence there must be a {: ... } line","typeGuard":null,"tryCatchPattern":"if err := applyTemplateDocumentAttributes(tree); err != nil { return fmt.Errorf(\"invalid doc attrs block: %w\", err) }","preventionTips":["Always give the marker fence a non-empty {: ... } body","Do not create an empty siyuan-template-doc-attrs-v1 block","Re-check the fence after editor round-trips that may strip code content"],"tags":["template","document-attributes","validation","kramdown"],"backgroundTag":"schema-validation-failed","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"}