@@ -40,7 +40,7 @@ export const LeftPanelOpenButton = () => {
4040 const extensions =
4141 configuredExtensions && configuredExtensions . length > 0
4242 ? configuredExtensions
43- : [ '.docx' , '.md' , '.markdown' ] ;
43+ : [ '.docx' , '.md' , '.markdown' , '.txt' ] ;
4444 const mimeTypes = new Set < string > ( ) ;
4545
4646 if ( extensions . some ( ( extension ) => extension === '.docx' ) ) {
@@ -55,6 +55,8 @@ export const LeftPanelOpenButton = () => {
5555 mimeTypes . add ( ContentTypes . Markdown ) ;
5656 }
5757
58+ mimeTypes . add ( ContentTypes . Txt ) ;
59+
5860 return Array . from ( mimeTypes ) ;
5961 } , [ config ?. CONVERSION_FILE_EXTENSIONS_ALLOWED ] ) ;
6062
@@ -63,9 +65,13 @@ export const LeftPanelOpenButton = () => {
6365 config ?. CONVERSION_FILE_EXTENSIONS_ALLOWED ?. map ( ( extension ) =>
6466 extension . toLowerCase ( ) ,
6567 ) ;
66- return configuredExtensions && configuredExtensions . length > 0
67- ? configuredExtensions
68- : [ '.docx' , '.md' , '.markdown' ] ;
68+ const baseExtensions =
69+ configuredExtensions && configuredExtensions . length > 0
70+ ? configuredExtensions
71+ : [ '.docx' , '.md' , '.markdown' , '.txt' ] ;
72+ return baseExtensions . includes ( '.txt' )
73+ ? baseExtensions
74+ : [ ...baseExtensions , '.txt' ] ;
6975 } , [ config ?. CONVERSION_FILE_EXTENSIONS_ALLOWED ] ) ;
7076
7177 const isResultCompatible = ( result : { name : string ; mimeType : string } ) => {
@@ -75,7 +81,8 @@ export const LeftPanelOpenButton = () => {
7581 ) ;
7682 const byMime =
7783 result . mimeType === ContentTypes . Docx ||
78- result . mimeType === ContentTypes . Markdown ;
84+ result . mimeType === ContentTypes . Markdown ||
85+ result . mimeType === ContentTypes . Txt ;
7986
8087 return byExtension || byMime ;
8188 } ;
@@ -110,7 +117,7 @@ export const LeftPanelOpenButton = () => {
110117 if ( ! isResultCompatible ( selectedFile ) ) {
111118 toast (
112119 t (
113- 'The document "{{documentName}}" import has failed (only .docx and .md files are allowed)' ,
120+ 'The document "{{documentName}}" import has failed (only .docx, .md and .txt files are allowed)' ,
114121 {
115122 documentName : selectedFile . name ,
116123 } ,
@@ -136,7 +143,26 @@ export const LeftPanelOpenButton = () => {
136143 type : mimeType ,
137144 } ) ;
138145
139- const importedDoc = await importDocAsync ( [ file , mimeType ] ) ;
146+ const isTxtFile =
147+ mimeType === ContentTypes . Txt ||
148+ selectedFile . mimeType === ContentTypes . Txt ||
149+ selectedFile . name . toLowerCase ( ) . endsWith ( '.txt' ) ;
150+
151+ let fileToImport = file ;
152+ let mimeTypeToImport = mimeType ;
153+
154+ if ( isTxtFile ) {
155+ const textContent = await blob . text ( ) ;
156+ const markdownFileName = selectedFile . name . toLowerCase ( ) . endsWith ( '.txt' )
157+ ? `${ selectedFile . name . slice ( 0 , - 4 ) } .md`
158+ : `${ selectedFile . name } .md` ;
159+ fileToImport = new File ( [ textContent ] , markdownFileName , {
160+ type : ContentTypes . Markdown ,
161+ } ) ;
162+ mimeTypeToImport = ContentTypes . Markdown ;
163+ }
164+
165+ const importedDoc = await importDocAsync ( [ fileToImport , mimeTypeToImport ] ) ;
140166
141167 setIsNavigating ( true ) ;
142168 await router . push ( `/docs/${ importedDoc . id } ` ) ;
0 commit comments