diff --git a/manifest.json b/manifest.json index b268814..62d3667 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "docxer", "name": "Docxer", - "version": "2.0.0", + "version": "2.0.1", "minAppVersion": "1.5.0", "description": "Import Word files easily. Adds a preview mode for .docx files and the ability to convert them to markdown (.md) files.", "author": "Developer-Mike", diff --git a/package-lock.json b/package-lock.json index 03f678a..3a0b158 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,13 +8,11 @@ "docx-preview": "^0.3.0", "esbuild-sass-plugin": "^2.6.0", "mammoth": "^1.6.0", - "mime-types": "^2.1.35", "monkey-around": "^2.3.0", "sass": "^1.70.0", "turndown": "^7.2.0" }, "devDependencies": { - "@types/mime-types": "^2.1.4", "@types/node": "^16.11.6", "@types/turndown": "^5.0.4", "@typescript-eslint/eslint-plugin": "5.29.0", @@ -542,12 +540,6 @@ "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==", "dev": true }, - "node_modules/@types/mime-types": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.4.tgz", - "integrity": "sha512-lfU4b34HOri+kAY5UheuFMWPDOI+OPceBSHZKp69gEyTL/mmJ4cnU6Y/rlme3UL3GyOn6Y42hyIEw0/q8sWx5w==", - "dev": true - }, "node_modules/@types/node": { "version": "16.18.50", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.50.tgz", @@ -1946,25 +1938,6 @@ "node": ">=8.6" } }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -2920,12 +2893,6 @@ "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==", "dev": true }, - "@types/mime-types": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.4.tgz", - "integrity": "sha512-lfU4b34HOri+kAY5UheuFMWPDOI+OPceBSHZKp69gEyTL/mmJ4cnU6Y/rlme3UL3GyOn6Y42hyIEw0/q8sWx5w==", - "dev": true - }, "@types/node": { "version": "16.18.50", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.50.tgz", @@ -3956,19 +3923,6 @@ "picomatch": "^2.3.1" } }, - "mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" - }, - "mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "requires": { - "mime-db": "1.52.0" - } - }, "minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", diff --git a/package.json b/package.json index 66b7a1e..d715416 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "dev": "node esbuild.config.mjs" }, "devDependencies": { - "@types/mime-types": "^2.1.4", "@types/node": "^16.11.6", "@types/turndown": "^5.0.4", "@typescript-eslint/eslint-plugin": "5.29.0", @@ -19,7 +18,6 @@ "docx-preview": "^0.3.0", "esbuild-sass-plugin": "^2.6.0", "mammoth": "^1.6.0", - "mime-types": "^2.1.35", "monkey-around": "^2.3.0", "sass": "^1.70.0", "turndown": "^7.2.0" diff --git a/src/convertable-file-views/docx.ts b/src/convertable-file-views/docx.ts index 1c94874..0fe87c9 100644 --- a/src/convertable-file-views/docx.ts +++ b/src/convertable-file-views/docx.ts @@ -2,9 +2,9 @@ import * as mammoth from "mammoth" import { renderAsync } from 'docx-preview' import ConvertibleFileView from "src/core/convertible-file-view" import FileUtils from "src/utils/file-utils" -import { extensions } from "mime-types" import ObsidianTurndown from "src/utils/obsidian-turndown" import { htmlToMarkdown } from "obsidian" +import MimeUtils from "src/utils/mime-utils" export default class DocxFileView extends ConvertibleFileView { static readonly VIEW_TYPE_ID = "docx-view" @@ -37,7 +37,7 @@ export default class DocxFileView extends ConvertibleFileView { const fallbackFilename = this.plugin.settings.getSetting("fallbackAttachmentName") const attachmentAltText = image.altText?.replace(/\n/g, " ") ?? "" - const fileExtension = extensions[image.contentType]?.first() || "png" + const fileExtension = MimeUtils.EXTENSIONS[image.contentType] ?? "png" const path = await FileUtils.createBinary(this.app, attachmentsDirectory, attachmentAltText, fallbackFilename, fileExtension, imageBinary) console.debug(`Extracted image to ${path}`) diff --git a/src/core/convertible-file-view.ts b/src/core/convertible-file-view.ts index 0429636..371d757 100644 --- a/src/core/convertible-file-view.ts +++ b/src/core/convertible-file-view.ts @@ -2,7 +2,7 @@ import { Notice, TFile, TextFileView, WorkspaceLeaf } from "obsidian" import DocxerPlugin from "src/main" import FileUtils from "src/utils/file-utils" -export default abstract class ConvertableFileView extends TextFileView { +export default abstract class ConvertibleFileView extends TextFileView { plugin: DocxerPlugin fileContent: string header: HTMLElement | null = null diff --git a/src/main.ts b/src/main.ts index f42ec8a..356c289 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,9 @@ import DocxFileView from "./convertable-file-views/docx" -import ConvertableFileView from "./core/convertible-file-view" +import ConvertibleFileView from "./core/convertible-file-view" import SettingsManager from "./settings" import { Plugin, WorkspaceLeaf } from "obsidian" -export const FILETYPE_MAP: { [key: string]: new(leaf: WorkspaceLeaf, plugin: DocxerPlugin) => ConvertableFileView } = { +export const FILETYPE_MAP: { [key: string]: new(leaf: WorkspaceLeaf, plugin: DocxerPlugin) => ConvertibleFileView } = { "docx": DocxFileView } diff --git a/src/utils/mime-utils.ts b/src/utils/mime-utils.ts new file mode 100644 index 0000000..0d26293 --- /dev/null +++ b/src/utils/mime-utils.ts @@ -0,0 +1,72 @@ +export default class MimeUtils { + static readonly EXTENSIONS: { [key: string]: string } = { + "audio/aac": "aac", + "application/x-abiword": "abw", + "image/apng": "apng", + "application/x-freearc": "arc", + "image/avif": "avif", + "video/x-msvideo": "avi", + "application/vnd.amazon.ebook": "azw", + "application/octet-stream": "bin", + "image/bmp": "bmp", + "application/x-bzip": "bz", + "application/x-bzip2": "bz2", + "application/x-cdf": "cda", + "application/x-csh": "csh", + "text/css": "css", + "text/csv": "csv", + "application/msword": "doc", + "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx", + "application/vnd.ms-fontobject": "eot", + "application/epub+zip": "epub", + "application/gzip": "gz", + "image/gif": "gif", + "text/html": "html", + "image/vnd.microsoft.icon": "ico", + "text/calendar": "ics", + "application/java-archive": "jar", + "image/jpeg": "jpeg", + "application/json": "json", + "application/ld+json": "jsonld", + "audio/x-midi": "mid", + "text/javascript": "mjs", + "audio/mpeg": "mp3", + "video/mp4": "mp4", + "video/mpeg": "mpeg", + "application/vnd.apple.installer+xml": "mpkg", + "application/vnd.oasis.opendocument.presentation": "odp", + "application/vnd.oasis.opendocument.spreadsheet": "ods", + "application/vnd.oasis.opendocument.text": "odt", + "audio/ogg": "oga", + "video/ogg": "ogv", + "application/ogg": "ogx", + "font/otf": "otf", + "image/png": "png", + "application/pdf": "pdf", + "application/x-httpd-php": "php", + "application/vnd.ms-powerpoint": "ppt", + "application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx", + "application/vnd.rar": "rar", + "application/rtf": "rtf", + "application/x-sh": "sh", + "image/svg+xml": "svg", + "application/x-tar": "tar", + "image/tiff": "tif", + "video/mp2t": "ts", + "font/ttf": "ttf", + "text/plain": "txt", + "application/vnd.visio": "vsd", + "audio/wav": "wav", + "audio/webm": "weba", + "video/webm": "webm", + "image/webp": "webp", + "font/woff": "woff", + "font/woff2": "woff2", + "application/xhtml+xml": "xhtml", + "application/vnd.ms-excel": "xls", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx", + "application/vnd.mozilla.xul+xml": "xul", + "application/x-zip-compressed.": "zip", + "application/x-7z-compressed": "7z" + } +} \ No newline at end of file