siyuan-note/siyuan · warning
Only supports importing Markdown document
Error message
Only supports importing Markdown document
What it means
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.
Source
Thrown at kernel/model/import.go:1487
return ast.WalkContinue
})
reassignIDUpdated(tree, id, updated)
importTrees = append(importTrees, tree)
hPathsIDs[tree.HPath] = tree.ID
idPaths[tree.ID] = tree.Path
count++
if 0 == count%4 {
util.PushEndlessProgress(fmt.Sprintf(Conf.language(70), fmt.Sprintf("%s", tree.HPath)))
}
return nil
})
} else { // 导入单个文件
fileName := filepath.Base(localPath)
if !strings.HasSuffix(fileName, ".md") && !strings.HasSuffix(fileName, ".markdown") {
return errors.New(Conf.Language(79))
}
title := strings.TrimSuffix(fileName, ".markdown")
title = strings.TrimSuffix(title, ".md")
targetPath := strings.TrimSuffix(toPath, ".sy")
id := ast.NewNodeID()
targetPath = path.Join(targetPath, id+".sy")
var data []byte
data, err = os.ReadFile(localPath)
if err != nil {
return err
}
tree, yfmRootID, yfmTitle, yfmUpdated := parseStdMd(data)
if nil == tree {
msg := fmt.Sprintf("parse tree [%s] failed", localPath)
logging.LogError(msg)
return errors.New(msg)
}View on GitHub (pinned to 251596fc0d)
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.
Example fix
// before: importing a .docx file directly err := model.ImportFromLocalPath(boxID, "/path/to/doc.docx", toPath) // returns: Only supports importing Markdown document // after: convert to Markdown first, then import // run: pandoc doc.docx -o doc.md err := model.ImportFromLocalPath(boxID, "/path/to/doc.md", toPath)
Defensive patterns
Strategy: validation
Validate before calling
// Validate file extension before calling import
func isMarkdownFile(localPath string) bool {
name := strings.ToLower(filepath.Base(localPath))
return strings.HasSuffix(name, ".md") || strings.HasSuffix(name, ".markdown")
}
// Before calling ImportFromLocalPath for a single file:
info, err := os.Stat(localPath)
if err != nil {
return err
}
if !info.IsDir() && !isMarkdownFile(localPath) {
return fmt.Errorf("file %s is not a Markdown document (.md or .markdown required)", filepath.Base(localPath))
} Try / catch
err := model.ImportFromLocalPath(boxID, localPath, toPath)
if err != nil {
if err.Error() == Conf.Language(79) {
// Non-Markdown file selected — guide user
return fmt.Errorf("only .md and .markdown files are supported for single-file import")
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Obsidian Vault has no readable Markdown
- invalid import token
- no file found
- import path is not sub path of import dir
- --file is required
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/d42720309c45704d.
Report an issue: GitHub.