mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-21 04:41:16 -05:00
Add support for reading .ipynb
This commit is contained in:
@@ -17,6 +17,8 @@ export async function extractTextFromFile(filePath: string): Promise<string> {
|
|||||||
return extractTextFromPDF(filePath)
|
return extractTextFromPDF(filePath)
|
||||||
case ".docx":
|
case ".docx":
|
||||||
return extractTextFromDOCX(filePath)
|
return extractTextFromDOCX(filePath)
|
||||||
|
case ".ipynb":
|
||||||
|
return extractTextFromIPYNB(filePath)
|
||||||
default:
|
default:
|
||||||
const isBinary = await isBinaryFile(filePath)
|
const isBinary = await isBinaryFile(filePath)
|
||||||
if (!isBinary) {
|
if (!isBinary) {
|
||||||
@@ -37,3 +39,17 @@ async function extractTextFromDOCX(filePath: string): Promise<string> {
|
|||||||
const result = await mammoth.extractRawText({ path: filePath })
|
const result = await mammoth.extractRawText({ path: filePath })
|
||||||
return result.value
|
return result.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function extractTextFromIPYNB(filePath: string): Promise<string> {
|
||||||
|
const data = await fs.readFile(filePath, "utf8")
|
||||||
|
const notebook = JSON.parse(data)
|
||||||
|
let extractedText = ""
|
||||||
|
|
||||||
|
for (const cell of notebook.cells) {
|
||||||
|
if ((cell.cell_type === "markdown" || cell.cell_type === "code") && cell.source) {
|
||||||
|
extractedText += cell.source.join("\n") + "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return extractedText
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user