{"record":{"id":"d42720309c45704d","repo":"siyuan-note/siyuan","slug":"only-supports-importing-markdown-document","errorCode":null,"errorMessage":"Only supports importing Markdown document","messagePattern":"Only supports importing Markdown document","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/import.go","lineNumber":1487,"sourceCode":"\t\t\t\treturn ast.WalkContinue\n\t\t\t})\n\n\t\t\treassignIDUpdated(tree, id, updated)\n\t\t\timportTrees = append(importTrees, tree)\n\n\t\t\thPathsIDs[tree.HPath] = tree.ID\n\t\t\tidPaths[tree.ID] = tree.Path\n\n\t\t\tcount++\n\t\t\tif 0 == count%4 {\n\t\t\t\tutil.PushEndlessProgress(fmt.Sprintf(Conf.language(70), fmt.Sprintf(\"%s\", tree.HPath)))\n\t\t\t}\n\t\t\treturn nil\n\t\t})\n\t} else { // 导入单个文件\n\t\tfileName := filepath.Base(localPath)\n\t\tif !strings.HasSuffix(fileName, \".md\") && !strings.HasSuffix(fileName, \".markdown\") {\n\t\t\treturn errors.New(Conf.Language(79))\n\t\t}\n\n\t\ttitle := strings.TrimSuffix(fileName, \".markdown\")\n\t\ttitle = strings.TrimSuffix(title, \".md\")\n\t\ttargetPath := strings.TrimSuffix(toPath, \".sy\")\n\t\tid := ast.NewNodeID()\n\t\ttargetPath = path.Join(targetPath, id+\".sy\")\n\t\tvar data []byte\n\t\tdata, err = os.ReadFile(localPath)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\ttree, yfmRootID, yfmTitle, yfmUpdated := parseStdMd(data)\n\t\tif nil == tree {\n\t\t\tmsg := fmt.Sprintf(\"parse tree [%s] failed\", localPath)\n\t\t\tlogging.LogError(msg)\n\t\t\treturn errors.New(msg)\n\t\t}","sourceCodeStart":1469,"sourceCodeEnd":1505,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/import.go#L1469-L1505","documentation":"Thrown by importFromLocalPath (language code 79) when importing a single file whose extension is neither .md nor .markdown. The single-file import path only supports Markdown documents; all other formats are rejected before any processing begins. This is a user-facing validation error that directs the user to use the correct format or import method. The check is at import.go:1486-1488 in the else branch (single file, not directory) of the import logic.","triggerScenarios":"Calling importFromLocalPath with a localPath whose filename does not end in .md or .markdown, AND the path is a file (not a directory). The directory import path has its own logic and does not hit this check.","commonSituations":"User selects a .docx, .html, .txt, .pdf, or other file in the single-file import dialog. User drags a non-Markdown file into the editor expecting it to be imported. File extension case mismatch (e.g., .MD on Windows) — note the check is case-sensitive and only accepts lowercase .md and .markdown.","solutions":["Convert the file to Markdown (.md) before importing — use a converter like Pandoc for .docx/.html.","If the file is already Markdown but has an uppercase extension (.MD), rename it to lowercase .md.","For directory imports containing mixed file types, the directory import path handles non-.md files gracefully by skipping them.","Use SiYuan's built-in Pandoc integration for importing non-Markdown formats if available."],"exampleFix":"// before: importing a .docx file directly\nerr := model.ImportFromLocalPath(boxID, \"/path/to/doc.docx\", toPath)\n// returns: Only supports importing Markdown document\n\n// after: convert to Markdown first, then import\n// run: pandoc doc.docx -o doc.md\nerr := model.ImportFromLocalPath(boxID, \"/path/to/doc.md\", toPath)","handlingStrategy":"validation","validationCode":"// Validate file extension before calling import\nfunc isMarkdownFile(localPath string) bool {\n    name := strings.ToLower(filepath.Base(localPath))\n    return strings.HasSuffix(name, \".md\") || strings.HasSuffix(name, \".markdown\")\n}\n\n// Before calling ImportFromLocalPath for a single file:\ninfo, err := os.Stat(localPath)\nif err != nil {\n    return err\n}\nif !info.IsDir() && !isMarkdownFile(localPath) {\n    return fmt.Errorf(\"file %s is not a Markdown document (.md or .markdown required)\", filepath.Base(localPath))\n}","typeGuard":null,"tryCatchPattern":"err := model.ImportFromLocalPath(boxID, localPath, toPath)\nif err != nil {\n    if err.Error() == Conf.Language(79) {\n        // Non-Markdown file selected — guide user\n        return fmt.Errorf(\"only .md and .markdown files are supported for single-file import\")\n    }\n}","preventionTips":["Validate the file extension before calling ImportFromLocalPath for single files.","Convert non-Markdown files to .md using Pandoc or another converter before importing.","For directory imports, non-.md files are automatically skipped — use directory import for mixed file types.","Handle case-insensitive extensions on Windows by normalizing to lowercase before checking."],"tags":["import","markdown","validation","file-type"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}