vimd 0.3.16 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +27 -18
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +26 -13
- package/dist/config/defaults.js +1 -1
- package/dist/core/converter.js +1 -1
- package/dist/core/pandoc-detector.d.ts +6 -2
- package/dist/core/pandoc-detector.d.ts.map +1 -1
- package/dist/core/pandoc-detector.js +25 -11
- package/dist/core/parser/pandoc-parser.d.ts +18 -6
- package/dist/core/parser/pandoc-parser.d.ts.map +1 -1
- package/dist/core/parser/pandoc-parser.js +17 -9
- package/dist/core/parser/parser-factory.d.ts +3 -1
- package/dist/core/parser/parser-factory.d.ts.map +1 -1
- package/dist/core/parser/parser-factory.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -218,6 +218,26 @@ export default {
|
|
|
218
218
|
};
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
+
### LaTeX ドキュメントサポート
|
|
222
|
+
|
|
223
|
+
vimd は `.tex` ファイルのプレビューに対応しています(v0.4.0以降)。
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
# LaTeX ファイルのライブプレビュー
|
|
227
|
+
vimd dev thesis.tex
|
|
228
|
+
|
|
229
|
+
# LaTeX ファイルを HTML に変換
|
|
230
|
+
vimd build thesis.tex
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
LaTeX ファイルは自動的に検出され、pandoc を使用して変換されます。
|
|
234
|
+
|
|
235
|
+
**対応する拡張子**:
|
|
236
|
+
- `.tex`
|
|
237
|
+
- `.latex`
|
|
238
|
+
|
|
239
|
+
**注意**: LaTeX プレビューには pandoc が必須です。pandoc がインストールされていない場合、インストールガイドが表示されます。
|
|
240
|
+
|
|
221
241
|
---
|
|
222
242
|
|
|
223
243
|
## Why vimd?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build.ts"],"names":[],"mappings":"AAkBA,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CAuEf"}
|
|
@@ -6,6 +6,13 @@ import { ParserFactory } from '../../core/parser/index.js';
|
|
|
6
6
|
import { Logger } from '../../utils/logger.js';
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import fs from 'fs-extra';
|
|
9
|
+
/**
|
|
10
|
+
* Check if the file is a LaTeX file based on extension.
|
|
11
|
+
*/
|
|
12
|
+
function isLatexFile(filePath) {
|
|
13
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
14
|
+
return ext === '.tex' || ext === '.latex';
|
|
15
|
+
}
|
|
9
16
|
export async function buildCommand(filePath, options) {
|
|
10
17
|
try {
|
|
11
18
|
Logger.info('Building HTML...');
|
|
@@ -16,40 +23,42 @@ export async function buildCommand(filePath, options) {
|
|
|
16
23
|
config.theme = options.theme;
|
|
17
24
|
}
|
|
18
25
|
Logger.info(`Theme: ${config.theme}`);
|
|
19
|
-
// 2.
|
|
20
|
-
const parserType = options.fast ? 'markdown-it' : config.buildParser;
|
|
21
|
-
Logger.info(`Parser: ${parserType}`);
|
|
22
|
-
// 3. Check pandoc installation only if pandoc parser is selected
|
|
23
|
-
if (parserType === 'pandoc') {
|
|
24
|
-
PandocDetector.ensureInstalled();
|
|
25
|
-
}
|
|
26
|
-
// 4. Check file exists
|
|
26
|
+
// 2. Check file exists first (needed for extension detection)
|
|
27
27
|
const absolutePath = path.resolve(filePath);
|
|
28
28
|
if (!(await fs.pathExists(absolutePath))) {
|
|
29
29
|
Logger.error(`File not found: ${filePath}`);
|
|
30
30
|
process.exit(1);
|
|
31
31
|
}
|
|
32
|
-
//
|
|
32
|
+
// 3. Detect file type and determine parser/format
|
|
33
|
+
const isLatex = isLatexFile(filePath);
|
|
34
|
+
const fromFormat = isLatex ? 'latex' : 'markdown';
|
|
35
|
+
// 4. Determine parser type (LaTeX requires pandoc, --fast is ignored for LaTeX)
|
|
36
|
+
const parserType = isLatex ? 'pandoc' : (options.fast ? 'markdown-it' : config.buildParser);
|
|
37
|
+
Logger.info(`Parser: ${parserType}`);
|
|
38
|
+
if (isLatex) {
|
|
39
|
+
Logger.info('Mode: LaTeX');
|
|
40
|
+
}
|
|
41
|
+
// 5. Check pandoc installation (required for pandoc parser or LaTeX files)
|
|
42
|
+
if (parserType === 'pandoc') {
|
|
43
|
+
PandocDetector.ensureInstalled(isLatex);
|
|
44
|
+
}
|
|
45
|
+
// 6. Determine output path
|
|
33
46
|
const outputPath = options.output
|
|
34
47
|
? path.resolve(options.output)
|
|
35
48
|
: path.join(path.dirname(absolutePath), path.basename(filePath, path.extname(filePath)) + '.html');
|
|
36
49
|
Logger.info(`Output: ${outputPath}`);
|
|
37
|
-
//
|
|
38
|
-
const
|
|
39
|
-
...config.pandoc,
|
|
40
|
-
standalone: true, // build always uses standalone
|
|
41
|
-
};
|
|
42
|
-
const parser = ParserFactory.create(parserType, pandocOptions, config.math);
|
|
50
|
+
// 7. Prepare converter with selected parser
|
|
51
|
+
const parser = ParserFactory.create(parserType, config.pandoc, config.math, fromFormat);
|
|
43
52
|
const converter = new MarkdownConverter({
|
|
44
53
|
theme: config.theme,
|
|
45
|
-
pandocOptions:
|
|
54
|
+
pandocOptions: config.pandoc,
|
|
46
55
|
customCSS: config.css,
|
|
47
56
|
template: config.template || undefined,
|
|
48
57
|
mathEnabled: config.math?.enabled ?? true,
|
|
49
58
|
});
|
|
50
59
|
converter.setParser(parser);
|
|
51
|
-
//
|
|
52
|
-
Logger.info(
|
|
60
|
+
// 8. Execute conversion
|
|
61
|
+
Logger.info(`Converting ${isLatex ? 'LaTeX' : 'markdown'}...`);
|
|
53
62
|
const html = await converter.convertWithTemplate(absolutePath);
|
|
54
63
|
await converter.writeHTML(html, outputPath);
|
|
55
64
|
Logger.success(`Build complete: ${outputPath}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/dev.ts"],"names":[],"mappings":"AAuBA,UAAU,UAAU;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC,CAgLf"}
|
package/dist/cli/commands/dev.js
CHANGED
|
@@ -11,6 +11,13 @@ import { SessionManager } from '../../utils/session-manager.js';
|
|
|
11
11
|
import * as path from 'path';
|
|
12
12
|
import fs from 'fs-extra';
|
|
13
13
|
import open from 'open';
|
|
14
|
+
/**
|
|
15
|
+
* Check if the file is a LaTeX file based on extension.
|
|
16
|
+
*/
|
|
17
|
+
function isLatexFile(filePath) {
|
|
18
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
19
|
+
return ext === '.tex' || ext === '.latex';
|
|
20
|
+
}
|
|
14
21
|
export async function devCommand(filePath, options) {
|
|
15
22
|
try {
|
|
16
23
|
Logger.info('Starting vimd dev...');
|
|
@@ -49,26 +56,32 @@ export async function devCommand(filePath, options) {
|
|
|
49
56
|
}
|
|
50
57
|
Logger.info(`Theme: ${config.theme}`);
|
|
51
58
|
Logger.info(`Port: ${port}`);
|
|
52
|
-
// 5.
|
|
53
|
-
const parserType = options.pandoc ? 'pandoc' : config.devParser;
|
|
54
|
-
Logger.info(`Parser: ${parserType}`);
|
|
55
|
-
// 6. Check pandoc installation only if pandoc parser is selected
|
|
56
|
-
if (parserType === 'pandoc') {
|
|
57
|
-
PandocDetector.ensureInstalled();
|
|
58
|
-
}
|
|
59
|
-
// 7. Check file exists
|
|
59
|
+
// 5. Check file exists first (needed for extension detection)
|
|
60
60
|
const absolutePath = path.resolve(filePath);
|
|
61
61
|
if (!(await fs.pathExists(absolutePath))) {
|
|
62
62
|
Logger.error(`File not found: ${filePath}`);
|
|
63
63
|
process.exit(1);
|
|
64
64
|
}
|
|
65
|
-
//
|
|
65
|
+
// 6. Detect file type and determine parser/format
|
|
66
|
+
const isLatex = isLatexFile(filePath);
|
|
67
|
+
const fromFormat = isLatex ? 'latex' : 'markdown';
|
|
68
|
+
// 7. Determine parser type (LaTeX requires pandoc)
|
|
69
|
+
const parserType = isLatex ? 'pandoc' : (options.pandoc ? 'pandoc' : config.devParser);
|
|
70
|
+
Logger.info(`Parser: ${parserType}`);
|
|
71
|
+
if (isLatex) {
|
|
72
|
+
Logger.info('Mode: LaTeX');
|
|
73
|
+
}
|
|
74
|
+
// 8. Check pandoc installation (required for pandoc parser or LaTeX files)
|
|
75
|
+
if (parserType === 'pandoc') {
|
|
76
|
+
PandocDetector.ensureInstalled(isLatex);
|
|
77
|
+
}
|
|
78
|
+
// 9. Prepare output HTML in source directory
|
|
66
79
|
const sourceDir = path.dirname(absolutePath);
|
|
67
80
|
const basename = path.basename(filePath, path.extname(filePath));
|
|
68
81
|
const htmlFileName = `vimd-preview-${basename}.html`;
|
|
69
82
|
const htmlPath = path.join(sourceDir, htmlFileName);
|
|
70
|
-
//
|
|
71
|
-
const parser = ParserFactory.create(parserType, config.pandoc, config.math);
|
|
83
|
+
// 10. Prepare converter with selected parser
|
|
84
|
+
const parser = ParserFactory.create(parserType, config.pandoc, config.math, fromFormat);
|
|
72
85
|
const converter = new MarkdownConverter({
|
|
73
86
|
theme: config.theme,
|
|
74
87
|
pandocOptions: config.pandoc,
|
|
@@ -77,8 +90,8 @@ export async function devCommand(filePath, options) {
|
|
|
77
90
|
mathEnabled: config.math?.enabled ?? true,
|
|
78
91
|
});
|
|
79
92
|
converter.setParser(parser);
|
|
80
|
-
//
|
|
81
|
-
Logger.info(
|
|
93
|
+
// 11. Initial conversion
|
|
94
|
+
Logger.info(`Converting ${isLatex ? 'LaTeX' : 'markdown'}...`);
|
|
82
95
|
const html = await converter.convertWithTemplate(absolutePath);
|
|
83
96
|
await converter.writeHTML(html, htmlPath);
|
|
84
97
|
Logger.success('Conversion complete');
|
package/dist/config/defaults.js
CHANGED
package/dist/core/converter.js
CHANGED
|
@@ -67,7 +67,7 @@ export class MarkdownConverter {
|
|
|
67
67
|
const template = await fs.readFile(templatePath, 'utf-8');
|
|
68
68
|
// Simple template replacement
|
|
69
69
|
let html = template
|
|
70
|
-
.replace('{{title}}', path.basename(markdownPath,
|
|
70
|
+
.replace('{{title}}', path.basename(markdownPath, path.extname(markdownPath)))
|
|
71
71
|
.replace('{{theme_css}}', themeCSS)
|
|
72
72
|
.replace('{{content}}', contentHtml);
|
|
73
73
|
if (customCSS) {
|
|
@@ -2,7 +2,11 @@ import { OSType } from '../utils/os-detector.js';
|
|
|
2
2
|
export declare class PandocDetector {
|
|
3
3
|
static check(): boolean;
|
|
4
4
|
static detectOS(): OSType;
|
|
5
|
-
static showInstallGuide(os: OSType): void;
|
|
6
|
-
|
|
5
|
+
static showInstallGuide(os: OSType, forLatex?: boolean): void;
|
|
6
|
+
/**
|
|
7
|
+
* Ensure pandoc is installed. If not, show installation guide and exit.
|
|
8
|
+
* @param forLatex - If true, indicates this is for LaTeX file processing (no markdown-it fallback)
|
|
9
|
+
*/
|
|
10
|
+
static ensureInstalled(forLatex?: boolean): void;
|
|
7
11
|
}
|
|
8
12
|
//# sourceMappingURL=pandoc-detector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pandoc-detector.d.ts","sourceRoot":"","sources":["../../src/core/pandoc-detector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,qBAAa,cAAc;IACzB,MAAM,CAAC,KAAK,IAAI,OAAO;IASvB,MAAM,CAAC,QAAQ,IAAI,MAAM;IAczB,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"pandoc-detector.d.ts","sourceRoot":"","sources":["../../src/core/pandoc-detector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,qBAAa,cAAc;IACzB,MAAM,CAAC,KAAK,IAAI,OAAO;IASvB,MAAM,CAAC,QAAQ,IAAI,MAAM;IAczB,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,IAAI;IA2DpE;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,QAAQ,GAAE,OAAe,GAAG,IAAI;CAQxD"}
|
|
@@ -23,17 +23,27 @@ export class PandocDetector {
|
|
|
23
23
|
return 'linux-debian';
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
static showInstallGuide(os) {
|
|
26
|
+
static showInstallGuide(os, forLatex = false) {
|
|
27
27
|
console.error('⚠️ pandoc not found');
|
|
28
28
|
console.error('');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
if (forLatex) {
|
|
30
|
+
// LaTeX files require pandoc - no fallback option
|
|
31
|
+
console.error('pandoc is required for LaTeX (.tex) file preview.');
|
|
32
|
+
console.error('');
|
|
33
|
+
console.error('Install pandoc:');
|
|
34
|
+
console.error('');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// Markdown files have a fallback option
|
|
38
|
+
console.error('pandoc is required for the selected parser mode.');
|
|
39
|
+
console.error('');
|
|
40
|
+
console.error('Option 1: Use markdown-it mode (no pandoc needed)');
|
|
41
|
+
console.error(' vimd dev document.md (default, fast preview)');
|
|
42
|
+
console.error(' vimd build document.md --fast');
|
|
43
|
+
console.error('');
|
|
44
|
+
console.error('Option 2: Install pandoc for high-quality output');
|
|
45
|
+
console.error('');
|
|
46
|
+
}
|
|
37
47
|
switch (os) {
|
|
38
48
|
case 'macos':
|
|
39
49
|
console.error(' macOS (Homebrew):');
|
|
@@ -65,11 +75,15 @@ export class PandocDetector {
|
|
|
65
75
|
console.error('');
|
|
66
76
|
process.exit(1);
|
|
67
77
|
}
|
|
68
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Ensure pandoc is installed. If not, show installation guide and exit.
|
|
80
|
+
* @param forLatex - If true, indicates this is for LaTeX file processing (no markdown-it fallback)
|
|
81
|
+
*/
|
|
82
|
+
static ensureInstalled(forLatex = false) {
|
|
69
83
|
if (this.check()) {
|
|
70
84
|
return;
|
|
71
85
|
}
|
|
72
86
|
const os = this.detectOS();
|
|
73
|
-
this.showInstallGuide(os);
|
|
87
|
+
this.showInstallGuide(os, forLatex);
|
|
74
88
|
}
|
|
75
89
|
}
|
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
import { Parser } from './types.js';
|
|
2
2
|
import { MathConfig, PandocConfig } from '../../config/types.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
|
|
4
|
+
* Source format for pandoc conversion.
|
|
5
|
+
*/
|
|
6
|
+
export type SourceFormat = 'markdown' | 'latex';
|
|
7
|
+
/**
|
|
8
|
+
* Document parser using pandoc.
|
|
9
|
+
* Provides high-quality document to HTML conversion with extensive features.
|
|
10
|
+
* Supports both Markdown and LaTeX source formats.
|
|
6
11
|
*/
|
|
7
12
|
export declare class PandocParser implements Parser {
|
|
8
13
|
readonly name = "pandoc";
|
|
9
14
|
private config;
|
|
10
15
|
private mathConfig?;
|
|
11
|
-
|
|
16
|
+
private fromFormat;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new PandocParser instance.
|
|
19
|
+
* @param config - Pandoc configuration options
|
|
20
|
+
* @param mathConfig - Math rendering configuration
|
|
21
|
+
* @param fromFormat - Source format ('markdown' or 'latex')
|
|
22
|
+
*/
|
|
23
|
+
constructor(config?: Partial<PandocConfig>, mathConfig?: MathConfig, fromFormat?: SourceFormat);
|
|
12
24
|
/**
|
|
13
|
-
* Convert
|
|
14
|
-
* @param
|
|
25
|
+
* Convert document to HTML using pandoc.
|
|
26
|
+
* @param content - The document content to convert
|
|
15
27
|
* @returns The converted HTML string
|
|
16
28
|
*/
|
|
17
|
-
parse(
|
|
29
|
+
parse(content: string): Promise<string>;
|
|
18
30
|
/**
|
|
19
31
|
* Check if pandoc is available.
|
|
20
32
|
* @returns true if pandoc is installed and accessible
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pandoc-parser.d.ts","sourceRoot":"","sources":["../../../src/core/parser/pandoc-parser.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"pandoc-parser.d.ts","sourceRoot":"","sources":["../../../src/core/parser/pandoc-parser.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,OAAO,CAAC;AAYhD;;;;GAIG;AACH,qBAAa,YAAa,YAAW,MAAM;IACzC,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,UAAU,CAAC,CAAa;IAChC,OAAO,CAAC,UAAU,CAAe;IAEjC;;;;;OAKG;gBAED,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM,EAClC,UAAU,CAAC,EAAE,UAAU,EACvB,UAAU,GAAE,YAAyB;IAOvC;;;;OAIG;IACG,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAkB7C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IASrC;;OAEG;IACH,OAAO,CAAC,eAAe;CAwCxB"}
|
|
@@ -10,34 +10,42 @@ const DEFAULT_PANDOC_CONFIG = {
|
|
|
10
10
|
highlightStyle: 'pygments',
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* Provides high-quality
|
|
13
|
+
* Document parser using pandoc.
|
|
14
|
+
* Provides high-quality document to HTML conversion with extensive features.
|
|
15
|
+
* Supports both Markdown and LaTeX source formats.
|
|
15
16
|
*/
|
|
16
17
|
export class PandocParser {
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Create a new PandocParser instance.
|
|
20
|
+
* @param config - Pandoc configuration options
|
|
21
|
+
* @param mathConfig - Math rendering configuration
|
|
22
|
+
* @param fromFormat - Source format ('markdown' or 'latex')
|
|
23
|
+
*/
|
|
24
|
+
constructor(config = {}, mathConfig, fromFormat = 'markdown') {
|
|
18
25
|
this.name = 'pandoc';
|
|
19
26
|
this.config = { ...DEFAULT_PANDOC_CONFIG, ...config };
|
|
20
27
|
this.mathConfig = mathConfig;
|
|
28
|
+
this.fromFormat = fromFormat;
|
|
21
29
|
}
|
|
22
30
|
/**
|
|
23
|
-
* Convert
|
|
24
|
-
* @param
|
|
31
|
+
* Convert document to HTML using pandoc.
|
|
32
|
+
* @param content - The document content to convert
|
|
25
33
|
* @returns The converted HTML string
|
|
26
34
|
*/
|
|
27
|
-
async parse(
|
|
35
|
+
async parse(content) {
|
|
28
36
|
const pandocArgs = this.buildPandocArgs();
|
|
29
37
|
const command = `pandoc ${pandocArgs.join(' ')}`;
|
|
30
38
|
try {
|
|
31
39
|
const html = execSync(command, {
|
|
32
40
|
encoding: 'utf-8',
|
|
33
|
-
input:
|
|
41
|
+
input: content,
|
|
34
42
|
maxBuffer: 10 * 1024 * 1024, // 10MB
|
|
35
43
|
});
|
|
36
44
|
return html;
|
|
37
45
|
}
|
|
38
46
|
catch (error) {
|
|
39
47
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
40
|
-
throw new Error(`Failed to convert
|
|
48
|
+
throw new Error(`Failed to convert document with pandoc: ${errorMessage}`);
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
@@ -59,7 +67,7 @@ export class PandocParser {
|
|
|
59
67
|
buildPandocArgs() {
|
|
60
68
|
const args = [];
|
|
61
69
|
// Basic options
|
|
62
|
-
args.push(
|
|
70
|
+
args.push(`--from=${this.fromFormat}`);
|
|
63
71
|
args.push('--to=html');
|
|
64
72
|
if (this.config.standalone) {
|
|
65
73
|
args.push('--standalone');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Parser, ParserType } from './types.js';
|
|
2
|
+
import { SourceFormat } from './pandoc-parser.js';
|
|
2
3
|
import { PandocConfig, MathConfig } from '../../config/types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Factory for creating parser instances.
|
|
@@ -10,10 +11,11 @@ export declare class ParserFactory {
|
|
|
10
11
|
* @param type - The type of parser to create
|
|
11
12
|
* @param pandocConfig - Optional configuration for pandoc parser
|
|
12
13
|
* @param mathConfig - Optional configuration for math support
|
|
14
|
+
* @param fromFormat - Source format for pandoc parser ('markdown' or 'latex')
|
|
13
15
|
* @returns A parser instance
|
|
14
16
|
* @throws Error if the parser type is unknown
|
|
15
17
|
*/
|
|
16
|
-
static create(type: ParserType, pandocConfig?: Partial<PandocConfig>, mathConfig?: MathConfig): Parser;
|
|
18
|
+
static create(type: ParserType, pandocConfig?: Partial<PandocConfig>, mathConfig?: MathConfig, fromFormat?: SourceFormat): Parser;
|
|
17
19
|
/**
|
|
18
20
|
* Create a parser with fallback support.
|
|
19
21
|
* If the preferred parser is not available, falls back to markdown-it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser-factory.d.ts","sourceRoot":"","sources":["../../../src/core/parser/parser-factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"parser-factory.d.ts","sourceRoot":"","sources":["../../../src/core/parser/parser-factory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAgB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEjE;;;GAGG;AACH,qBAAa,aAAa;IACxB;;;;;;;;OAQG;IACH,MAAM,CAAC,MAAM,CACX,IAAI,EAAE,UAAU,EAChB,YAAY,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,EACpC,UAAU,CAAC,EAAE,UAAU,EACvB,UAAU,GAAE,YAAyB,GACpC,MAAM;IAaT;;;;;;;;OAQG;WACU,kBAAkB,CAC7B,SAAS,EAAE,UAAU,EACrB,YAAY,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,EACpC,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,MAAM,CAAC;IAmBlB;;;OAGG;IACH,MAAM,CAAC,mBAAmB,IAAI,UAAU;IAIxC;;;OAGG;IACH,MAAM,CAAC,qBAAqB,IAAI,UAAU;CAG3C"}
|
|
@@ -11,15 +11,16 @@ export class ParserFactory {
|
|
|
11
11
|
* @param type - The type of parser to create
|
|
12
12
|
* @param pandocConfig - Optional configuration for pandoc parser
|
|
13
13
|
* @param mathConfig - Optional configuration for math support
|
|
14
|
+
* @param fromFormat - Source format for pandoc parser ('markdown' or 'latex')
|
|
14
15
|
* @returns A parser instance
|
|
15
16
|
* @throws Error if the parser type is unknown
|
|
16
17
|
*/
|
|
17
|
-
static create(type, pandocConfig, mathConfig) {
|
|
18
|
+
static create(type, pandocConfig, mathConfig, fromFormat = 'markdown') {
|
|
18
19
|
switch (type) {
|
|
19
20
|
case 'markdown-it':
|
|
20
21
|
return new MarkdownItParser(mathConfig);
|
|
21
22
|
case 'pandoc':
|
|
22
|
-
return new PandocParser(pandocConfig, mathConfig);
|
|
23
|
+
return new PandocParser(pandocConfig, mathConfig, fromFormat);
|
|
23
24
|
default:
|
|
24
25
|
// TypeScript exhaustive check
|
|
25
26
|
const _exhaustive = type;
|