Skip to content

Commit 543b3b4

Browse files
Fixed not working on mobile due to library dependency.
1 parent 4397910 commit 543b3b4

File tree

7 files changed

+78
-54
lines changed

7 files changed

+78
-54
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "docxer",
33
"name": "Docxer",
4-
"version": "2.0.0",
4+
"version": "2.0.1",
55
"minAppVersion": "1.5.0",
66
"description": "Import Word files easily. Adds a preview mode for .docx files and the ability to convert them to markdown (.md) files.",
77
"author": "Developer-Mike",

package-lock.json

Lines changed: 0 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"dev": "node esbuild.config.mjs"
55
},
66
"devDependencies": {
7-
"@types/mime-types": "^2.1.4",
87
"@types/node": "^16.11.6",
98
"@types/turndown": "^5.0.4",
109
"@typescript-eslint/eslint-plugin": "5.29.0",
@@ -19,7 +18,6 @@
1918
"docx-preview": "^0.3.0",
2019
"esbuild-sass-plugin": "^2.6.0",
2120
"mammoth": "^1.6.0",
22-
"mime-types": "^2.1.35",
2321
"monkey-around": "^2.3.0",
2422
"sass": "^1.70.0",
2523
"turndown": "^7.2.0"

src/convertable-file-views/docx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as mammoth from "mammoth"
22
import { renderAsync } from 'docx-preview'
33
import ConvertibleFileView from "src/core/convertible-file-view"
44
import FileUtils from "src/utils/file-utils"
5-
import { extensions } from "mime-types"
65
import ObsidianTurndown from "src/utils/obsidian-turndown"
76
import { htmlToMarkdown } from "obsidian"
7+
import MimeUtils from "src/utils/mime-utils"
88

99
export default class DocxFileView extends ConvertibleFileView {
1010
static readonly VIEW_TYPE_ID = "docx-view"
@@ -37,7 +37,7 @@ export default class DocxFileView extends ConvertibleFileView {
3737

3838
const fallbackFilename = this.plugin.settings.getSetting("fallbackAttachmentName")
3939
const attachmentAltText = image.altText?.replace(/\n/g, " ") ?? ""
40-
const fileExtension = extensions[image.contentType]?.first() || "png"
40+
const fileExtension = MimeUtils.EXTENSIONS[image.contentType] ?? "png"
4141

4242
const path = await FileUtils.createBinary(this.app, attachmentsDirectory, attachmentAltText, fallbackFilename, fileExtension, imageBinary)
4343
console.debug(`Extracted image to ${path}`)

src/core/convertible-file-view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Notice, TFile, TextFileView, WorkspaceLeaf } from "obsidian"
22
import DocxerPlugin from "src/main"
33
import FileUtils from "src/utils/file-utils"
44

5-
export default abstract class ConvertableFileView extends TextFileView {
5+
export default abstract class ConvertibleFileView extends TextFileView {
66
plugin: DocxerPlugin
77
fileContent: string
88
header: HTMLElement | null = null

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import DocxFileView from "./convertable-file-views/docx"
2-
import ConvertableFileView from "./core/convertible-file-view"
2+
import ConvertibleFileView from "./core/convertible-file-view"
33
import SettingsManager from "./settings"
44
import { Plugin, WorkspaceLeaf } from "obsidian"
55

6-
export const FILETYPE_MAP: { [key: string]: new(leaf: WorkspaceLeaf, plugin: DocxerPlugin) => ConvertableFileView } = {
6+
export const FILETYPE_MAP: { [key: string]: new(leaf: WorkspaceLeaf, plugin: DocxerPlugin) => ConvertibleFileView } = {
77
"docx": DocxFileView
88
}
99

src/utils/mime-utils.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
export default class MimeUtils {
2+
static readonly EXTENSIONS: { [key: string]: string } = {
3+
"audio/aac": "aac",
4+
"application/x-abiword": "abw",
5+
"image/apng": "apng",
6+
"application/x-freearc": "arc",
7+
"image/avif": "avif",
8+
"video/x-msvideo": "avi",
9+
"application/vnd.amazon.ebook": "azw",
10+
"application/octet-stream": "bin",
11+
"image/bmp": "bmp",
12+
"application/x-bzip": "bz",
13+
"application/x-bzip2": "bz2",
14+
"application/x-cdf": "cda",
15+
"application/x-csh": "csh",
16+
"text/css": "css",
17+
"text/csv": "csv",
18+
"application/msword": "doc",
19+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
20+
"application/vnd.ms-fontobject": "eot",
21+
"application/epub+zip": "epub",
22+
"application/gzip": "gz",
23+
"image/gif": "gif",
24+
"text/html": "html",
25+
"image/vnd.microsoft.icon": "ico",
26+
"text/calendar": "ics",
27+
"application/java-archive": "jar",
28+
"image/jpeg": "jpeg",
29+
"application/json": "json",
30+
"application/ld+json": "jsonld",
31+
"audio/x-midi": "mid",
32+
"text/javascript": "mjs",
33+
"audio/mpeg": "mp3",
34+
"video/mp4": "mp4",
35+
"video/mpeg": "mpeg",
36+
"application/vnd.apple.installer+xml": "mpkg",
37+
"application/vnd.oasis.opendocument.presentation": "odp",
38+
"application/vnd.oasis.opendocument.spreadsheet": "ods",
39+
"application/vnd.oasis.opendocument.text": "odt",
40+
"audio/ogg": "oga",
41+
"video/ogg": "ogv",
42+
"application/ogg": "ogx",
43+
"font/otf": "otf",
44+
"image/png": "png",
45+
"application/pdf": "pdf",
46+
"application/x-httpd-php": "php",
47+
"application/vnd.ms-powerpoint": "ppt",
48+
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
49+
"application/vnd.rar": "rar",
50+
"application/rtf": "rtf",
51+
"application/x-sh": "sh",
52+
"image/svg+xml": "svg",
53+
"application/x-tar": "tar",
54+
"image/tiff": "tif",
55+
"video/mp2t": "ts",
56+
"font/ttf": "ttf",
57+
"text/plain": "txt",
58+
"application/vnd.visio": "vsd",
59+
"audio/wav": "wav",
60+
"audio/webm": "weba",
61+
"video/webm": "webm",
62+
"image/webp": "webp",
63+
"font/woff": "woff",
64+
"font/woff2": "woff2",
65+
"application/xhtml+xml": "xhtml",
66+
"application/vnd.ms-excel": "xls",
67+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
68+
"application/vnd.mozilla.xul+xml": "xul",
69+
"application/x-zip-compressed.": "zip",
70+
"application/x-7z-compressed": "7z"
71+
}
72+
}

0 commit comments

Comments
 (0)