Skip to content

Commit

Permalink
🐛 fix Can't edit custom command.
Browse files Browse the repository at this point in the history
  • Loading branch information
mokeyish committed May 12, 2022
1 parent 1b47102 commit eb2ef66
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 335 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-enhancing-export",
"name": "Obsidian Enhancing Export",
"version": "1.0.4",
"version": "1.0.5",
"minAppVersion": "0.12.0",
"description": "This is a enhancing export plugin for Obsidian. It allows to export to formats like Html, DOCX, ePub and PDF or Markdown(Hugo) etc.",
"author": "YISH",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-enhancing-export",
"version": "1.0.4",
"version": "1.0.5",
"description": "This is a enhancing export plugin for Obsidian. It allows to export to formats like Html, DOCX, ePub and PDF or Markdown(Hugo) etc.",
"main": "main.js",
"scripts": {
Expand Down
30 changes: 20 additions & 10 deletions src/export_command_templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default {
type: 'pandoc',
arguments:
'-f markdown --resource-path="${currentDir}" --self-contained --metadata title="${currentFileName}" -s -o "${outputPath}" -t html',
customArguments: '--mathjax="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg-full.js"',
customArguments:
'--mathjax="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg-full.js"',
extension: '.html',
},
'PDF': {
Expand All @@ -48,55 +49,64 @@ export default {
'Word (.docx)': {
name: 'Word (.docx)',
type: 'pandoc',
arguments: '-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t docx',
arguments:
'-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t docx',
extension: '.docx',
},
'OpenOffice': {
name: 'OpenOffice',
type: 'pandoc',
arguments: '-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t odt',
arguments:
'-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t odt',
extension: '.odt',
},
'RTF': {
name: 'RTF',
type: 'pandoc',
arguments: '-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t rtf',
arguments:
'-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t rtf',
extension: '.rtf',
},
'Epub': {
name: 'Epub',
type: 'pandoc',
arguments: '-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t epub',
arguments:
'-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t epub',
extension: '.epub',
},
'Latex': {
name: 'Latex',
type: 'pandoc',
arguments: '-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t latex',
arguments:
'-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t latex',
extension: '.latex',
},
'Media Wiki': {
name: 'Media Wiki',
type: 'pandoc',
arguments: '-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t mediawiki',
arguments:
'-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t mediawiki',
extension: '.mediawiki',
},
'reStructuredText': {
name: 'reStructuredText',
type: 'pandoc',
arguments: '-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t rst',
arguments:
'-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t rst',
extension: '.rst',
},
'Textile': {
name: 'Textile',
type: 'pandoc',
arguments: '-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t textile',
arguments:
'-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t textile',
extension: '.textile',
},
'OPML': {
name: 'OPML',
type: 'pandoc',
arguments: '-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t opml',
arguments:
'-f markdown --resource-path="${currentDir}" -s -o "${outputPath}" -t opml',
extension: '.opml',
},
'Custom': {
Expand Down
2 changes: 1 addition & 1 deletion src/lua.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const files = {
'url.lua': url,
'polyfill.lua': polyfill,
'markdown.lua': markdown,
'markdown+hugo.lua': markdown_hugo
'markdown+hugo.lua': markdown_hugo,
};

export default files;
12 changes: 8 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import luaScripts from './lua';
import * as fsp from 'fs/promises';
import { App, Menu, Plugin, PluginManifest, TFile } from 'obsidian';
import { UniversalExportPluginSettings, DEFAULT_SETTINGS } from './settings';
import { ExportDialog } from './ui/export_modal';
import { ExportSettingTab } from './ui/setting_tab';
import lang, { Lang } from './lang';


export default class UniversalExportPlugin extends Plugin {
settings: UniversalExportPluginSettings;
lang: Lang;
Expand Down Expand Up @@ -49,7 +47,11 @@ export default class UniversalExportPlugin extends Plugin {
}

public async loadSettings(): Promise<void> {
this.settings = Object.assign({}, JSON.parse(JSON.stringify(DEFAULT_SETTINGS)), await this.loadData());
this.settings = Object.assign(
{},
JSON.parse(JSON.stringify(DEFAULT_SETTINGS)),
await this.loadData()
);
if (this.settings.version !== this.manifest.version) {
await this.saveLuaScripts();
this.settings.version = this.manifest.version;
Expand All @@ -66,7 +68,9 @@ export default class UniversalExportPlugin extends Plugin {
const { adapter } = this.app.vault;
const luaDir = `${this.manifest.dir}/lua`;
await adapter.mkdir(luaDir);
for (const luaScript of Object.keys(luaScripts) as Array<keyof typeof luaScripts>) {
for (const luaScript of Object.keys(luaScripts) as Array<
keyof typeof luaScripts
>) {
const luaFile = `${luaDir}/${luaScript}`;
await adapter.writeBinary(luaFile, luaScripts[luaScript]);
}
Expand Down
11 changes: 8 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export interface Variables {

export type PlatformValue<T> = { [k in typeof platform]?: T };

export function setPlatformValue<T>(obj: { [k in typeof platform]?: T }, value: T): { [k in typeof platform]?: T } {
export function setPlatformValue<T>(
obj: { [k in typeof platform]?: T },
value: T
): { [k in typeof platform]?: T } {
if (typeof value === 'string' && value.trim() === '') {
value = undefined;
}
Expand All @@ -47,7 +50,7 @@ export function getPlatformValue<T>(obj: { [k in typeof platform]?: T }): T {
}

export interface UniversalExportPluginSettings {
version?: string,
version?: string;
pandocPath?: PlatformValue<string>;
showOverwriteConfirmation?: boolean;
defaultExportDirectoryMode: 'Auto' | 'Same' | 'Custom';
Expand Down Expand Up @@ -90,7 +93,9 @@ export interface CustomExportSetting extends CommonExportSetting {
export type ExportSetting = PandocExportSetting | CustomExportSetting;

export const DEFAULT_SETTINGS: UniversalExportPluginSettings = {
items: Object.values(export_command_templates).filter(o => o.type !== 'custom'),
items: Object.values(export_command_templates).filter(
o => o.type !== 'custom'
),
pandocPath: undefined,
defaultExportDirectoryMode: 'Auto',
openExportedFile: true,
Expand Down
2 changes: 1 addition & 1 deletion src/shims-lua.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module '*.lua' {
const lua: Uint8Array;
export default lua;
}
}
36 changes: 26 additions & 10 deletions src/ui/add_new_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export class AddNewModal extends Modal {
get lang() {
return this.settingTab.lang;
}
constructor(app: App, settingTab: ExportSettingTab, callback: (setting: ExportSetting) => void) {
constructor(
app: App,
settingTab: ExportSettingTab,
callback: (setting: ExportSetting) => void
) {
super(app);
this.settingTab = settingTab;
this.callback = callback;
Expand All @@ -26,7 +30,11 @@ export class AddNewModal extends Modal {
let nameSetting: Setting;

new Setting(contentEl).setName(lang.template).addDropdown(cb => {
cb.addOptions(Object.fromEntries(Object.values(export_command_templates).map(o => [o.name, o.name])))
cb.addOptions(
Object.fromEntries(
Object.values(export_command_templates).map(o => [o.name, o.name])
)
)
.setValue(tplName)
.onChange(v => {
tplName = v;
Expand All @@ -40,14 +48,22 @@ export class AddNewModal extends Modal {
cb.setValue(name).onChange(v => (name = v));
});

contentEl.createEl('div', { cls: ['modal-button-container'], parent: contentEl }, el => {
el.createEl('button', { text: lang.add, cls: ['mod-cta'], parent: el }).onclick = async () => {
tpl = JSON.parse(JSON.stringify(export_command_templates[tplName]));
tpl.name = name;
callback(tpl);
this.close();
};
});
contentEl.createEl(
'div',
{ cls: ['modal-button-container'], parent: contentEl },
el => {
el.createEl('button', {
text: lang.add,
cls: ['mod-cta'],
parent: el,
}).onclick = async () => {
tpl = JSON.parse(JSON.stringify(export_command_templates[tplName]));
tpl.name = name;
callback(tpl);
this.close();
};
}
);
}

onClose() {
Expand Down
Loading

0 comments on commit eb2ef66

Please sign in to comment.