Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	main.js
  • Loading branch information
devbean committed Apr 17, 2023
2 parents 55c18f9 + 5c23ed4 commit 2bf0e9f
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 26 deletions.
49 changes: 40 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80141,9 +80141,10 @@ var DEFAULT_SETTINGS = {
defaultCommentStatus: "open" /* Open */,
rememberLastSelectedCategories: true,
showWordPressEditConfirm: false,
mathJaxOutputType: "svg" /* SVG */
mathJaxOutputType: "svg" /* SVG */,
enableHtml: false
};
function upgradeSettings(existingSettings, to, plugin) {
function upgradeSettings(existingSettings, to) {
return __async(this, null, function* () {
console.log(existingSettings, to);
if (isUndefined_default(existingSettings.version)) {
Expand Down Expand Up @@ -80185,10 +80186,16 @@ function upgradeSettings(existingSettings, to, plugin) {
} else {
newSettings.profiles = [];
}
return newSettings;
return {
needUpgrade: true,
settings: newSettings
};
}
}
return existingSettings;
return {
needUpgrade: false,
settings: existingSettings
};
});
}

Expand Down Expand Up @@ -91071,7 +91078,6 @@ var WpRestClient = class extends AbstractWordPressClient {
response: data
};
}).catch((error) => {
console.log(error);
return {
code: 1 /* Error */,
data: this.plugin.i18n.t("error_invalidUser")
Expand Down Expand Up @@ -91724,6 +91730,13 @@ var WordpressSettingTab = class extends import_obsidian15.PluginSettingTab {
text: mathJaxOutputTypeDesc,
cls: "setting-item-description"
});
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* () {
this.plugin.settings.enableHtml = value;
yield this.plugin.saveSettings();
AppState.getInstance().markdownParser.set({
html: this.plugin.settings.enableHtml
});
})));
}
};

