Support Markdown files in App.tsx
This commit is contained in:
@@ -422,7 +422,7 @@ export default function App() {
|
|||||||
async (filePath: string) => {
|
async (filePath: string) => {
|
||||||
try {
|
try {
|
||||||
const filename = filePath.split(/[\/]/).pop() || DEFAULT_TITLE;
|
const filename = filePath.split(/[\/]/).pop() || DEFAULT_TITLE;
|
||||||
const title = filename.replace(/\.txt$/i, "") || DEFAULT_TITLE;
|
const title = filename.replace(/\.(txt|md)$/i, "") || DEFAULT_TITLE;
|
||||||
const contents = await readTextFile(filePath);
|
const contents = await readTextFile(filePath);
|
||||||
const { textId } = await createText(title, contents);
|
const { textId } = await createText(title, contents);
|
||||||
await refreshTexts();
|
await refreshTexts();
|
||||||
@@ -437,7 +437,10 @@ export default function App() {
|
|||||||
const handleFilePaths = useCallback(
|
const handleFilePaths = useCallback(
|
||||||
async (paths: string[]) => {
|
async (paths: string[]) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const txtPaths = paths.filter((path) => path.toLowerCase().endsWith(".txt"));
|
const txtPaths = paths.filter((path) => {
|
||||||
|
const lower = path.toLowerCase();
|
||||||
|
return lower.endsWith(".txt") || lower.endsWith(".md");
|
||||||
|
});
|
||||||
const recent = recentOpenRef.current;
|
const recent = recentOpenRef.current;
|
||||||
for (const path of txtPaths) {
|
for (const path of txtPaths) {
|
||||||
const key = path.toLowerCase();
|
const key = path.toLowerCase();
|
||||||
@@ -499,7 +502,7 @@ export default function App() {
|
|||||||
const path = await open({
|
const path = await open({
|
||||||
multiple: false,
|
multiple: false,
|
||||||
directory: false,
|
directory: false,
|
||||||
filters: [{ name: "Text", extensions: ["txt"] }],
|
filters: [{ name: "Text/Markdown", extensions: ["txt", "md"] }],
|
||||||
defaultPath: baseDir
|
defaultPath: baseDir
|
||||||
});
|
});
|
||||||
if (!path || Array.isArray(path)) return;
|
if (!path || Array.isArray(path)) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user