From 4eaf797d049b2a306b67a63ba6b9b1454e24e2f4 Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Tue, 27 Feb 2024 22:16:25 +0100 Subject: [PATCH 1/9] removed Image to Text prefix --- README.md | 12 ++++++------ src/main.ts | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a4b1d4c..4f7859b 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ Recognize Text on images in your notes. Select the image and run the command. Th ## Commands -| Command | Description | -| -------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -| Image To Text: Replace Selection | Replace your image with the recognized text. Recognize text based on the language defined in settings | -| Image To Text: Replace Selection - custom language | Replace your image with the recognized text. Recognize text based on custom selection | -| Image To Text: Append Selection | Append the recognized text to your image. Recognize text based on language defined in settings | -| Image To Text: Append Selection - custom language | Append the recognized text to your image. Recognize text based on custom selection | +| Command | Description | +| ----------------------------------- | ----------------------------------------------------------------------------------------------------- | +| Replace Selection | Replace your image with the recognized text. Recognize text based on the language defined in settings | +| Replace Selection - custom language | Replace your image with the recognized text. Recognize text based on custom selection | +| Append Selection | Append the recognized text to your image. Recognize text based on language defined in settings | +| Append Selection - custom language | Append the recognized text to your image. Recognize text based on custom selection | ## Example diff --git a/src/main.ts b/src/main.ts index 15ac144..11fa9fc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -42,7 +42,7 @@ export default class ImageToTextOcrPlugin extends Plugin { this.addCommand({ id: "replace", - name: "Image To Text: Replace Selection", + name: "Replace Selection", icon: "image-minus", editorCallback: async (editor: Editor) => { const selection = editor.getSelection(); @@ -77,7 +77,7 @@ export default class ImageToTextOcrPlugin extends Plugin { this.addCommand({ id: "replace-select-language", - name: "Image To Text: Replace Selection - custom language", + name: "Replace Selection - custom language", icon: "image-minus", editorCallback: async (editor: Editor) => { const selection = editor.getSelection(); @@ -124,7 +124,7 @@ export default class ImageToTextOcrPlugin extends Plugin { this.addCommand({ id: "append", - name: "Image To Text: Append Selection", + name: "Append Selection", icon: "image-plus", editorCallback: async (editor: Editor) => { const selection = editor.getSelection(); @@ -158,7 +158,7 @@ export default class ImageToTextOcrPlugin extends Plugin { this.addCommand({ id: "append-select-language", - name: "Image To Text: Append Selection - custom language", + name: "Append Selection - custom language", icon: "image-plus", editorCallback: async (editor: Editor) => { const selection = editor.getSelection(); From 745724110c9a6dc46015a259347dc68278b76ff4 Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Tue, 27 Feb 2024 22:17:39 +0100 Subject: [PATCH 2/9] changed to sentence case --- README.md | 8 ++++---- src/main.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4f7859b..056d176 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ Recognize Text on images in your notes. Select the image and run the command. Th | Command | Description | | ----------------------------------- | ----------------------------------------------------------------------------------------------------- | -| Replace Selection | Replace your image with the recognized text. Recognize text based on the language defined in settings | -| Replace Selection - custom language | Replace your image with the recognized text. Recognize text based on custom selection | -| Append Selection | Append the recognized text to your image. Recognize text based on language defined in settings | -| Append Selection - custom language | Append the recognized text to your image. Recognize text based on custom selection | +| Replace selection | Replace your image with the recognized text. Recognize text based on the language defined in settings | +| Replace selection - custom language | Replace your image with the recognized text. Recognize text based on custom selection | +| Append selection | Append the recognized text to your image. Recognize text based on language defined in settings | +| Append selection - custom language | Append the recognized text to your image. Recognize text based on custom selection | ## Example diff --git a/src/main.ts b/src/main.ts index 11fa9fc..36b8c97 100644 --- a/src/main.ts +++ b/src/main.ts @@ -42,7 +42,7 @@ export default class ImageToTextOcrPlugin extends Plugin { this.addCommand({ id: "replace", - name: "Replace Selection", + name: "Replace selection", icon: "image-minus", editorCallback: async (editor: Editor) => { const selection = editor.getSelection(); @@ -77,7 +77,7 @@ export default class ImageToTextOcrPlugin extends Plugin { this.addCommand({ id: "replace-select-language", - name: "Replace Selection - custom language", + name: "Replace selection - custom language", icon: "image-minus", editorCallback: async (editor: Editor) => { const selection = editor.getSelection(); @@ -124,7 +124,7 @@ export default class ImageToTextOcrPlugin extends Plugin { this.addCommand({ id: "append", - name: "Append Selection", + name: "Append selection", icon: "image-plus", editorCallback: async (editor: Editor) => { const selection = editor.getSelection(); @@ -158,7 +158,7 @@ export default class ImageToTextOcrPlugin extends Plugin { this.addCommand({ id: "append-select-language", - name: "Append Selection - custom language", + name: "Append selection - custom language", icon: "image-plus", editorCallback: async (editor: Editor) => { const selection = editor.getSelection(); From a601dc6ea1c27645bf40e6d61e19de1bb2ef7b58 Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Tue, 27 Feb 2024 22:33:40 +0100 Subject: [PATCH 3/9] changed to sentence case --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index eee6e84..82f4f76 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "id": "image-to-text-ocr", - "name": "Image to Text OCR", + "name": "Image to text OCR", "version": "1.0.1", "minAppVersion": "0.15.0", "description": "Convert a image in your note to text.", @@ -8,4 +8,4 @@ "authorUrl": "https://github.com/dario-baumberger", "fundingUrl": "https://www.buymeacoffee.com/dariobaumberger", "isDesktopOnly": false -} \ No newline at end of file +} From 8b06e7206f471859f6ffdf46ddd3d6514d58de1b Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Tue, 27 Feb 2024 22:36:02 +0100 Subject: [PATCH 4/9] replaced vault adapter and vault getFiles --- README.md | 6 +----- src/main.ts | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 056d176..422d62d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![GitHub stars](https://img.shields.io/github/stars/dario-baumberger/obsidian-image-to-text-ocr?style=flat) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/dario-baumberger/obsidian-image-to-text-ocr/blob/master/LICENCE) -# Obsidian Image to Text +# Obsidian Image to text Recognize Text on images in your notes. Select the image and run the command. The recognized text will be appended to your image or will replace your image - depending on the command @@ -40,10 +40,6 @@ Recognize Text on images in your notes. Select the image and run the command. Th | URL | `https://www.example.com/example.png` | URL to an image | | img Tag | `` | Img tag with a valid src attribute | -## Supported Devices - -Obsidian images are not supported on mobile devices since the file adapter works only on desktop. All other images are available also on mobile. - ## Installation ### Community Plugin diff --git a/src/main.ts b/src/main.ts index 36b8c97..e8366dc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import {Editor, FileSystemAdapter, Notice, Plugin, TFile} from "obsidian"; +import {Editor, Notice, Plugin} from "obsidian"; import {ImageToTextOcrPluginSettingTab} from "./settings"; import { checkFileType, @@ -29,8 +29,6 @@ const MESSAGE_FILETYPE = const MESSAGE_CONTENT = "Not supported content. Allowed: Obsidian Images, Markdown Images and Urls"; const MESSAGE_PATH = "Could not resolve image path"; -const MESSAGE_ADAPTER = - "Error resolving adapter. Obsidian images are not supported on mobile devices."; const MESSAGE_NOTFOUND = "Image file not found in the vault."; const MESSAGE_RUNNING = "Recoginition is running..."; @@ -225,25 +223,22 @@ export default class ImageToTextOcrPlugin extends Plugin { * get file path based on filename */ async resolveImagePath(fileName: string): Promise { - const files = this.app.vault.getFiles(); - const imageFile = files.find((file) => file.name === fileName); + const imageFile = this.app.metadataCache.getFirstLinkpathDest( + fileName, + "" + ); if (!imageFile) { new Notice(MESSAGE_NOTFOUND, 0); throw new Error(MESSAGE_NOTFOUND); } - const adapter = this.app.vault.adapter; - if (adapter instanceof FileSystemAdapter) { - const resourcePath = adapter.getResourcePath(imageFile.path); - if (this.settings.devMode) { - console.log(`resourcePath: ${resourcePath}`); - } - return resourcePath; - } else { - new Notice(MESSAGE_ADAPTER, 0); - throw new Error(MESSAGE_ADAPTER); + const resourcePath = this.app.vault.getResourcePath(imageFile); + + if (this.settings.devMode) { + console.log(`resourcePath: ${resourcePath}`); } + return resourcePath; } /** From 25341caa017e6f7e4ce9b1a88fbcf716d15b280a Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Tue, 27 Feb 2024 22:37:59 +0100 Subject: [PATCH 5/9] changed to prettier write --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8254975..6f27b59 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "version": "node version-bump.mjs && git add manifest.json versions.json", "test": "vitest", "lint": "npx eslint", - "prettier": "npx prettier .", + "prettier": "npx prettier . --write", "coverage": "vitest run --coverage" }, "keywords": [], From 030d9eaa8714fcac35630e063632771d600bcd40 Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Tue, 27 Feb 2024 22:41:17 +0100 Subject: [PATCH 6/9] prettier --- .github/ISSUE_TEMPLATE/bug_report.md | 20 +++++++++++--------- .github/ISSUE_TEMPLATE/feature_request.md | 3 +-- esbuild.config.mjs | 6 +++--- src/languages.ts | 2 +- version-bump.mjs | 4 ++-- versions.json | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 5b0a804..0914b29 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -3,8 +3,7 @@ name: Bug report about: Create a report to help us improve title: "[BUG]" labels: bug -assignees: '' - +assignees: "" --- **Describe the bug** @@ -12,6 +11,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' @@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] **Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 11eb268..32109a7 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -3,8 +3,7 @@ name: Feature request about: Suggest an idea for this project title: "[Feature Request]" labels: enhancement -assignees: '' - +assignees: "" --- **Is your feature request related to a problem? Please describe.** diff --git a/esbuild.config.mjs b/esbuild.config.mjs index e4197e9..612d75c 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -12,7 +12,7 @@ const prod = process.argv[2] === "production"; const context = await esbuild.context({ banner: { - js: banner, + js: banner }, entryPoints: ["src/main.ts"], bundle: true, @@ -30,14 +30,14 @@ const context = await esbuild.context({ "@lezer/common", "@lezer/highlight", "@lezer/lr", - ...builtins, + ...builtins ], format: "cjs", target: "es2018", logLevel: "info", sourcemap: prod ? false : "inline", treeShaking: true, - outfile: "main.js", + outfile: "main.js" }); if (prod) { diff --git a/src/languages.ts b/src/languages.ts index 1b1f49a..68b82cb 100644 --- a/src/languages.ts +++ b/src/languages.ts @@ -100,5 +100,5 @@ export const languages: Record = { uzb: "Uzbek", uzb_cyrl: "Uzbek - Cyrillic", vie: "Vietnamese", - yid: "Yiddish", + yid: "Yiddish" }; diff --git a/version-bump.mjs b/version-bump.mjs index d409fa0..816d38b 100644 --- a/version-bump.mjs +++ b/version-bump.mjs @@ -1,10 +1,10 @@ -import { readFileSync, writeFileSync } from "fs"; +import {readFileSync, writeFileSync} from "fs"; const targetVersion = process.env.npm_package_version; // read minAppVersion from manifest.json and bump version to target version let manifest = JSON.parse(readFileSync("manifest.json", "utf8")); -const { minAppVersion } = manifest; +const {minAppVersion} = manifest; manifest.version = targetVersion; writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t")); diff --git a/versions.json b/versions.json index a6d5a03..189c17e 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,4 @@ { "1.0.0": "0.15.0", "1.0.1": "0.15.0" -} \ No newline at end of file +} From bc631a1ba64377e3851e5eb717456e3e76f4fda8 Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Tue, 27 Feb 2024 22:42:16 +0100 Subject: [PATCH 7/9] ignore coverage files --- .gitignore | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.gitignore b/.gitignore index e09a007..e6860db 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,23 @@ data.json # Exclude macOS Finder (System Explorer) View States .DS_Store +coverage/base.css +coverage/block-navigation.js +coverage/clover.xml +coverage/coverage-final.json +coverage/favicon.png +coverage/index.html +coverage/prettify.css +coverage/prettify.js +coverage/sort-arrow-sprite.png +coverage/sorter.js +coverage/obsidian-image-to-text-ocr/esbuild.config.mjs.html +coverage/obsidian-image-to-text-ocr/index.html +coverage/obsidian-image-to-text-ocr/main.js.html +coverage/obsidian-image-to-text-ocr/version-bump.mjs.html +coverage/obsidian-image-to-text-ocr/src/functions.ts.html +coverage/obsidian-image-to-text-ocr/src/index.html +coverage/obsidian-image-to-text-ocr/src/languages.ts.html +coverage/obsidian-image-to-text-ocr/src/main.ts.html +coverage/obsidian-image-to-text-ocr/src/modal.ts.html +coverage/obsidian-image-to-text-ocr/src/settings.ts.html From 584669ec756baf2cea7caf3bdc33567f16d8d74f Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Tue, 27 Feb 2024 22:43:08 +0100 Subject: [PATCH 8/9] chaged gitignore coverage pattern --- .gitignore | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index e6860db..276a0f1 100644 --- a/.gitignore +++ b/.gitignore @@ -20,23 +20,6 @@ data.json # Exclude macOS Finder (System Explorer) View States .DS_Store -coverage/base.css -coverage/block-navigation.js -coverage/clover.xml -coverage/coverage-final.json -coverage/favicon.png -coverage/index.html -coverage/prettify.css -coverage/prettify.js -coverage/sort-arrow-sprite.png -coverage/sorter.js -coverage/obsidian-image-to-text-ocr/esbuild.config.mjs.html -coverage/obsidian-image-to-text-ocr/index.html -coverage/obsidian-image-to-text-ocr/main.js.html -coverage/obsidian-image-to-text-ocr/version-bump.mjs.html -coverage/obsidian-image-to-text-ocr/src/functions.ts.html -coverage/obsidian-image-to-text-ocr/src/index.html -coverage/obsidian-image-to-text-ocr/src/languages.ts.html -coverage/obsidian-image-to-text-ocr/src/main.ts.html -coverage/obsidian-image-to-text-ocr/src/modal.ts.html -coverage/obsidian-image-to-text-ocr/src/settings.ts.html + +# exlude coverage +coverage/ From b29eae685aed144a19c983eb8dd2f0c0fc236098 Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Tue, 27 Feb 2024 22:44:33 +0100 Subject: [PATCH 9/9] changed to version 1.0.2 --- manifest.json | 4 ++-- package.json | 2 +- versions.json | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/manifest.json b/manifest.json index 82f4f76..351d388 100644 --- a/manifest.json +++ b/manifest.json @@ -1,11 +1,11 @@ { "id": "image-to-text-ocr", "name": "Image to text OCR", - "version": "1.0.1", + "version": "1.0.2", "minAppVersion": "0.15.0", "description": "Convert a image in your note to text.", "author": "Dario Baumberger", "authorUrl": "https://github.com/dario-baumberger", "fundingUrl": "https://www.buymeacoffee.com/dariobaumberger", "isDesktopOnly": false -} +} \ No newline at end of file diff --git a/package.json b/package.json index 6f27b59..bbb998e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-image-to-text-ocr", - "version": "1.0.1", + "version": "1.0.2", "description": "Convert a image in your note to text", "main": "main.js", "scripts": { diff --git a/versions.json b/versions.json index 189c17e..03d60fe 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { "1.0.0": "0.15.0", - "1.0.1": "0.15.0" -} + "1.0.1": "0.15.0", + "1.0.2": "0.15.0" +} \ No newline at end of file