Expand Down Expand Up @@ -91835,6 +91848,8 @@ __export(en_exports, {
settings_defaultPostStatusDesc: () => settings_defaultPostStatusDesc,
settings_defaultPostStatusDraft: () => settings_defaultPostStatusDraft,
settings_defaultPostStatusPublish: () => settings_defaultPostStatusPublish,
settings_enableHtml: () => settings_enableHtml,
settings_enableHtmlDesc: () => settings_enableHtmlDesc,
settings_mathJaxOutputType: () => settings_mathJaxOutputType,
settings_mathJaxOutputTypeDesc: () => settings_mathJaxOutputTypeDesc,
settings_mathJaxOutputTypeSVG: () => settings_mathJaxOutputTypeSVG,
Expand Down Expand Up @@ -91924,7 +91939,9 @@ var settings_mathJaxOutputTypeDesc = "Select MathJax output format.";
var settings_mathJaxOutputTypeTeX = "TeX";
var settings_MathJaxOutputTypeTeXDesc = "Convert MathJax to TeX directly. WordPress needs install MathJax related plugin, such as simple-mathjax.";
var settings_mathJaxOutputTypeSVG = "SVG";
var settings_MathJaxOutputTypeSVGDesc = "Convert MathJax to SVG. Browser render SVG, no plugin needed for WordPress";
var settings_MathJaxOutputTypeSVGDesc = "Convert MathJax to SVG. Browser render SVG, no plugin needed for WordPress.";
var settings_enableHtml = "Enable HTML";
var settings_enableHtmlDesc = "Enable HTML tags in notes. This might cause XSS attack to your WordPress.";
var loginModal_title = "WordPress Login";
var loginModal_username = "Username";
var loginModal_usernameDesc = "Username for <%= url %>";
Expand Down Expand Up @@ -92033,6 +92050,8 @@ var en_default = {
settings_MathJaxOutputTypeTeXDesc,
settings_mathJaxOutputTypeSVG,
settings_MathJaxOutputTypeSVGDesc,
settings_enableHtml,
settings_enableHtmlDesc,
loginModal_title,
loginModal_username,
loginModal_usernameDesc,
Expand Down Expand Up @@ -92164,6 +92183,8 @@ __export(zh_cn_exports, {
settings_defaultPostStatusDesc: () => settings_defaultPostStatusDesc2,
settings_defaultPostStatusDraft: () => settings_defaultPostStatusDraft2,
settings_defaultPostStatusPublish: () => settings_defaultPostStatusPublish2,
settings_enableHtml: () => settings_enableHtml2,
settings_enableHtmlDesc: () => settings_enableHtmlDesc2,
settings_mathJaxOutputType: () => settings_mathJaxOutputType2,
settings_mathJaxOutputTypeDesc: () => settings_mathJaxOutputTypeDesc2,
settings_mathJaxOutputTypeSVG: () => settings_mathJaxOutputTypeSVG2,
Expand Down Expand Up @@ -92254,6 +92275,8 @@ var settings_mathJaxOutputTypeTeX2 = "TeX";
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";
var settings_mathJaxOutputTypeSVG2 = "SVG";
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";
var settings_enableHtml2 = "\u542F\u7528 HTML";
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";
var loginModal_title2 = "WordPress \u767B\u5F55";
var loginModal_username2 = "\u7528\u6237\u540D";
var loginModal_usernameDesc2 = "<%= url %> \u7528\u6237\u540D";
Expand Down Expand Up @@ -92362,6 +92385,8 @@ var zh_cn_default = {
settings_MathJaxOutputTypeTeXDesc: settings_MathJaxOutputTypeTeXDesc2,
settings_mathJaxOutputTypeSVG: settings_mathJaxOutputTypeSVG2,
settings_MathJaxOutputTypeSVGDesc: settings_MathJaxOutputTypeSVGDesc2,
settings_enableHtml: settings_enableHtml2,
settings_enableHtmlDesc: settings_enableHtmlDesc2,
loginModal_title: loginModal_title2,
loginModal_username: loginModal_username2,
loginModal_usernameDesc: loginModal_usernameDesc2,
Expand Down Expand Up @@ -92547,10 +92572,13 @@ var WordpressPlugin = class extends import_obsidian19.Plugin {
}
loadSettings() {
return __async(this, null, function* () {
var _a, _b, _c;
var _a, _b, _c, _d, _e;
__privateSet(this, _settings, Object.assign({}, DEFAULT_SETTINGS, yield this.loadData()));
__privateSet(this, _settings, yield upgradeSettings(__privateGet(this, _settings), "2" /* V2 */, this));
yield this.saveSettings();
const { needUpgrade, settings } = yield upgradeSettings(__privateGet(this, _settings), "2" /* V2 */);
__privateSet(this, _settings, settings);
if (needUpgrade) {
yield this.saveSettings();
}
const crypto2 = new PassCrypto();
const count = (_b = (_a = __privateGet(this, _settings)) == null ? void 0 : _a.profiles.length) != null ? _b : 0;
for (let i2 = 0; i2 < count; i2++) {
Expand All @@ -92560,6 +92588,9 @@ var WordpressPlugin = class extends import_obsidian19.Plugin {
profile.password = yield crypto2.decrypt(enPass.encrypted, enPass.key, enPass.vector);
}
}
AppState.getInstance().markdownParser.set({
html: (_e = (_d = __privateGet(this, _settings)) == null ? void 0 : _d.enableHtml) != null ? _e : false
});
});
}
saveSettings() {
Expand Down
1 change: 1 addition & 0 deletions src/app-state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Events } from 'obsidian';
import MarkdownIt from 'markdown-it';


export class AppState {
private static instance: AppState;

Expand Down
2 changes: 1 addition & 1 deletion src/confirm-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function openConfirmModal(
/**
* Confirm modal.
*/
export class ConfirmModal extends Modal {
class ConfirmModal extends Modal {

constructor(
private readonly messages: ConfirmModalMessages,
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
"settings_mathJaxOutputTypeTeX": "TeX",
"settings_MathJaxOutputTypeTeXDesc": "Convert MathJax to TeX directly. WordPress needs install MathJax related plugin, such as simple-mathjax.",
"settings_mathJaxOutputTypeSVG": "SVG",
"settings_MathJaxOutputTypeSVGDesc": "Convert MathJax to SVG. Browser render SVG, no plugin needed for WordPress",
"settings_MathJaxOutputTypeSVGDesc": "Convert MathJax to SVG. Browser render SVG, no plugin needed for WordPress.",
"settings_enableHtml": "Enable HTML",
"settings_enableHtmlDesc": "Enable HTML tags in notes. This might cause XSS attack to your WordPress.",
"loginModal_title": "WordPress Login",
"loginModal_username": "Username",
"loginModal_usernameDesc": "Username for <%= url %>",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"settings_MathJaxOutputTypeTeXDesc": "将 MathJax 公式输出为 TeX 格式。WordPress 需要安装 MathJax 相关插件,例如 simple-mathjax",
"settings_mathJaxOutputTypeSVG": "SVG",
"settings_MathJaxOutputTypeSVGDesc": "将 MathJax 公式输出为 SVG 格式。浏览器可以直接显示 SVG 矢量图,WordPress 无需任何处理",
"settings_enableHtml": "启用 HTML",
"settings_enableHtmlDesc": "启用笔记中的 HTML 标签。这可能导致针对 WordPress 的 XSS 攻击",
"loginModal_title": "WordPress 登录",
"loginModal_username": "用户名",
"loginModal_usernameDesc": "<%= url %> 用户名",
Expand Down
11 changes: 9 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ export default class WordpressPlugin extends Plugin {

async loadSettings() {
this.#settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
this.#settings = await upgradeSettings(this.#settings, SettingsVersion.V2, this);
await this.saveSettings();
const { needUpgrade, settings } = await upgradeSettings(this.#settings, SettingsVersion.V2);
this.#settings = settings;
if (needUpgrade) {
await this.saveSettings();
}

const crypto = new PassCrypto();
const count = this.#settings?.profiles.length ?? 0;
Expand All @@ -92,6 +95,10 @@ export default class WordpressPlugin extends Plugin {
profile.password = await crypto.decrypt(enPass.encrypted, enPass.key, enPass.vector);
}
}

AppState.getInstance().markdownParser.set({
html: this.#settings?.enableHtml ?? false
});
}

async saveSettings() {
Expand Down
20 changes: 14 additions & 6 deletions src/plugin-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export interface WordpressPluginSettings {
showWordPressEditConfirm: boolean;

mathJaxOutputType: MathJaxOutputType;

enableHtml: boolean;
}

export const DEFAULT_SETTINGS: WordpressPluginSettings = {
Expand All @@ -71,14 +73,14 @@ export const DEFAULT_SETTINGS: WordpressPluginSettings = {
defaultCommentStatus: CommentStatus.Open,
rememberLastSelectedCategories: true,
showWordPressEditConfirm: false,
mathJaxOutputType: MathJaxOutputType.SVG
mathJaxOutputType: MathJaxOutputType.SVG,
enableHtml: false
}

export async function upgradeSettings(
existingSettings: SafeAny,
to: SettingsVersion,
plugin: WordpressPlugin
): Promise<WordpressPluginSettings> {
to: SettingsVersion
): Promise<{ needUpgrade: boolean, settings: WordpressPluginSettings }> {
console.log(existingSettings, to);
if (isUndefined(existingSettings.version)) {
// V1
Expand Down Expand Up @@ -120,8 +122,14 @@ export async function upgradeSettings(
} else {
newSettings.profiles = [];
}
return newSettings;
return {
needUpgrade: true,
settings: newSettings
};
}
}
return existingSettings;
return {
needUpgrade: false,
settings: existingSettings
};
}
2 changes: 1 addition & 1 deletion src/post-published-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function openPostPublishedModal(
/**
* WordPress post published modal.
*/
export class PostPublishedModal extends Modal {
class PostPublishedModal extends Modal {

constructor(
private readonly plugin: WordpressPlugin,
Expand Down
18 changes: 17 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { WpProfileManageModal } from './wp-profile-manage-modal';
import { MathJaxOutputType } from './plugin-settings';
import { WpProfile } from './wp-profile';
import { setupMarkdownParser } from './utils';
import { AppState } from './app-state';


export class WordpressSettingTab extends PluginSettingTab {
Expand Down Expand Up @@ -38,7 +39,6 @@ export class WordpressSettingTab extends PluginSettingTab {

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

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

new Setting(containerEl)
Expand Down Expand Up @@ -146,6 +146,22 @@ export class WordpressSettingTab extends PluginSettingTab {
text: mathJaxOutputTypeDesc,
cls: 'setting-item-description'
});

new Setting(containerEl)
.setName(t('settings_enableHtml'))
.setDesc(t('settings_enableHtmlDesc'))
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.enableHtml)
.onChange(async (value) => {
this.plugin.settings.enableHtml = value;
await this.plugin.saveSettings();

AppState.getInstance().markdownParser.set({
html: this.plugin.settings.enableHtml
});
}),
);
}

}
2 changes: 1 addition & 1 deletion src/wp-login-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function openLoginModal(
/**
* WordPress login modal with username and password inputs.
*/
export class WpLoginModal extends Modal {
class WpLoginModal extends Modal {

constructor(
private readonly plugin: WordpressPlugin,
Expand Down
2 changes: 1 addition & 1 deletion src/wp-profile-chooser-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function openProfileChooserModal(
/**
* WordPress profiles chooser modal.
*/
export class WpProfileChooserModal extends Modal {
class WpProfileChooserModal extends Modal {

private readonly profiles: WpProfile[];

Expand Down
2 changes: 1 addition & 1 deletion src/wp-profile-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function openProfileModal(
/**
* WordPress profile modal.
*/
export class WpProfileModal extends Modal {
class WpProfileModal extends Modal {

private readonly profileData: WpProfile;

Expand Down
2 changes: 1 addition & 1 deletion src/wp-publish-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function openPublishModal(
/**
* WordPress publish modal.
*/
export class WpPublishModal extends Modal {
class WpPublishModal extends Modal {

constructor(
private readonly plugin: WordpressPlugin,
Expand Down
1 change: 0 additions & 1 deletion src/wp-rest-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export class WpRestClient extends AbstractWordPressClient {
};
})
.catch(error => {
console.log(error);
return {
code: WordPressClientReturnCode.Error,
data: this.plugin.i18n.t('error_invalidUser')
Expand Down

0 comments on commit 2bf0e9f

Please sign in to comment.