Skip to content

Commit 2bf0e9f

Browse files
committed
Merge branch 'develop'
# Conflicts: # main.js
2 parents 55c18f9 + 5c23ed4 commit 2bf0e9f

14 files changed

Lines changed: 92 additions & 26 deletions

main.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80141,9 +80141,10 @@ var DEFAULT_SETTINGS = {
8014180141
defaultCommentStatus: "open" /* Open */,
8014280142
rememberLastSelectedCategories: true,
8014380143
showWordPressEditConfirm: false,
80144-
mathJaxOutputType: "svg" /* SVG */
80144+
mathJaxOutputType: "svg" /* SVG */,
80145+
enableHtml: false
8014580146
};
80146-
function upgradeSettings(existingSettings, to, plugin) {
80147+
function upgradeSettings(existingSettings, to) {
8014780148
return __async(this, null, function* () {
8014880149
console.log(existingSettings, to);
8014980150
if (isUndefined_default(existingSettings.version)) {
@@ -80185,10 +80186,16 @@ function upgradeSettings(existingSettings, to, plugin) {
8018580186
} else {
8018680187
newSettings.profiles = [];
8018780188
}
80188-
return newSettings;
80189+
return {
80190+
needUpgrade: true,
80191+
settings: newSettings
80192+
};
8018980193
}
8019080194
}
80191-
return existingSettings;
80195+
return {
80196+
needUpgrade: false,
80197+
settings: existingSettings
80198+
};
8019280199
});
8019380200
}
8019480201

@@ -91071,7 +91078,6 @@ var WpRestClient = class extends AbstractWordPressClient {
9107191078
response: data
9107291079
};
9107391080
}).catch((error) => {
91074-
console.log(error);
9107591081
return {
9107691082
code: 1 /* Error */,
9107791083
data: this.plugin.i18n.t("error_invalidUser")
@@ -91724,6 +91730,13 @@ var WordpressSettingTab = class extends import_obsidian15.PluginSettingTab {
9172491730
text: mathJaxOutputTypeDesc,
9172591731
cls: "setting-item-description"
9172691732
});
91733+
new import_obsidian15.Setting(containerEl).setName(t2("settings_enableHtml")).setDesc(t2("settings_enableHtmlDesc")).addToggle((toggle) => toggle.setValue(this.plugin.settings.enableHtml).onChange((value) => __async(this, null, function* () {
91734+
this.plugin.settings.enableHtml = value;
91735+
yield this.plugin.saveSettings();
91736+
AppState.getInstance().markdownParser.set({
91737+
html: this.plugin.settings.enableHtml
91738+
});
91739+
})));
9172791740
}
9172891741
};
9172991742

