mirror of
https://github.com/flatulentfowl/docdrop.git
synced 2026-07-22 06:49:52 +00:00
Added support for all file types supported by markitdown
This commit is contained in:
parent
54a7653bcf
commit
3ec69575c8
5 changed files with 35 additions and 16 deletions
|
|
@ -1,8 +1,10 @@
|
|||
# DocDrop
|
||||
|
||||
An [Obsidian](https://obsidian.md) plugin that converts PDF files to Markdown using Microsoft's [MarkItDown](https://github.com/microsoft/markitdown) CLI tool.
|
||||
An [Obsidian](https://obsidian.md) plugin that converts documents, spreadsheets, images, and more to Markdown using Microsoft's [MarkItDown](https://github.com/microsoft/markitdown) CLI tool.
|
||||
|
||||
Right-click any PDF in your vault and have it converted to a clean Markdown file in seconds — entirely on your machine, no cloud required (unless you opt in to the advanced AI features).
|
||||
Right-click any supported file in your vault and have it converted to a clean Markdown file in seconds — entirely on your machine, no cloud required (unless you opt in to the advanced AI features).
|
||||
|
||||
**Supported formats:** PDF, Word (`.docx`), PowerPoint (`.pptx`), Excel (`.xlsx`), images (`.jpg`, `.png`, `.gif`, `.webp`, `.bmp`, `.tiff`), HTML, CSV, JSON, XML, EPUB, ZIP, and audio (`.mp3`, `.wav` — requires ffmpeg).
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -65,7 +67,7 @@ Then copy `main.js`, `manifest.json`, and `styles.css` into your vault's plugin
|
|||
|
||||
### Right-click menu
|
||||
|
||||
Right-click any PDF file in the Obsidian file explorer and select **Convert to Markdown with DocDrop**. The converted `.md` file is saved in the same folder as the PDF (or a custom folder — see Settings).
|
||||
Right-click any supported file in the Obsidian file explorer and select **Convert to Markdown with DocDrop**. The converted `.md` file is saved in the same folder as the source file (or a custom folder — see Settings).
|
||||
|
||||
### Command palette
|
||||
|
||||
|
|
|
|||
4
main.js
4
main.js
File diff suppressed because one or more lines are too long
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"id": "docdrop",
|
||||
"name": "DocDrop",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"minAppVersion": "1.0.0",
|
||||
"description": "Convert PDF files to Markdown using Microsofts markitdown CLI.",
|
||||
"description": "Convert PDF, Word, PowerPoint, Excel, images, and more to Markdown using Microsoft's markitdown.",
|
||||
"author": "Rhys Gottwald",
|
||||
"authorUrl": "",
|
||||
"isDesktopOnly": true
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docdrop",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0",
|
||||
"description": "Obsidian plugin: convert PDFs to Markdown via Microsoft's markitdown",
|
||||
"main": "main.js",
|
||||
"type": "module",
|
||||
|
|
|
|||
33
src/main.ts
33
src/main.ts
|
|
@ -11,6 +11,23 @@ import {
|
|||
} from "obsidian";
|
||||
import { execFile } from "child_process";
|
||||
|
||||
// ─── Supported file types ────────────────────────────────────────────────────
|
||||
|
||||
const SUPPORTED_EXTENSIONS = new Set([
|
||||
"pdf",
|
||||
"docx", "doc",
|
||||
"pptx", "ppt",
|
||||
"xlsx", "xls",
|
||||
"jpg", "jpeg", "png", "gif", "webp", "bmp", "tiff",
|
||||
"html", "htm",
|
||||
"csv",
|
||||
"json",
|
||||
"xml",
|
||||
"epub",
|
||||
"zip",
|
||||
"mp3", "wav",
|
||||
]);
|
||||
|
||||
// ─── Settings ────────────────────────────────────────────────────────────────
|
||||
|
||||
interface DocDropSettings {
|
||||
|
|
@ -373,32 +390,32 @@ export default class DocDropPlugin extends Plugin {
|
|||
this.addSettingTab(new DocDropSettingTab(this.app, this));
|
||||
|
||||
this.addCommand({
|
||||
id: "convert-active-pdf",
|
||||
name: "Convert active PDF to Markdown",
|
||||
id: "convert-active-file",
|
||||
name: "Convert active file to Markdown",
|
||||
callback: () => {
|
||||
const activeFile = this.app.workspace.getActiveFile();
|
||||
if (!activeFile) {
|
||||
new Notice("No file is currently open.");
|
||||
return;
|
||||
}
|
||||
if (activeFile.extension.toLowerCase() !== "pdf") {
|
||||
new Notice("The active file is not a PDF.");
|
||||
if (!SUPPORTED_EXTENSIONS.has(activeFile.extension.toLowerCase())) {
|
||||
new Notice(`DocDrop does not support .${activeFile.extension} files.`);
|
||||
return;
|
||||
}
|
||||
this.convertPdf(activeFile);
|
||||
this.convertFile(activeFile);
|
||||
},
|
||||
});
|
||||
|
||||
this.registerEvent(
|
||||
this.app.workspace.on("file-menu", (menu, file: TAbstractFile) => {
|
||||
if (!(file instanceof TFile)) return;
|
||||
if (file.extension.toLowerCase() !== "pdf") return;
|
||||
if (!SUPPORTED_EXTENSIONS.has(file.extension.toLowerCase())) return;
|
||||
|
||||
menu.addItem((item) => {
|
||||
item
|
||||
.setTitle("Convert to Markdown with DocDrop")
|
||||
.setIcon("file-text")
|
||||
.onClick(() => this.convertPdf(file));
|
||||
.onClick(() => this.convertFile(file));
|
||||
});
|
||||
})
|
||||
);
|
||||
|
|
@ -414,7 +431,7 @@ export default class DocDropPlugin extends Plugin {
|
|||
await this.saveData(this.settings);
|
||||
}
|
||||
|
||||
private async convertPdf(pdfFile: TFile): Promise<void> {
|
||||
private async convertFile(pdfFile: TFile): Promise<void> {
|
||||
const adapter = this.app.vault.adapter;
|
||||
const basePath = (adapter as any).getBasePath() as string;
|
||||
const absolutePdfPath = `${basePath}/${pdfFile.path}`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue