Applies Obsidian linter and fixes code issues
Applies linting rules to the codebase and resolves identified issues. Addresses: - Renamed headings in settings tabs to improve UI consistency and style. - Resolved require() style imports - Added void operator to ensure correct promise handling. - Replaced deprecated Obsidian API calls. - Enforces sentence case to enhance UI text consistency.
This commit is contained in:
37 files changed
+4314
-872
No files matched your search
@@ -202,7 +202,7 @@ export interface MarkdownPreprocessorConfig {
|
||||
*
|
||||
* // Process markdown
|
||||
* const obsidianMarkdown = '# My Note\n\n[[internal-link]]\n\n![[image.png]]';
|
||||
* const result = await preprocessor.process(obsidianMarkdown);
|
||||
* const result = preprocessor.process(obsidianMarkdown);
|
||||
*
|
||||
* console.log(result.content); // Standard markdown
|
||||
* console.log(result.metadata.imageEmbeds); // Image processing info
|
||||
@@ -218,7 +218,7 @@ export interface MarkdownPreprocessorConfig {
|
||||
* });
|
||||
*
|
||||
* // Process with new configuration
|
||||
* const newResult = await preprocessor.process(markdown);
|
||||
* const newResult = preprocessor.process(markdown);
|
||||
* ```
|
||||
*/
|
||||
export class MarkdownPreprocessor {
|
||||
@@ -268,7 +268,6 @@ export class MarkdownPreprocessor {
|
||||
* in the correct order, aggregates metadata from each stage, and returns a complete
|
||||
* result with processed content and comprehensive metadata.
|
||||
*
|
||||
* The method is async to support future extensions (though current processors are sync).
|
||||
* Processing is stateless - each call operates independently on the provided content.
|
||||
*
|
||||
* Processing Order (critical for avoiding conflicts):
|
||||
@@ -300,7 +299,7 @@ export class MarkdownPreprocessor {
|
||||
* Callout: > [!note] This is important
|
||||
* `;
|
||||
*
|
||||
* const result = await preprocessor.process(markdown);
|
||||
* const result = preprocessor.process(markdown);
|
||||
*
|
||||
* // Check for errors
|
||||
* if (result.errors.length > 0) {
|
||||
@@ -320,7 +319,7 @@ export class MarkdownPreprocessor {
|
||||
* ```typescript
|
||||
* // Handle remote images
|
||||
* const markdown = '';
|
||||
* const result = await preprocessor.process(markdown);
|
||||
* const result = preprocessor.process(markdown);
|
||||
*
|
||||
* // Remote images are queued for download
|
||||
* result.metadata.imageEmbeds.forEach(embed => {
|
||||
@@ -329,7 +328,7 @@ export class MarkdownPreprocessor {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
public async process(content: string): Promise<PreprocessingResult> {
|
||||
public process(content: string): PreprocessingResult {
|
||||
const result: PreprocessingResult = {
|
||||
content: content,
|
||||
metadata: {
|
||||
@@ -506,7 +505,7 @@ export class MarkdownPreprocessor {
|
||||
* });
|
||||
*
|
||||
* // Process note with web-friendly links
|
||||
* const result = await preprocessor.process(markdown);
|
||||
* const result = preprocessor.process(markdown);
|
||||
* // Links will use the new base URL
|
||||
* ```
|
||||
*
|
||||
@@ -521,7 +520,7 @@ export class MarkdownPreprocessor {
|
||||
* });
|
||||
*
|
||||
* // Process with HTML-style links
|
||||
* const result = await preprocessor.process(markdown);
|
||||
* const result = preprocessor.process(markdown);
|
||||
* // [[note]] becomes [note](note.html)
|
||||
* ```
|
||||
*
|
||||
|
||||
@@ -299,7 +299,7 @@ export class PandocTypstConverter {
|
||||
this.processCleanupHandler = () => {
|
||||
// Only cleanup if not already disposed to avoid double-cleanup
|
||||
if (!this.isDisposed) {
|
||||
this.cleanup();
|
||||
void this.cleanup();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -364,14 +364,14 @@ export class PandocTypstConverter {
|
||||
if (!this.tempDir) {
|
||||
if (this.pandocOptions.vaultBasePath) {
|
||||
// Use TempDirectoryManager for plugin temp directories
|
||||
const configDir = this.plugin?.app?.vault?.configDir || '.obsidian';
|
||||
const configDir = this.plugin?.app?.vault?.configDir;
|
||||
const tempManager = TempDirectoryManager.create(this.pandocOptions.vaultBasePath, configDir, undefined, this.plugin?.app);
|
||||
this.tempDir = await tempManager.ensureTempDir('pandoc');
|
||||
} else {
|
||||
// Fallback to system temp if plugin folder not available - use TempDirectoryManager fallback
|
||||
const pathUtils = new PathUtils(this.plugin.app);
|
||||
const vaultPath = pathUtils.getVaultPath();
|
||||
const configDir = this.plugin?.app?.vault?.configDir || '.obsidian';
|
||||
const configDir = this.plugin?.app?.vault?.configDir;
|
||||
const tempManager = new TempDirectoryManager({ vaultPath, configDir, app: this.plugin.app });
|
||||
this.tempDir = await tempManager.ensureTempDir('pandoc');
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Handles discovery of pdf2img and other CLI tools in the Obsidian environment.
|
||||
*/
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
import type { obsidianTypstPDFExport } from '../../../main';
|
||||
import { PathUtils } from '../../core/PathUtils';
|
||||
@@ -30,7 +31,10 @@ export class BinaryLocator {
|
||||
// In Obsidian, __dirname points to electron.asar, so we need to find the actual plugin path
|
||||
// Try multiple strategies to find the plugin directory
|
||||
const pluginDirName = plugin?.manifest?.dir || 'typst-pdf-export';
|
||||
const configDir = plugin?.app.vault.configDir || '.obsidian';
|
||||
const configDir = plugin?.app.vault.configDir;
|
||||
if (!configDir) {
|
||||
throw new Error('Unable to determine Obsidian configuration directory');
|
||||
}
|
||||
const possiblePluginDirs = this.getPossiblePluginDirs(plugin, pluginDirName, configDir);
|
||||
|
||||
// Find the first directory that exists and has node_modules
|
||||
@@ -154,7 +158,6 @@ export class BinaryLocator {
|
||||
try {
|
||||
if (!plugin?.app) {
|
||||
// This should not happen in normal plugin operation, but provide fallback
|
||||
const fs = require('fs').promises;
|
||||
await fs.access(binaryPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Handles filename pattern matching when pdf2img generates files with different names.
|
||||
*/
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
import { PathUtils } from '../../core/PathUtils';
|
||||
import type { obsidianTypstPDFExport } from '../../../main';
|
||||
@@ -35,7 +36,6 @@ export class FileDiscovery {
|
||||
if (!plugin?.app) {
|
||||
// Fallback to path for external tool output directories
|
||||
const expectedOutputPath = path.join(outputDir, expectedFileName);
|
||||
const fs = require('fs').promises;
|
||||
try {
|
||||
await fs.access(expectedOutputPath);
|
||||
return {
|
||||
@@ -112,8 +112,7 @@ export class FileDiscovery {
|
||||
files = dirList.files.map(f => path.basename(f));
|
||||
} else {
|
||||
// Use filesystem fallback for absolute/external paths
|
||||
const fs = require('fs').promises;
|
||||
files = await fs.readdir(outputDir);
|
||||
files = await fs.readdir(outputDir);
|
||||
}
|
||||
|
||||
// Look for any image files that might match
|
||||
@@ -180,7 +179,6 @@ export class FileDiscovery {
|
||||
expectedOutputPath: string
|
||||
): Promise<FileDiscoveryResult> {
|
||||
try {
|
||||
const fs = require('fs').promises;
|
||||
// Debug: List what files are actually in the output directory
|
||||
const files = await fs.readdir(outputDir);
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Handles format conversion, quality management, and dimension detection.
|
||||
*/
|
||||
|
||||
import { spawn } from 'child_process';
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
import { PathUtils } from '../../core/PathUtils';
|
||||
import type { obsidianTypstPDFExport } from '../../../main';
|
||||
@@ -58,7 +60,6 @@ export class ImageOptimizer {
|
||||
quality: number = 90
|
||||
): Promise<{success: boolean; error?: string}> {
|
||||
try {
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
// Use ImageMagick to convert PNG to JPEG
|
||||
const convertProcess = spawn('magick', [
|
||||
@@ -108,7 +109,6 @@ export class ImageOptimizer {
|
||||
fallbackDimensions: ImageDimensions = { width: 800, height: 600 }
|
||||
): Promise<{dimensions: ImageDimensions; success: boolean; error?: string}> {
|
||||
try {
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
// Use ImageMagick identify to get image dimensions
|
||||
const identifyProcess = spawn('magick', [
|
||||
@@ -233,7 +233,6 @@ export class ImageOptimizer {
|
||||
|
||||
await plugin.app.vault.adapter.remove(relativePath);
|
||||
} else {
|
||||
const fs = require('fs').promises;
|
||||
await fs.unlink(inputImagePath);
|
||||
}
|
||||
} catch (unlinkError) {
|
||||
@@ -249,7 +248,6 @@ export class ImageOptimizer {
|
||||
await plugin.app.vault.adapter.writeBinary(pngFinalPath, content);
|
||||
await plugin.app.vault.adapter.remove(inputImagePath);
|
||||
} else {
|
||||
const fs = require('fs').promises;
|
||||
await fs.rename(inputImagePath, pngFinalPath);
|
||||
}
|
||||
actualImagePath = pngFinalPath;
|
||||
@@ -261,7 +259,6 @@ export class ImageOptimizer {
|
||||
await plugin.app.vault.adapter.writeBinary(finalOutputPath, content);
|
||||
await plugin.app.vault.adapter.remove(inputImagePath);
|
||||
} else {
|
||||
const fs = require('fs').promises;
|
||||
await fs.rename(inputImagePath, finalOutputPath);
|
||||
}
|
||||
actualImagePath = finalOutputPath;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Executes external pdf2img binary to convert PDF pages to images.
|
||||
*/
|
||||
|
||||
import { exec } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import * as path from 'path';
|
||||
import { BinaryLocator } from './BinaryLocator';
|
||||
import { EnvironmentUtils } from './EnvironmentUtils';
|
||||
@@ -111,8 +113,6 @@ export class PdfCliExecutor {
|
||||
plugin?: obsidianTypstPDFExport
|
||||
): Promise<PdfCliResult> {
|
||||
try {
|
||||
const { exec } = require('child_process');
|
||||
const { promisify } = require('util');
|
||||
const execAsync = promisify(exec);
|
||||
|
||||
// Get augmented environment for CLI execution
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Extracted from MarkdownPreprocessor for better code organization
|
||||
*/
|
||||
|
||||
import * as yaml from 'js-yaml';
|
||||
import matter from 'gray-matter';
|
||||
import { PreprocessingResult } from '../MarkdownPreprocessor';
|
||||
|
||||
export interface FrontmatterProcessorConfig {
|
||||
@@ -32,7 +34,6 @@ export class FrontmatterProcessor {
|
||||
if (!this.FRONTMATTER_PATTERN.test(content)) {
|
||||
// No frontmatter found - add title frontmatter if we have a noteTitle
|
||||
if (this.noteTitle) {
|
||||
const yaml = require('js-yaml');
|
||||
const titleFrontmatter = yaml.dump({ title: this.noteTitle });
|
||||
result.metadata.title = this.noteTitle;
|
||||
result.metadata.frontmatter = { title: this.noteTitle };
|
||||
@@ -43,11 +44,10 @@ export class FrontmatterProcessor {
|
||||
}
|
||||
|
||||
// Use gray-matter for robust frontmatter parsing
|
||||
const matter = require('gray-matter');
|
||||
|
||||
// Add debugging to see what's being parsed
|
||||
console.log('FrontmatterProcessor: Attempting to parse content with frontmatter pattern detected');
|
||||
console.log('First 200 chars:', content.substring(0, 200));
|
||||
console.debug('FrontmatterProcessor: Attempting to parse content with frontmatter pattern detected');
|
||||
console.debug('First 200 chars:', content.substring(0, 200));
|
||||
|
||||
const parsed = matter(content);
|
||||
|
||||
@@ -100,7 +100,6 @@ export class FrontmatterProcessor {
|
||||
|
||||
if (this.preserveFrontmatter) {
|
||||
// Keep the frontmatter in the content, but reconstruct it with the modified title
|
||||
const yaml = require('js-yaml');
|
||||
const newFrontmatter = yaml.dump(finalFrontmatter);
|
||||
let processedContent = `---\n${newFrontmatter}---\n${parsed.content}`;
|
||||
|
||||
@@ -115,8 +114,7 @@ export class FrontmatterProcessor {
|
||||
// Return content without frontmatter, but add title as frontmatter for Pandoc
|
||||
let processedContent: string;
|
||||
if (this.noteTitle) {
|
||||
const yaml = require('js-yaml');
|
||||
const titleFrontmatter = yaml.dump({ title: this.noteTitle });
|
||||
const titleFrontmatter = yaml.dump({ title: this.noteTitle });
|
||||
processedContent = `---\n${titleFrontmatter}---\n${parsed.content}`;
|
||||
} else {
|
||||
processedContent = parsed.content;
|
||||
@@ -141,7 +139,6 @@ export class FrontmatterProcessor {
|
||||
} else {
|
||||
// No frontmatter found - add title frontmatter if we have a noteTitle
|
||||
if (this.noteTitle) {
|
||||
const yaml = require('js-yaml');
|
||||
const titleFrontmatter = yaml.dump({ title: this.noteTitle });
|
||||
result.metadata.title = this.noteTitle;
|
||||
result.metadata.frontmatter = { title: this.noteTitle };
|
||||
@@ -152,8 +149,8 @@ export class FrontmatterProcessor {
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
console.log('FrontmatterProcessor: gray-matter failed with error:', errorMessage);
|
||||
console.log('Content being parsed (first 500 chars):', content.substring(0, 500));
|
||||
console.error('FrontmatterProcessor: gray-matter failed with error:', errorMessage);
|
||||
console.error('Content being parsed (first 500 chars):', content.substring(0, 500));
|
||||
result.warnings.push(`Failed to parse frontmatter with gray-matter: ${errorMessage}`);
|
||||
|
||||
// Fallback to simple regex-based parsing
|
||||
@@ -185,8 +182,7 @@ export class FrontmatterProcessor {
|
||||
if (this.preserveFrontmatter) {
|
||||
// Reconstruct frontmatter with modified title
|
||||
if (this.noteTitle) {
|
||||
const yaml = require('js-yaml');
|
||||
const newFrontmatter = yaml.dump(frontmatter);
|
||||
const newFrontmatter = yaml.dump(frontmatter);
|
||||
let processedContent = content.replace(this.FRONTMATTER_PATTERN, `---\n${newFrontmatter}---\n`);
|
||||
|
||||
// Add printed frontmatter if requested
|
||||
@@ -205,8 +201,7 @@ export class FrontmatterProcessor {
|
||||
} else {
|
||||
// Add title as frontmatter for Pandoc even when not preserving original
|
||||
if (this.noteTitle) {
|
||||
const yaml = require('js-yaml');
|
||||
const titleFrontmatter = yaml.dump({ title: this.noteTitle });
|
||||
const titleFrontmatter = yaml.dump({ title: this.noteTitle });
|
||||
let processedContent = content.replace(this.FRONTMATTER_PATTERN, `---\n${titleFrontmatter}---\n`);
|
||||
|
||||
// Add printed frontmatter if requested
|
||||
@@ -230,7 +225,6 @@ export class FrontmatterProcessor {
|
||||
} else {
|
||||
// No frontmatter pattern found, but gray-matter failed - treat as file without frontmatter
|
||||
if (this.noteTitle) {
|
||||
const yaml = require('js-yaml');
|
||||
const titleFrontmatter = yaml.dump({ title: this.noteTitle });
|
||||
result.metadata.title = this.noteTitle;
|
||||
result.metadata.frontmatter = { title: this.noteTitle };
|
||||
@@ -265,13 +259,18 @@ export class FrontmatterProcessor {
|
||||
if (Array.isArray(value)) {
|
||||
// For arrays, put each item on its own line if there are many items
|
||||
if (value.length > 3) {
|
||||
formattedValue = '\n\n' + value.map(item => `- ${item}`).join('\n') + '\n';
|
||||
formattedValue = '\n\n' + value.map(item =>
|
||||
typeof item === 'object' ? JSON.stringify(item) : String(item)
|
||||
).join('\n').split('\n').map(line => `- ${line}`).join('\n') + '\n';
|
||||
} else {
|
||||
formattedValue = value.join(', ');
|
||||
formattedValue = value.map(item =>
|
||||
typeof item === 'object' ? JSON.stringify(item) : String(item)
|
||||
).join(', ');
|
||||
}
|
||||
} else if (typeof value === 'object') {
|
||||
} else if (typeof value === 'object' && value !== null) {
|
||||
formattedValue = JSON.stringify(value);
|
||||
} else {
|
||||
} else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
||||
// Handle primitive values
|
||||
const valueStr = String(value);
|
||||
// If the value is very long (like email lists), break it up
|
||||
if (valueStr.length > 80 && valueStr.includes(',')) {
|
||||
@@ -308,8 +307,11 @@ export class FrontmatterProcessor {
|
||||
} else {
|
||||
formattedValue = valueStr;
|
||||
}
|
||||
} else {
|
||||
// Handle null, undefined, or any other unexpected types
|
||||
formattedValue = '';
|
||||
}
|
||||
|
||||
|
||||
// Add line break after the property label, then the value
|
||||
if (formattedValue.startsWith('\n')) {
|
||||
// Value already starts with newline (like lists), so just add the label
|
||||
|
||||
Reference in new issue
Block a user