Skip to content

Commit 359b2f0

Browse files
committed
chore: prettify
1 parent 6b300d5 commit 359b2f0

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

src/core.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assertNever from "assert-never";
22
import { NothingSelected, PluginSettings } from "setting";
3-
import fileUrl from 'file-url';
3+
import fileUrl from "file-url";
44

55
interface WordBoundaries {
66
start: { line: number; ch: number };
@@ -10,7 +10,7 @@ interface WordBoundaries {
1010
// https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch08s18.html
1111
const win32Path = /^[a-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$/i;
1212
const unixPath = /^(?:\/[^/]+)+\/?$/i;
13-
const testFilePath = (url:string) => win32Path.test(url) || unixPath.test(url);
13+
const testFilePath = (url: string) => win32Path.test(url) || unixPath.test(url);
1414

1515
/**
1616
* @param cm CodeMirror Instance
@@ -111,13 +111,13 @@ function getReplaceText(
111111
return true;
112112
} catch (error) {
113113
// settings.regex: fallback test allows url without protocol (http,file...)
114-
return testFilePath(text) || new RegExp(settings.regex).test(text);
114+
return testFilePath(text) || new RegExp(settings.regex).test(text);
115115
}
116116
};
117117
const isImgEmbed = (text: string): boolean => {
118118
const rules = settings.listForImgEmbed
119119
.split("\n")
120-
.filter(v => v.length > 0)
120+
.filter((v) => v.length > 0)
121121
.map((v) => new RegExp(v));
122122
for (const reg of rules) {
123123
if (reg.test(text)) return true;
@@ -153,7 +153,7 @@ function getReplaceText(
153153
/** Process file url, special characters, etc */
154154
function processUrl(src: string): string {
155155
let output;
156-
if (testFilePath(src)){
156+
if (testFilePath(src)) {
157157
output = fileUrl(src, { resolve: false });
158158
} else {
159159
output = src;

src/main.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MarkdownView, Plugin } from "obsidian";
22
import * as CodeMirror from "codemirror";
3-
import UrlIntoSelection from "./core"
3+
import UrlIntoSelection from "./core";
44
import {
55
PluginSettings,
66
UrlIntoSelectionSettingsTab,
@@ -24,9 +24,7 @@ export default class UrlIntoSel_Plugin extends Plugin {
2424
});
2525

2626
this.registerCodeMirror((cm: CodeMirror.Editor) => {
27-
cm.on("paste", (cm, e) =>
28-
UrlIntoSelection(cm, e, this.settings)
29-
);
27+
cm.on("paste", (cm, e) => UrlIntoSelection(cm, e, this.settings));
3028
});
3129
}
3230

@@ -44,4 +42,4 @@ export default class UrlIntoSel_Plugin extends Plugin {
4442
return activeLeaf.view.sourceMode.cmEditor;
4543
} else throw new Error("activeLeaf.view not MarkdownView");
4644
}
47-
}
45+
}

src/setting.ts

+19-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const DEFAULT_SETTINGS: PluginSettings = {
1818
regex: /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/
1919
.source,
2020
nothingSelected: NothingSelected.doNothing,
21-
listForImgEmbed: ""
21+
listForImgEmbed: "",
2222
};
2323

2424
export class UrlIntoSelectionSettingsTab extends PluginSettingTab {
@@ -31,7 +31,9 @@ export class UrlIntoSelectionSettingsTab extends PluginSettingTab {
3131

3232
new Setting(containerEl)
3333
.setName("Fallback Regular expression")
34-
.setDesc("Regular expression used to match URLs when default match fails.")
34+
.setDesc(
35+
"Regular expression used to match URLs when default match fails."
36+
)
3537
.addText((text) =>
3638
text
3739
.setPlaceholder("Enter regular expression here..")
@@ -45,15 +47,13 @@ export class UrlIntoSelectionSettingsTab extends PluginSettingTab {
4547
);
4648
new Setting(containerEl)
4749
.setName("Behavior on pasting URL when nothing is selected")
48-
.setDesc(
49-
"Auto Select: Automatically select word surrounding the cursor."
50-
)
50+
.setDesc("Auto Select: Automatically select word surrounding the cursor.")
5151
.addDropdown((dropdown) => {
5252
const options: Record<NothingSelected, string> = {
5353
0: "Do nothing",
5454
1: "Auto Select",
5555
2: "Insert [](url)",
56-
3: "Insert <url>"
56+
3: "Insert <url>",
5757
};
5858

5959
dropdown
@@ -65,22 +65,26 @@ export class UrlIntoSelectionSettingsTab extends PluginSettingTab {
6565
this.display();
6666
});
6767
});
68-
new Setting(containerEl)
69-
.setName('Whitelist for image embed syntax')
70-
.setDesc(createFragment(el=>{
71-
el.appendText("![selection](url) will be used for URL that matches the following list.");
72-
el.createEl('br');
73-
el.appendText("Rules are regex-based, split by line break.")
74-
}))
68+
new Setting(containerEl)
69+
.setName("Whitelist for image embed syntax")
70+
.setDesc(
71+
createFragment((el) => {
72+
el.appendText(
73+
"![selection](url) will be used for URL that matches the following list."
74+
);
75+
el.createEl("br");
76+
el.appendText("Rules are regex-based, split by line break.");
77+
})
78+
)
7579
.addTextArea((text) => {
7680
text
77-
.setPlaceholder('Example:\nyoutu\.?be|vimeo')
81+
.setPlaceholder("Example:\nyoutu.?be|vimeo")
7882
.setValue(plugin.settings.listForImgEmbed)
7983
.onChange((value) => {
8084
plugin.settings.listForImgEmbed = value;
8185
plugin.saveData(plugin.settings);
8286
return text;
83-
})
87+
});
8488
text.inputEl.rows = 6;
8589
text.inputEl.cols = 25;
8690
});

0 commit comments

Comments
 (0)