fix: resolve horizontal rule YAML parsing conflicts
Fixes issue where horizontal rules (---) in markdown were causing "Error parsing YAML metadata" when exporting to PDF via Pandoc. Changes: - Add HorizontalRuleProcessor to transform --- to *** before Pandoc - Preserve YAML frontmatter by detecting and skipping frontmatter sections - Add horizontalrule definition to all Typst templates for Pandoc compatibility - Update universal wrapper to import horizontalrule from templates - Clean up PandocTypstConverter formatting and remove debug output The processor now detects YAML frontmatter patterns and only transforms horizontal rules in content body, preventing destruction of document frontmatter while resolving Pandoc parsing conflicts. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
9 files changed
+337
-209
No files matched your search
@@ -94,42 +94,42 @@ export class PandocTypstConverter {
|
||||
* Convert markdown content to PDF
|
||||
*/
|
||||
async convertMarkdownToPDF(
|
||||
content: string,
|
||||
outputPath: string,
|
||||
options: Partial<PandocOptions> = {},
|
||||
progressCallback?: ProgressCallback
|
||||
): Promise<ConversionResult> {
|
||||
content: string,
|
||||
outputPath: string,
|
||||
options: Partial<PandocOptions> = {},
|
||||
progressCallback?: ProgressCallback
|
||||
): Promise<ConversionResult> {
|
||||
try {
|
||||
progressCallback?.('Preparing markdown content...', 10);
|
||||
|
||||
// Create temporary markdown file
|
||||
await this.ensureTempDirectory();
|
||||
const tempInputPath = path.join(this.tempDir!, `temp-${Date.now()}.md`);
|
||||
|
||||
await fsPromises.writeFile(tempInputPath, content, 'utf-8');
|
||||
|
||||
// Merge options
|
||||
this.pandocOptions = { ...this.pandocOptions, ...options };
|
||||
|
||||
// Convert using the file-based method
|
||||
const result = await this.convertToPDF(tempInputPath, outputPath, progressCallback);
|
||||
|
||||
// Cleanup temp file
|
||||
try {
|
||||
progressCallback?.('Preparing markdown content...', 10);
|
||||
|
||||
// Create temporary markdown file
|
||||
await this.ensureTempDirectory();
|
||||
const tempInputPath = path.join(this.tempDir!, `temp-${Date.now()}.md`);
|
||||
|
||||
await fsPromises.writeFile(tempInputPath, content, 'utf-8');
|
||||
|
||||
// Merge options
|
||||
this.pandocOptions = { ...this.pandocOptions, ...options };
|
||||
|
||||
// Convert using the file-based method
|
||||
const result = await this.convertToPDF(tempInputPath, outputPath, progressCallback);
|
||||
|
||||
// Cleanup temp file
|
||||
try {
|
||||
await fsPromises.unlink(tempInputPath);
|
||||
} catch (error) {
|
||||
console.warn('Failed to cleanup temp file:', error);
|
||||
}
|
||||
|
||||
return result;
|
||||
await fsPromises.unlink(tempInputPath);
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
success: false,
|
||||
error: `Conversion failed: ${errorMessage}`
|
||||
};
|
||||
console.warn('Failed to cleanup temp file:', error);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
success: false,
|
||||
error: `Conversion failed: ${errorMessage}`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up cleanup handlers for temporary files
|
||||
|
||||
Reference in new issue
Block a user