Skip to content

Commit

Permalink
Fixed not working on mobile due to library dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Developer-Mike committed Jul 1, 2024
1 parent 4397910 commit 543b3b4
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 54 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
46 changes: 0 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/convertable-file-views/docx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion src/core/convertible-file-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
72 changes: 72 additions & 0 deletions src/utils/mime-utils.ts
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 543b3b4

Please sign in to comment.