feat(settings): restore lost settings and enhance plugin configuration
- Restore settings lost during refactor from commit 175fad5b
- Add ImageMagick path configuration with dependency checking
- Implement proper folder suggestion using AbstractInputSuggest
- Convert page format and orientation to dropdown selections
- Add template dropdown with dynamic loading from TemplateManager
- Convert font selections to dropdowns populated from `typst fonts`
- Split margins into individual top/bottom/left/right fields with CM units
- Enhance dependency checker to validate Pandoc, Typst, and ImageMagick
- Remove heading and small font size options, retain body font size only
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 file changed
+305
-55
@@ -13,7 +13,8 @@ import {
|
|||||||
Notice,
|
Notice,
|
||||||
Menu,
|
Menu,
|
||||||
MarkdownView,
|
MarkdownView,
|
||||||
Editor
|
Editor,
|
||||||
|
AbstractInputSuggest
|
||||||
} from 'obsidian';
|
} from 'obsidian';
|
||||||
|
|
||||||
import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS, ExportFormat } from './src/core/settings';
|
import { obsidianTypstPDFExportSettings, DEFAULT_SETTINGS, ExportFormat } from './src/core/settings';
|
||||||
@@ -27,7 +28,7 @@ import * as fs from 'fs';
|
|||||||
export class obsidianTypstPDFExport extends Plugin {
|
export class obsidianTypstPDFExport extends Plugin {
|
||||||
settings: obsidianTypstPDFExportSettings;
|
settings: obsidianTypstPDFExportSettings;
|
||||||
private converter: PandocTypstConverter;
|
private converter: PandocTypstConverter;
|
||||||
private templateManager: TemplateManager;
|
templateManager: TemplateManager;
|
||||||
private currentExportController: AbortController | null = null;
|
private currentExportController: AbortController | null = null;
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
@@ -263,6 +264,9 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
* Export a file with specific configuration
|
* Export a file with specific configuration
|
||||||
*/
|
*/
|
||||||
private async exportFileWithConfig(file: TFile, config: ExportConfig): Promise<void> {
|
private async exportFileWithConfig(file: TFile, config: ExportConfig): Promise<void> {
|
||||||
|
// Get plugin directory and vault base path
|
||||||
|
const vaultPath = (this.app.vault.adapter as any).basePath;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create abort controller for cancellation
|
// Create abort controller for cancellation
|
||||||
this.currentExportController = new AbortController();
|
this.currentExportController = new AbortController();
|
||||||
@@ -272,9 +276,6 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
|
|
||||||
// Read file content
|
// Read file content
|
||||||
const content = await this.app.vault.read(file);
|
const content = await this.app.vault.read(file);
|
||||||
|
|
||||||
// Get plugin directory and vault base path
|
|
||||||
const vaultPath = (this.app.vault.adapter as any).basePath;
|
|
||||||
const pluginDir = path.join(vaultPath, '.obsidian', 'plugins', 'obsidian-typst-pdf-export');
|
const pluginDir = path.join(vaultPath, '.obsidian', 'plugins', 'obsidian-typst-pdf-export');
|
||||||
|
|
||||||
// Create temp directory for processing
|
// Create temp directory for processing
|
||||||
@@ -453,13 +454,14 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* Show dependency status modal
|
* Show dependency status modal
|
||||||
*/
|
*/
|
||||||
private async showDependencyStatus(): Promise<void> {
|
async showDependencyStatus(): Promise<void> {
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const { promisify } = require('util');
|
const { promisify } = require('util');
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
let pandocVersion = 'Not found';
|
let pandocVersion = 'Not found';
|
||||||
let typstVersion = 'Not found';
|
let typstVersion = 'Not found';
|
||||||
|
let imagemagickVersion = 'Not found';
|
||||||
|
|
||||||
// Check Pandoc
|
// Check Pandoc
|
||||||
try {
|
try {
|
||||||
@@ -485,16 +487,34 @@ export class obsidianTypstPDFExport extends Plugin {
|
|||||||
console.error('Typst check failed:', error);
|
console.error('Typst check failed:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check ImageMagick/convert
|
||||||
|
try {
|
||||||
|
const convertPath = this.settings.executablePaths.imagemagickPath || 'convert';
|
||||||
|
const { stdout } = await execAsync(`${convertPath} --version`);
|
||||||
|
const match = stdout.match(/ImageMagick\s+([\d.-]+)/);
|
||||||
|
if (match) {
|
||||||
|
imagemagickVersion = match[1];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('ImageMagick check failed:', error);
|
||||||
|
}
|
||||||
|
|
||||||
// Show results in a notice
|
// Show results in a notice
|
||||||
|
const missingDeps = [];
|
||||||
|
if (pandocVersion === 'Not found') missingDeps.push('Pandoc');
|
||||||
|
if (typstVersion === 'Not found') missingDeps.push('Typst');
|
||||||
|
if (imagemagickVersion === 'Not found') missingDeps.push('ImageMagick');
|
||||||
|
|
||||||
const message = `Dependency Status:
|
const message = `Dependency Status:
|
||||||
Pandoc: ${pandocVersion}
|
Pandoc: ${pandocVersion}
|
||||||
Typst: ${typstVersion}
|
Typst: ${typstVersion}
|
||||||
|
ImageMagick: ${imagemagickVersion}
|
||||||
|
|
||||||
${pandocVersion === 'Not found' || typstVersion === 'Not found' ?
|
${missingDeps.length > 0 ?
|
||||||
'Missing dependencies! Please install them and check the paths in settings.' :
|
`Missing dependencies: ${missingDeps.join(', ')}. Please install them and check the paths in settings.` :
|
||||||
'All dependencies found!'}`;
|
'All dependencies found!'}`;
|
||||||
|
|
||||||
new Notice(message, 10000); // Show for 10 seconds
|
new Notice(message, 12000); // Show for 12 seconds (longer due to more content)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async checkDependenciesAsync(): Promise<void> {
|
private async checkDependenciesAsync(): Promise<void> {
|
||||||
@@ -528,6 +548,13 @@ ${pandocVersion === 'Not found' || typstVersion === 'Not found' ?
|
|||||||
missingDeps.push('Typst');
|
missingDeps.push('Typst');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check ImageMagick
|
||||||
|
try {
|
||||||
|
execSync('convert --version', { encoding: 'utf8', env });
|
||||||
|
} catch {
|
||||||
|
missingDeps.push('ImageMagick');
|
||||||
|
}
|
||||||
|
|
||||||
// Only show notice if dependencies are missing
|
// Only show notice if dependencies are missing
|
||||||
if (missingDeps.length > 0) {
|
if (missingDeps.length > 0) {
|
||||||
new Notice(
|
new Notice(
|
||||||
@@ -794,6 +821,34 @@ ${pandocVersion === 'Not found' || typstVersion === 'Not found' ?
|
|||||||
/**
|
/**
|
||||||
* Settings Tab
|
* Settings Tab
|
||||||
*/
|
*/
|
||||||
|
class FolderSuggest extends AbstractInputSuggest<string> {
|
||||||
|
private folders: string[];
|
||||||
|
private inputElement: HTMLInputElement;
|
||||||
|
|
||||||
|
constructor(app: App, inputEl: HTMLInputElement) {
|
||||||
|
super(app, inputEl);
|
||||||
|
this.inputElement = inputEl;
|
||||||
|
this.folders = ["/"].concat(this.app.vault.getAllFolders().map(folder => folder.path));
|
||||||
|
}
|
||||||
|
|
||||||
|
getSuggestions(inputStr: string): string[] {
|
||||||
|
const inputLower = inputStr.toLowerCase();
|
||||||
|
return this.folders.filter(folder =>
|
||||||
|
folder.toLowerCase().includes(inputLower)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderSuggestion(folder: string, el: HTMLElement): void {
|
||||||
|
el.createEl("div", { text: folder });
|
||||||
|
}
|
||||||
|
|
||||||
|
selectSuggestion(folder: string): void {
|
||||||
|
this.inputElement.value = folder;
|
||||||
|
this.inputElement.dispatchEvent(new Event('input'));
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
||||||
plugin: obsidianTypstPDFExport;
|
plugin: obsidianTypstPDFExport;
|
||||||
|
|
||||||
@@ -817,6 +872,9 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
|||||||
// Typography defaults section
|
// Typography defaults section
|
||||||
this.createTypographyDefaultsSection(containerEl);
|
this.createTypographyDefaultsSection(containerEl);
|
||||||
|
|
||||||
|
// Page setup section
|
||||||
|
this.createPageSetupSection(containerEl);
|
||||||
|
|
||||||
// Behavior section
|
// Behavior section
|
||||||
this.createBehaviorSection(containerEl);
|
this.createBehaviorSection(containerEl);
|
||||||
}
|
}
|
||||||
@@ -824,6 +882,17 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
|||||||
private createExecutablePathsSection(containerEl: HTMLElement): void {
|
private createExecutablePathsSection(containerEl: HTMLElement): void {
|
||||||
containerEl.createEl('h3', { text: 'Executable Paths' });
|
containerEl.createEl('h3', { text: 'Executable Paths' });
|
||||||
|
|
||||||
|
// Add dependency check button
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Dependencies')
|
||||||
|
.setDesc('Check the status of external dependencies')
|
||||||
|
.addButton(button => button
|
||||||
|
.setButtonText('Check Dependencies')
|
||||||
|
.setCta()
|
||||||
|
.onClick(async () => {
|
||||||
|
await this.plugin.showDependencyStatus();
|
||||||
|
}));
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Pandoc path')
|
.setName('Pandoc path')
|
||||||
.setDesc('Path to pandoc executable (leave empty to use system PATH)')
|
.setDesc('Path to pandoc executable (leave empty to use system PATH)')
|
||||||
@@ -845,6 +914,31 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
|||||||
this.plugin.settings.typstPath = value;
|
this.plugin.settings.typstPath = value;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('ImageMagick convert path')
|
||||||
|
.setDesc('Path to ImageMagick convert executable (leave empty to use system PATH)')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('convert')
|
||||||
|
.setValue(this.plugin.settings.executablePaths.imagemagickPath)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.executablePaths.imagemagickPath = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}));
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Additional system paths')
|
||||||
|
.setDesc('Additional paths to search for executables (comma-separated)')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('/opt/homebrew/bin, /usr/local/bin')
|
||||||
|
.setValue(this.plugin.settings.executablePaths.additionalPaths.join(', '))
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.executablePaths.additionalPaths = value
|
||||||
|
.split(',')
|
||||||
|
.map(p => p.trim())
|
||||||
|
.filter(p => p.length > 0);
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private createExportDefaultsSection(containerEl: HTMLElement): void {
|
private createExportDefaultsSection(containerEl: HTMLElement): void {
|
||||||
@@ -853,13 +947,31 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
|||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Default template')
|
.setName('Default template')
|
||||||
.setDesc('Default Typst template for exports')
|
.setDesc('Default Typst template for exports')
|
||||||
.addText(text => text
|
.addDropdown(async (dropdown) => {
|
||||||
.setPlaceholder('default')
|
try {
|
||||||
.setValue(this.plugin.settings.exportDefaults.template)
|
const templates = await this.plugin.templateManager.getAvailableTemplates();
|
||||||
.onChange(async (value) => {
|
// Filter out universal-wrapper.pandoc.typ as requested
|
||||||
this.plugin.settings.exportDefaults.template = value;
|
const filteredTemplates = templates.filter(template =>
|
||||||
await this.plugin.saveSettings();
|
template !== 'universal-wrapper.pandoc.typ'
|
||||||
}));
|
);
|
||||||
|
|
||||||
|
filteredTemplates.forEach(template => {
|
||||||
|
dropdown.addOption(template, template);
|
||||||
|
});
|
||||||
|
|
||||||
|
dropdown
|
||||||
|
.setValue(this.plugin.settings.exportDefaults.template)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.exportDefaults.template = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load templates:', error);
|
||||||
|
// Fallback to text input
|
||||||
|
dropdown.addOption('default.typ', 'default.typ');
|
||||||
|
dropdown.setValue(this.plugin.settings.exportDefaults.template);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Default format')
|
.setName('Default format')
|
||||||
@@ -876,13 +988,17 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
|||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Output folder')
|
.setName('Output folder')
|
||||||
.setDesc('Default folder for exported PDFs (relative to vault root)')
|
.setDesc('Default folder for exported PDFs (relative to vault root)')
|
||||||
.addText(text => text
|
.addText(text => {
|
||||||
.setPlaceholder('exports')
|
text
|
||||||
.setValue(this.plugin.settings.outputFolder)
|
.setPlaceholder('exports')
|
||||||
.onChange(async (value) => {
|
.setValue(this.plugin.settings.outputFolder)
|
||||||
this.plugin.settings.outputFolder = value;
|
.onChange(async (value) => {
|
||||||
await this.plugin.saveSettings();
|
this.plugin.settings.outputFolder = value;
|
||||||
}));
|
await this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
|
||||||
|
new FolderSuggest(this.app, text.inputEl);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private createTypographyDefaultsSection(containerEl: HTMLElement): void {
|
private createTypographyDefaultsSection(containerEl: HTMLElement): void {
|
||||||
@@ -891,32 +1007,68 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
|||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Body font')
|
.setName('Body font')
|
||||||
.setDesc('Default font for body text')
|
.setDesc('Default font for body text')
|
||||||
.addText(text => text
|
.addDropdown(async (dropdown) => {
|
||||||
.setValue(this.plugin.settings.typography.fonts.body)
|
try {
|
||||||
.onChange(async (value) => {
|
const fonts = await this.getAvailableFonts();
|
||||||
this.plugin.settings.typography.fonts.body = value;
|
fonts.forEach(font => {
|
||||||
await this.plugin.saveSettings();
|
dropdown.addOption(font, font);
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
dropdown
|
||||||
|
.setValue(this.plugin.settings.typography.fonts.body)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.typography.fonts.body = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load fonts:', error);
|
||||||
|
dropdown.addOption(this.plugin.settings.typography.fonts.body, this.plugin.settings.typography.fonts.body);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Heading font')
|
.setName('Heading font')
|
||||||
.setDesc('Default font for headings')
|
.setDesc('Default font for headings')
|
||||||
.addText(text => text
|
.addDropdown(async (dropdown) => {
|
||||||
.setValue(this.plugin.settings.typography.fonts.heading)
|
try {
|
||||||
.onChange(async (value) => {
|
const fonts = await this.getAvailableFonts();
|
||||||
this.plugin.settings.typography.fonts.heading = value;
|
fonts.forEach(font => {
|
||||||
await this.plugin.saveSettings();
|
dropdown.addOption(font, font);
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
dropdown
|
||||||
|
.setValue(this.plugin.settings.typography.fonts.heading)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.typography.fonts.heading = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load fonts:', error);
|
||||||
|
dropdown.addOption(this.plugin.settings.typography.fonts.heading, this.plugin.settings.typography.fonts.heading);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Monospace font')
|
.setName('Monospace font')
|
||||||
.setDesc('Default font for code and monospace text')
|
.setDesc('Default font for code and monospace text')
|
||||||
.addText(text => text
|
.addDropdown(async (dropdown) => {
|
||||||
.setValue(this.plugin.settings.typography.fonts.monospace)
|
try {
|
||||||
.onChange(async (value) => {
|
const fonts = await this.getAvailableFonts();
|
||||||
this.plugin.settings.typography.fonts.monospace = value;
|
fonts.forEach(font => {
|
||||||
await this.plugin.saveSettings();
|
dropdown.addOption(font, font);
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
dropdown
|
||||||
|
.setValue(this.plugin.settings.typography.fonts.monospace)
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.typography.fonts.monospace = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load fonts:', error);
|
||||||
|
dropdown.addOption(this.plugin.settings.typography.fonts.monospace, this.plugin.settings.typography.fonts.monospace);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Body font size')
|
.setName('Body font size')
|
||||||
@@ -929,28 +1081,79 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
|||||||
this.plugin.settings.typography.fontSizes.body = value;
|
this.plugin.settings.typography.fontSizes.body = value;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private createPageSetupSection(containerEl: HTMLElement): void {
|
||||||
|
containerEl.createEl('h3', { text: 'Page Setup' });
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Heading font size')
|
.setName('Page size')
|
||||||
.setDesc('Default font size for headings (in points)')
|
.setDesc('Paper size for PDF output')
|
||||||
.addSlider(slider => slider
|
.addDropdown(dropdown => dropdown
|
||||||
.setLimits(10, 24, 0.5)
|
.addOption('a4', 'A4')
|
||||||
.setValue(this.plugin.settings.typography.fontSizes.heading)
|
.addOption('a5', 'A5')
|
||||||
.setDynamicTooltip()
|
.addOption('letter', 'US Letter')
|
||||||
|
.addOption('legal', 'US Legal')
|
||||||
|
.addOption('a3', 'A3')
|
||||||
|
.setValue(this.plugin.settings.pageSetup.size)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.typography.fontSizes.heading = value;
|
this.plugin.settings.pageSetup.size = value;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName('Small font size')
|
.setName('Page orientation')
|
||||||
.setDesc('Default font size for small text (in points)')
|
.setDesc('Page orientation')
|
||||||
.addSlider(slider => slider
|
.addDropdown(dropdown => dropdown
|
||||||
.setLimits(6, 12, 0.5)
|
.addOption('portrait', 'Portrait')
|
||||||
.setValue(this.plugin.settings.typography.fontSizes.small)
|
.addOption('landscape', 'Landscape')
|
||||||
.setDynamicTooltip()
|
.setValue(this.plugin.settings.pageSetup.orientation)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.typography.fontSizes.small = value;
|
this.plugin.settings.pageSetup.orientation = value as 'portrait' | 'landscape';
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}));
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Top margin')
|
||||||
|
.setDesc('Top page margin in centimeters')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('2.54')
|
||||||
|
.setValue(this.formatSingleMarginForDisplay(this.plugin.settings.pageSetup.margins.top))
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.pageSetup.margins.top = this.parseMarginValue(value, 72);
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}));
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Bottom margin')
|
||||||
|
.setDesc('Bottom page margin in centimeters')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('2.54')
|
||||||
|
.setValue(this.formatSingleMarginForDisplay(this.plugin.settings.pageSetup.margins.bottom))
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.pageSetup.margins.bottom = this.parseMarginValue(value, 72);
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}));
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Left margin')
|
||||||
|
.setDesc('Left page margin in centimeters')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('2.54')
|
||||||
|
.setValue(this.formatSingleMarginForDisplay(this.plugin.settings.pageSetup.margins.left))
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.pageSetup.margins.left = this.parseMarginValue(value, 72);
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
}));
|
||||||
|
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName('Right margin')
|
||||||
|
.setDesc('Right page margin in centimeters')
|
||||||
|
.addText(text => text
|
||||||
|
.setPlaceholder('2.54')
|
||||||
|
.setValue(this.formatSingleMarginForDisplay(this.plugin.settings.pageSetup.margins.right))
|
||||||
|
.onChange(async (value) => {
|
||||||
|
this.plugin.settings.pageSetup.margins.right = this.parseMarginValue(value, 72);
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -988,6 +1191,53 @@ class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
|
|||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper methods for fonts
|
||||||
|
private async getAvailableFonts(): Promise<string[]> {
|
||||||
|
try {
|
||||||
|
const { exec } = require('child_process');
|
||||||
|
const { promisify } = require('util');
|
||||||
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
|
const typstPath = this.plugin.settings.typstPath || 'typst';
|
||||||
|
const { stdout } = await execAsync(`${typstPath} fonts`);
|
||||||
|
|
||||||
|
const fonts = stdout
|
||||||
|
.split('\n')
|
||||||
|
.map((line: string) => line.trim())
|
||||||
|
.filter((line: string) => line.length > 0)
|
||||||
|
.sort();
|
||||||
|
|
||||||
|
return fonts;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to get fonts from typst:', error);
|
||||||
|
// Return common fallback fonts
|
||||||
|
return [
|
||||||
|
'Times New Roman',
|
||||||
|
'Arial',
|
||||||
|
'Helvetica',
|
||||||
|
'Georgia',
|
||||||
|
'Courier New',
|
||||||
|
'Monaco',
|
||||||
|
'SF Pro Text',
|
||||||
|
'SF Mono',
|
||||||
|
'Concourse OT',
|
||||||
|
'UbuntuMono Nerd Font Mono'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper methods for margin conversion
|
||||||
|
private formatSingleMarginForDisplay(marginPoints: number): string {
|
||||||
|
// Convert from points to CM (1 point = 0.035278 cm)
|
||||||
|
const marginCm = (marginPoints * 0.035278).toFixed(2);
|
||||||
|
return marginCm;
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseMarginValue(value: string, defaultPoints: number): number {
|
||||||
|
const cm = parseFloat(value.trim());
|
||||||
|
return isNaN(cm) ? defaultPoints : cm / 0.035278; // Convert CM to points
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default export for Obsidian
|
// Default export for Obsidian
|
||||||
|
|||||||
Reference in new issue
Block a user