Skip to content

Commit

Permalink
add option to ignore note properties when copying to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
addozhang committed Feb 27, 2024
1 parent 9887e31 commit 8b51ed8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"authorUrl": "https://atbug.com",
"isDesktopOnly": true,
"minAppVersion": "0.11.0",
"version": "0.5.1"
"version": "0.5.2"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-image-upload-toolkit",
"version": "0.5.1",
"version": "0.5.2",
"description": "",
"author": "addozhang",
"main": "main.js",
Expand Down
4 changes: 3 additions & 1 deletion src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {ImagekitSetting} from "./uploader/imagekit/imagekitUploader";

export interface PublishSettings {
imageAltText: boolean;
replaceOriginalDoc: boolean
replaceOriginalDoc: boolean;
ignoreProperties: boolean;
attachmentLocation: string;
imageStore: string;
//Imgur Anonymous setting
Expand All @@ -27,6 +28,7 @@ export interface PublishSettings {
const DEFAULT_SETTINGS: PublishSettings = {
imageAltText: true,
replaceOriginalDoc: false,
ignoreProperties: true,
attachmentLocation: ".",
imageStore: ImageStore.IMGUR.id,
imgurAnonymousSetting: {clientId: IMGUR_PLUGIN_CLIENT_ID},
Expand Down
17 changes: 13 additions & 4 deletions src/ui/publishSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,31 @@ export default class PublishSettingTab extends PluginSettingTab {
})
);

new Setting((imageStoreTypeDiv))
new Setting(imageStoreTypeDiv)
.setName("Use image name as Alt Text")
.setDesc("Whether to use image name as Alt Text with '-' and '_' replaced with space.")
.addToggle(toggle =>
toggle
.setValue(this.plugin.settings.imageAltText)
.onChange( value => this.plugin.settings.imageAltText = value)
.onChange(value => this.plugin.settings.imageAltText = value)
);

new Setting((imageStoreTypeDiv))
new Setting(imageStoreTypeDiv)
.setName("Update original document")
.setDesc("Whether to replace internal link with store link.")
.addToggle(toggle =>
toggle
.setValue(this.plugin.settings.replaceOriginalDoc)
.onChange( value => this.plugin.settings.replaceOriginalDoc = value)
.onChange(value => this.plugin.settings.replaceOriginalDoc = value)
);

new Setting(imageStoreTypeDiv)
.setName("Ignore note properties")
.setDesc("Where to ignore note properties when copying to clipboard. This won't affect original note.")
.addToggle(toggle =>
toggle
.setValue(this.plugin.settings.ignoreProperties)
.onChange(value => this.plugin.settings.ignoreProperties = value)
);

// Image Store
Expand Down
4 changes: 4 additions & 0 deletions src/uploader/imageTagProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {PublishSettings} from "../publish";

const MD_REGEX = /\!\[(.*)\]\((.*?\.(png|jpg|jpeg|gif|svg|webp|excalidraw))\)/g;
const WIKI_REGEX = /\!\[\[(.*?\.(png|jpg|jpeg|gif|svg|webp|excalidraw))(|.*)?\]\]/g;
const PROPERTIES_REGEX = /^---[\s\S]+?---\n/;

interface Image {
name: string;
Expand Down Expand Up @@ -59,6 +60,9 @@ export default class ImageTagProcessor {
if (this.settings.replaceOriginalDoc) {
this.getEditor()?.setValue(value);
}
if (this.settings.ignoreProperties) {
value = value.replace(PROPERTIES_REGEX, '');
}
switch (action) {
case ACTION_PUBLISH:
navigator.clipboard.writeText(value);
Expand Down

0 comments on commit 8b51ed8

Please sign in to comment.