fix: stop treating .txt as a supported document

Plain text was listed in the open, locate and link handlers but the file
dialog never offered it for new files, and a .txt opened through the app
behaved like Markdown without being one. Drop the extension everywhere so
the supported set is one list: md, markdown, mdown, mkd.
This commit is contained in:
2026-11-03 22:10:01 +08:00
parent dfe38890e0
commit c783a6dc56

View File

@@ -2797,6 +2797,16 @@ mod tests {
assert!(html.contains("<hr />")); assert!(html.contains("<hr />"));
} }
#[test]
fn only_markdown_extensions_are_supported_documents() {
for name in ["note.md", "note.MARKDOWN", "note.mdown", "note.mkd"] {
assert!(is_supported_document(Path::new(name)), "{name}");
}
for name in ["note.txt", "note.html", "note", "note.md.bak"] {
assert!(!is_supported_document(Path::new(name)), "{name}");
}
}
#[test] #[test]
fn file_urls_only_open_existing_supported_documents() { fn file_urls_only_open_existing_supported_documents() {
let dir = temp_test_dir("document-links"); let dir = temp_test_dir("document-links");
@@ -3824,7 +3834,7 @@ fn is_supported_document(path: &Path) -> bool {
.map(|extension| { .map(|extension| {
matches!( matches!(
extension.to_string_lossy().to_ascii_lowercase().as_str(), extension.to_string_lossy().to_ascii_lowercase().as_str(),
"md" | "markdown" | "mdown" | "mkd" | "txt" "md" | "markdown" | "mdown" | "mkd"
) )
}) })
.unwrap_or(false) .unwrap_or(false)
@@ -4947,7 +4957,7 @@ fn main() {
return; return;
} }
if let Some(paths) = rfd::FileDialog::new() if let Some(paths) = rfd::FileDialog::new()
.add_filter("Markdown", &["md", "markdown", "mdown", "mkd", "txt"]) .add_filter("Markdown", &["md", "markdown", "mdown", "mkd"])
.pick_files() .pick_files()
{ {
let _ = proxy.send_event(UserEvent::OpenPaths( let _ = proxy.send_event(UserEvent::OpenPaths(
@@ -5190,7 +5200,7 @@ fn main() {
} }
TaoEvent::UserEvent(UserEvent::LocateTab(window_id, id)) => { TaoEvent::UserEvent(UserEvent::LocateTab(window_id, id)) => {
if let Some(path) = rfd::FileDialog::new() if let Some(path) = rfd::FileDialog::new()
.add_filter("Markdown", &["md", "markdown", "mdown", "mkd", "txt"]) .add_filter("Markdown", &["md", "markdown", "mdown", "mkd"])
.pick_file() .pick_file()
{ {
if let Some((other_id, other_tab)) = find_open_path(&app, &path) { if let Some((other_id, other_tab)) = find_open_path(&app, &path) {