@@ -91835,6 +91848,8 @@ __export(en_exports, {
9183591848
settings_defaultPostStatusDesc: () => settings_defaultPostStatusDesc,
9183691849
settings_defaultPostStatusDraft: () => settings_defaultPostStatusDraft,
9183791850
settings_defaultPostStatusPublish: () => settings_defaultPostStatusPublish,
91851+
settings_enableHtml: () => settings_enableHtml,
91852+
settings_enableHtmlDesc: () => settings_enableHtmlDesc,
9183891853
settings_mathJaxOutputType: () => settings_mathJaxOutputType,
9183991854
settings_mathJaxOutputTypeDesc: () => settings_mathJaxOutputTypeDesc,
9184091855
settings_mathJaxOutputTypeSVG: () => settings_mathJaxOutputTypeSVG,
@@ -91924,7 +91939,9 @@ var settings_mathJaxOutputTypeDesc = "Select MathJax output format.";
9192491939
var settings_mathJaxOutputTypeTeX = "TeX";
9192591940
var settings_MathJaxOutputTypeTeXDesc = "Convert MathJax to TeX directly. WordPress needs install MathJax related plugin, such as simple-mathjax.";
9192691941
var settings_mathJaxOutputTypeSVG = "SVG";
91927-
var settings_MathJaxOutputTypeSVGDesc = "Convert MathJax to SVG. Browser render SVG, no plugin needed for WordPress";
91942+
var settings_MathJaxOutputTypeSVGDesc = "Convert MathJax to SVG. Browser render SVG, no plugin needed for WordPress.";
91943+
var settings_enableHtml = "Enable HTML";
91944+
var settings_enableHtmlDesc = "Enable HTML tags in notes. This might cause XSS attack to your WordPress.";
9192891945
var loginModal_title = "WordPress Login";
9192991946
var loginModal_username = "Username";
9193091947
var loginModal_usernameDesc = "Username for <%= url %>";
@@ -92033,6 +92050,8 @@ var en_default = {
9203392050
settings_MathJaxOutputTypeTeXDesc,
9203492051
settings_mathJaxOutputTypeSVG,
9203592052
settings_MathJaxOutputTypeSVGDesc,
92053+
settings_enableHtml,
92054+
settings_enableHtmlDesc,
9203692055
loginModal_title,
9203792056
loginModal_username,
9203892057
loginModal_usernameDesc,
@@ -92164,6 +92183,8 @@ __export(zh_cn_exports, {
9216492183
settings_defaultPostStatusDesc: () => settings_defaultPostStatusDesc2,
9216592184
settings_defaultPostStatusDraft: () => settings_defaultPostStatusDraft2,
9216692185
settings_defaultPostStatusPublish: () => settings_defaultPostStatusPublish2,
92186+
settings_enableHtml: () => settings_enableHtml2,
92187+
settings_enableHtmlDesc: () => settings_enableHtmlDesc2,
9216792188
settings_mathJaxOutputType: () => settings_mathJaxOutputType2,
9216892189
settings_mathJaxOutputTypeDesc: () => settings_mathJaxOutputTypeDesc2,
9216992190
settings_mathJaxOutputTypeSVG: () => settings_mathJaxOutputTypeSVG2,
@@ -92254,6 +92275,8 @@ var settings_mathJaxOutputTypeTeX2 = "TeX";
9225492275
var settings_MathJaxOutputTypeTeXDesc2 = "\u5C06 MathJax \u516C\u5F0F\u8F93\u51FA\u4E3A TeX \u683C\u5F0F\u3002WordPress \u9700\u8981\u5B89\u88C5 MathJax \u76F8\u5173\u63D2\u4EF6\uFF0C\u4F8B\u5982 simple-mathjax";
9225592276
var settings_mathJaxOutputTypeSVG2 = "SVG";
9225692277
var settings_MathJaxOutputTypeSVGDesc2 = "\u5C06 MathJax \u516C\u5F0F\u8F93\u51FA\u4E3A SVG \u683C\u5F0F\u3002\u6D4F\u89C8\u5668\u53EF\u4EE5\u76F4\u63A5\u663E\u793A SVG \u77E2\u91CF\u56FE\uFF0CWordPress \u65E0\u9700\u4EFB\u4F55\u5904\u7406";
92278+
var settings_enableHtml2 = "\u542F\u7528 HTML";
92279+
var settings_enableHtmlDesc2 = "\u542F\u7528\u7B14\u8BB0\u4E2D\u7684 HTML \u6807\u7B7E\u3002\u8FD9\u53EF\u80FD\u5BFC\u81F4\u9488\u5BF9 WordPress \u7684 XSS \u653B\u51FB";
9225792280
var loginModal_title2 = "WordPress \u767B\u5F55";
9225892281
var loginModal_username2 = "\u7528\u6237\u540D";
9225992282
var loginModal_usernameDesc2 = "<%= url %> \u7528\u6237\u540D";
@@ -92362,6 +92385,8 @@ var zh_cn_default = {
9236292385
settings_MathJaxOutputTypeTeXDesc: settings_MathJaxOutputTypeTeXDesc2,
9236392386
settings_mathJaxOutputTypeSVG: settings_mathJaxOutputTypeSVG2,
9236492387
settings_MathJaxOutputTypeSVGDesc: settings_MathJaxOutputTypeSVGDesc2,
92388+
settings_enableHtml: settings_enableHtml2,
92389+
settings_enableHtmlDesc: settings_enableHtmlDesc2,
9236592390
loginModal_title: loginModal_title2,
9236692391
loginModal_username: loginModal_username2,
9236792392
loginModal_usernameDesc: loginModal_usernameDesc2,
@@ -92547,10 +92572,13 @@ var WordpressPlugin = class extends import_obsidian19.Plugin {
9254792572
}
9254892573
loadSettings() {
9254992574
return __async(this, null, function* () {
92550-
var _a, _b, _c;
92575+
var _a, _b, _c, _d, _e;
9255192576
__privateSet(this, _settings, Object.assign({}, DEFAULT_SETTINGS, yield this.loadData()));
92552-
__privateSet(this, _settings, yield upgradeSettings(__privateGet(this, _settings), "2" /* V2 */, this));
92553-
yield this.saveSettings();
92577+
const { needUpgrade, settings } = yield upgradeSettings(__privateGet(this, _settings), "2" /* V2 */);
92578+
__privateSet(this, _settings, settings);
92579+
if (needUpgrade) {
92580+
yield this.saveSettings();
92581+
}
9255492582
const crypto2 = new PassCrypto();
9255592583
const count = (_b = (_a = __privateGet(this, _settings)) == null ? void 0 : _a.profiles.length) != null ? _b : 0;
9255692584
for (let i2 = 0; i2 < count; i2++) {
@@ -92560,6 +92588,9 @@ var WordpressPlugin = class extends import_obsidian19.Plugin {
9256092588
profile.password = yield crypto2.decrypt(enPass.encrypted, enPass.key, enPass.vector);
9256192589
}
9256292590
}
92591+
AppState.getInstance().markdownParser.set({
92592+
html: (_e = (_d = __privateGet(this, _settings)) == null ? void 0 : _d.enableHtml) != null ? _e : false
92593+
});
9256392594
});
9256492595
}
9256592596
saveSettings() {

src/app-state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Events } from 'obsidian';
22
import MarkdownIt from 'markdown-it';
33

4+
45
export class AppState {
56
private static instance: AppState;
67

src/confirm-modal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function openConfirmModal(
3535
/**
3636
* Confirm modal.
3737
*/
38-
export class ConfirmModal extends Modal {
38+
class ConfirmModal extends Modal {
3939

4040
constructor(
4141
private readonly messages: ConfirmModalMessages,

src/i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
"settings_mathJaxOutputTypeTeX": "TeX",
6565
"settings_MathJaxOutputTypeTeXDesc": "Convert MathJax to TeX directly. WordPress needs install MathJax related plugin, such as simple-mathjax.",
6666
"settings_mathJaxOutputTypeSVG": "SVG",
67-
"settings_MathJaxOutputTypeSVGDesc": "Convert MathJax to SVG. Browser render SVG, no plugin needed for WordPress",
67+
"settings_MathJaxOutputTypeSVGDesc": "Convert MathJax to SVG. Browser render SVG, no plugin needed for WordPress.",
68+
"settings_enableHtml": "Enable HTML",
69+
"settings_enableHtmlDesc": "Enable HTML tags in notes. This might cause XSS attack to your WordPress.",
6870
"loginModal_title": "WordPress Login",
6971
"loginModal_username": "Username",
7072
"loginModal_usernameDesc": "Username for <%= url %>",

src/i18n/zh-cn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
"settings_MathJaxOutputTypeTeXDesc": "将 MathJax 公式输出为 TeX 格式。WordPress 需要安装 MathJax 相关插件,例如 simple-mathjax",
6666
"settings_mathJaxOutputTypeSVG": "SVG",
6767
"settings_MathJaxOutputTypeSVGDesc": "将 MathJax 公式输出为 SVG 格式。浏览器可以直接显示 SVG 矢量图,WordPress 无需任何处理",
68+
"settings_enableHtml": "启用 HTML",
69+
"settings_enableHtmlDesc": "启用笔记中的 HTML 标签。这可能导致针对 WordPress 的 XSS 攻击",
6870
"loginModal_title": "WordPress 登录",
6971
"loginModal_username": "用户名",
7072
"loginModal_usernameDesc": "<%= url %> 用户名",

src/main.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ export default class WordpressPlugin extends Plugin {
8080

8181
async loadSettings() {
8282
this.#settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
83-
this.#settings = await upgradeSettings(this.#settings, SettingsVersion.V2, this);
84-
await this.saveSettings();
83+
const { needUpgrade, settings } = await upgradeSettings(this.#settings, SettingsVersion.V2);
84+
this.#settings = settings;
85+
if (needUpgrade) {
86+
await this.saveSettings();
87+
}
8588

8689
const crypto = new PassCrypto();
8790
const count = this.#settings?.profiles.length ?? 0;
@@ -92,6 +95,10 @@ export default class WordpressPlugin extends Plugin {
9295
profile.password = await crypto.decrypt(enPass.encrypted, enPass.key, enPass.vector);
9396
}
9497
}
98+
99+
AppState.getInstance().markdownParser.set({
100+
html: this.#settings?.enableHtml ?? false
101+
});
95102
}
96103

97104
async saveSettings() {

src/plugin-settings.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export interface WordpressPluginSettings {
6161
showWordPressEditConfirm: boolean;
6262

6363
mathJaxOutputType: MathJaxOutputType;
64+
65+
enableHtml: boolean;
6466
}
6567

6668
export const DEFAULT_SETTINGS: WordpressPluginSettings = {
@@ -71,14 +73,14 @@ export const DEFAULT_SETTINGS: WordpressPluginSettings = {
7173
defaultCommentStatus: CommentStatus.Open,
7274
rememberLastSelectedCategories: true,
7375
showWordPressEditConfirm: false,
74-
mathJaxOutputType: MathJaxOutputType.SVG
76+
mathJaxOutputType: MathJaxOutputType.SVG,
77+
enableHtml: false
7578
}
7679

7780
export async function upgradeSettings(
7881
existingSettings: SafeAny,
79-
to: SettingsVersion,
80-
plugin: WordpressPlugin
81-
): Promise<WordpressPluginSettings> {
82+
to: SettingsVersion
83+
): Promise<{ needUpgrade: boolean, settings: WordpressPluginSettings }> {
8284
console.log(existingSettings, to);
8385
if (isUndefined(existingSettings.version)) {
8486
// V1
@@ -120,8 +122,14 @@ export async function upgradeSettings(
120122
} else {
121123
newSettings.profiles = [];
122124
}
123-
return newSettings;
125+
return {
126+
needUpgrade: true,
127+
settings: newSettings
128+
};
124129
}
125130
}
126-
return existingSettings;
131+
return {
132+
needUpgrade: false,
133+
settings: existingSettings
134+
};
127135
}

src/post-published-modal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function openPostPublishedModal(
1717
/**
1818
* WordPress post published modal.
1919
*/
20-
export class PostPublishedModal extends Modal {
20+
class PostPublishedModal extends Modal {
2121

2222
constructor(
2323
private readonly plugin: WordpressPlugin,

src/settings.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { WpProfileManageModal } from './wp-profile-manage-modal';
66
import { MathJaxOutputType } from './plugin-settings';
77
import { WpProfile } from './wp-profile';
88
import { setupMarkdownParser } from './utils';
9+
import { AppState } from './app-state';
910

1011

1112
export class WordpressSettingTab extends PluginSettingTab {
@@ -38,7 +39,6 @@ export class WordpressSettingTab extends PluginSettingTab {
3839

3940
containerEl.createEl('h1', { text: t('settings_title') });
4041

41-
// let apiDesc = getApiTypeDesc(this.plugin.settings.apiType);
4242
let mathJaxOutputTypeDesc = getMathJaxOutputTypeDesc(this.plugin.settings.mathJaxOutputType);
4343

4444
new Setting(containerEl)
@@ -146,6 +146,22 @@ export class WordpressSettingTab extends PluginSettingTab {
146146
text: mathJaxOutputTypeDesc,
147147
cls: 'setting-item-description'
148148
});
149+
150+
new Setting(containerEl)
151+
.setName(t('settings_enableHtml'))
152+
.setDesc(t('settings_enableHtmlDesc'))
153+
.addToggle((toggle) =>
154+
toggle
155+
.setValue(this.plugin.settings.enableHtml)
156+
.onChange(async (value) => {
157+
this.plugin.settings.enableHtml = value;
158+
await this.plugin.saveSettings();
159+
160+
AppState.getInstance().markdownParser.set({
161+
html: this.plugin.settings.enableHtml
162+
});
163+
}),
164+
);
149165
}
150166

151167
}

src/wp-login-modal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function openLoginModal(
2323
/**
2424
* WordPress login modal with username and password inputs.
2525
*/
26-
export class WpLoginModal extends Modal {
26+
class WpLoginModal extends Modal {
2727

2828
constructor(
2929
private readonly plugin: WordpressPlugin,

0 commit comments

Comments
 (0)