vimd 0.1.11 → 0.2.0

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.
Files changed (34) hide show
  1. package/README.md +110 -193
  2. package/dist/cli/commands/build.d.ts +1 -0
  3. package/dist/cli/commands/build.d.ts.map +1 -1
  4. package/dist/cli/commands/build.js +19 -10
  5. package/dist/cli/commands/dev.d.ts +1 -0
  6. package/dist/cli/commands/dev.d.ts.map +1 -1
  7. package/dist/cli/commands/dev.js +18 -10
  8. package/dist/cli/index.js +2 -0
  9. package/dist/config/defaults.d.ts.map +1 -1
  10. package/dist/config/defaults.js +2 -0
  11. package/dist/config/types.d.ts +7 -0
  12. package/dist/config/types.d.ts.map +1 -1
  13. package/dist/core/converter.d.ts +18 -0
  14. package/dist/core/converter.d.ts.map +1 -1
  15. package/dist/core/converter.js +30 -1
  16. package/dist/core/pandoc-detector.d.ts.map +1 -1
  17. package/dist/core/pandoc-detector.js +7 -2
  18. package/dist/core/parser/index.d.ts +5 -0
  19. package/dist/core/parser/index.d.ts.map +1 -0
  20. package/dist/core/parser/index.js +4 -0
  21. package/dist/core/parser/markdown-it-parser.d.ts +23 -0
  22. package/dist/core/parser/markdown-it-parser.d.ts.map +1 -0
  23. package/dist/core/parser/markdown-it-parser.js +49 -0
  24. package/dist/core/parser/pandoc-parser.d.ts +27 -0
  25. package/dist/core/parser/pandoc-parser.d.ts.map +1 -0
  26. package/dist/core/parser/pandoc-parser.js +83 -0
  27. package/dist/core/parser/parser-factory.d.ts +36 -0
  28. package/dist/core/parser/parser-factory.d.ts.map +1 -0
  29. package/dist/core/parser/parser-factory.js +63 -0
  30. package/dist/core/parser/types.d.ts +26 -0
  31. package/dist/core/parser/types.d.ts.map +1 -0
  32. package/dist/core/parser/types.js +2 -0
  33. package/dist/themes/styles/technical.css +632 -47
  34. package/package.json +6 -1
@@ -9,8 +9,37 @@ const __dirname = path.dirname(__filename);
9
9
  export class MarkdownConverter {
10
10
  constructor(config) {
11
11
  this.config = config;
12
+ this.parser = null;
13
+ }
14
+ /**
15
+ * Set the parser to use for conversion.
16
+ * If not set, falls back to legacy pandoc conversion.
17
+ * @param parser - The parser instance to use
18
+ */
19
+ setParser(parser) {
20
+ this.parser = parser;
21
+ }
22
+ /**
23
+ * Get the currently set parser.
24
+ * @returns The parser instance or null if not set
25
+ */
26
+ getParser() {
27
+ return this.parser;
12
28
  }
13
29
  async convert(markdownPath) {
30
+ // If a parser is set, use it
31
+ if (this.parser) {
32
+ const content = await fs.readFile(markdownPath, 'utf-8');
33
+ return this.parser.parse(content);
34
+ }
35
+ // Legacy: use direct pandoc execution for backward compatibility
36
+ return this.convertWithPandocLegacy(markdownPath);
37
+ }
38
+ /**
39
+ * Legacy pandoc conversion method.
40
+ * Used when no parser is explicitly set (backward compatibility).
41
+ */
42
+ async convertWithPandocLegacy(markdownPath) {
14
43
  const pandocArgs = this.buildPandocArgs();
15
44
  const command = `pandoc ${pandocArgs.join(' ')} "${markdownPath}"`;
16
45
  try {
@@ -68,7 +97,7 @@ export class MarkdownConverter {
68
97
  }
69
98
  }
70
99
  if (this.config.pandocOptions.highlightStyle) {
71
- args.push(`--highlight-style=${this.config.pandocOptions.highlightStyle}`);
100
+ args.push(`--syntax-highlighting=${this.config.pandocOptions.highlightStyle}`);
72
101
  }
73
102
  // Metadata
74
103
  if (this.config.pandocOptions.metadata) {
@@ -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;IA4CzC,MAAM,CAAC,eAAe,IAAI,IAAI;CAQ/B"}
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;IAiDzC,MAAM,CAAC,eAAe,IAAI,IAAI;CAQ/B"}
@@ -26,8 +26,13 @@ export class PandocDetector {
26
26
  static showInstallGuide(os) {
27
27
  console.error('⚠️ pandoc not found');
28
28
  console.error('');
29
- console.error('vimd requires pandoc to convert Markdown to HTML.');
30
- console.error('Please install pandoc manually:');
29
+ console.error('pandoc is required for the selected parser mode.');
30
+ console.error('');
31
+ console.error('Option 1: Use markdown-it mode (no pandoc needed)');
32
+ console.error(' vimd dev document.md (default, fast preview)');
33
+ console.error(' vimd build document.md --fast');
34
+ console.error('');
35
+ console.error('Option 2: Install pandoc for high-quality output');
31
36
  console.error('');
32
37
  switch (os) {
33
38
  case 'macos':
@@ -0,0 +1,5 @@
1
+ export type { Parser, ParserType } from './types.js';
2
+ export { MarkdownItParser } from './markdown-it-parser.js';
3
+ export { PandocParser } from './pandoc-parser.js';
4
+ export { ParserFactory } from './parser-factory.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/parser/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,4 @@
1
+ // src/core/parser/index.ts
2
+ export { MarkdownItParser } from './markdown-it-parser.js';
3
+ export { PandocParser } from './pandoc-parser.js';
4
+ export { ParserFactory } from './parser-factory.js';
@@ -0,0 +1,23 @@
1
+ import { Parser } from './types.js';
2
+ /**
3
+ * Markdown parser using markdown-it library.
4
+ * Provides fast markdown to HTML conversion with GFM support.
5
+ */
6
+ export declare class MarkdownItParser implements Parser {
7
+ readonly name = "markdown-it";
8
+ private md;
9
+ constructor();
10
+ /**
11
+ * Convert markdown to HTML.
12
+ * @param markdown - The markdown content to convert
13
+ * @returns The converted HTML string
14
+ */
15
+ parse(markdown: string): Promise<string>;
16
+ /**
17
+ * Check if the parser is available.
18
+ * markdown-it is always available as it's an npm package.
19
+ * @returns Always returns true
20
+ */
21
+ isAvailable(): Promise<boolean>;
22
+ }
23
+ //# sourceMappingURL=markdown-it-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown-it-parser.d.ts","sourceRoot":"","sources":["../../../src/core/parser/markdown-it-parser.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,MAAM;IAC7C,QAAQ,CAAC,IAAI,iBAAiB;IAC9B,OAAO,CAAC,EAAE,CAAa;;IAwBvB;;;;OAIG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI9C;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAGtC"}
@@ -0,0 +1,49 @@
1
+ // src/core/parser/markdown-it-parser.ts
2
+ import MarkdownIt from 'markdown-it';
3
+ import hljs from 'highlight.js';
4
+ import strikethrough from 'markdown-it-strikethrough-alt';
5
+ import taskLists from 'markdown-it-task-lists';
6
+ /**
7
+ * Markdown parser using markdown-it library.
8
+ * Provides fast markdown to HTML conversion with GFM support.
9
+ */
10
+ export class MarkdownItParser {
11
+ constructor() {
12
+ this.name = 'markdown-it';
13
+ this.md = new MarkdownIt({
14
+ html: true,
15
+ linkify: true,
16
+ typographer: true,
17
+ highlight: (str, lang) => {
18
+ if (lang && hljs.getLanguage(lang)) {
19
+ try {
20
+ return hljs.highlight(str, { language: lang }).value;
21
+ }
22
+ catch {
23
+ // Ignore highlight errors
24
+ }
25
+ }
26
+ return ''; // Use external default escaping
27
+ },
28
+ });
29
+ // Enable GFM plugins
30
+ this.md.use(strikethrough); // ~~strikethrough~~
31
+ this.md.use(taskLists); // - [ ] task list
32
+ }
33
+ /**
34
+ * Convert markdown to HTML.
35
+ * @param markdown - The markdown content to convert
36
+ * @returns The converted HTML string
37
+ */
38
+ async parse(markdown) {
39
+ return this.md.render(markdown);
40
+ }
41
+ /**
42
+ * Check if the parser is available.
43
+ * markdown-it is always available as it's an npm package.
44
+ * @returns Always returns true
45
+ */
46
+ async isAvailable() {
47
+ return true;
48
+ }
49
+ }
@@ -0,0 +1,27 @@
1
+ import { Parser } from './types.js';
2
+ import { PandocConfig } from '../../config/types.js';
3
+ /**
4
+ * Markdown parser using pandoc.
5
+ * Provides high-quality markdown to HTML conversion with extensive features.
6
+ */
7
+ export declare class PandocParser implements Parser {
8
+ readonly name = "pandoc";
9
+ private config;
10
+ constructor(config?: Partial<PandocConfig>);
11
+ /**
12
+ * Convert markdown to HTML using pandoc.
13
+ * @param markdown - The markdown content to convert
14
+ * @returns The converted HTML string
15
+ */
16
+ parse(markdown: string): Promise<string>;
17
+ /**
18
+ * Check if pandoc is available.
19
+ * @returns true if pandoc is installed and accessible
20
+ */
21
+ isAvailable(): Promise<boolean>;
22
+ /**
23
+ * Build pandoc command arguments from config.
24
+ */
25
+ private buildPandocArgs;
26
+ }
27
+ //# sourceMappingURL=pandoc-parser.d.ts.map
@@ -0,0 +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,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAYrD;;;GAGG;AACH,qBAAa,YAAa,YAAW,MAAM;IACzC,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAe;gBAEjB,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM;IAI9C;;;;OAIG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAkB9C;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IASrC;;OAEG;IACH,OAAO,CAAC,eAAe;CA+BxB"}
@@ -0,0 +1,83 @@
1
+ // src/core/parser/pandoc-parser.ts
2
+ import { execSync } from 'child_process';
3
+ /**
4
+ * Default pandoc configuration for high-quality HTML output.
5
+ */
6
+ const DEFAULT_PANDOC_CONFIG = {
7
+ standalone: false,
8
+ toc: false,
9
+ tocDepth: 3,
10
+ highlightStyle: 'pygments',
11
+ };
12
+ /**
13
+ * Markdown parser using pandoc.
14
+ * Provides high-quality markdown to HTML conversion with extensive features.
15
+ */
16
+ export class PandocParser {
17
+ constructor(config = {}) {
18
+ this.name = 'pandoc';
19
+ this.config = { ...DEFAULT_PANDOC_CONFIG, ...config };
20
+ }
21
+ /**
22
+ * Convert markdown to HTML using pandoc.
23
+ * @param markdown - The markdown content to convert
24
+ * @returns The converted HTML string
25
+ */
26
+ async parse(markdown) {
27
+ const pandocArgs = this.buildPandocArgs();
28
+ const command = `pandoc ${pandocArgs.join(' ')}`;
29
+ try {
30
+ const html = execSync(command, {
31
+ encoding: 'utf-8',
32
+ input: markdown,
33
+ maxBuffer: 10 * 1024 * 1024, // 10MB
34
+ });
35
+ return html;
36
+ }
37
+ catch (error) {
38
+ const errorMessage = error instanceof Error ? error.message : String(error);
39
+ throw new Error(`Failed to convert markdown with pandoc: ${errorMessage}`);
40
+ }
41
+ }
42
+ /**
43
+ * Check if pandoc is available.
44
+ * @returns true if pandoc is installed and accessible
45
+ */
46
+ async isAvailable() {
47
+ try {
48
+ execSync('pandoc --version', { stdio: 'pipe' });
49
+ return true;
50
+ }
51
+ catch {
52
+ return false;
53
+ }
54
+ }
55
+ /**
56
+ * Build pandoc command arguments from config.
57
+ */
58
+ buildPandocArgs() {
59
+ const args = [];
60
+ // Basic options
61
+ args.push('--from=markdown');
62
+ args.push('--to=html');
63
+ if (this.config.standalone) {
64
+ args.push('--standalone');
65
+ }
66
+ if (this.config.toc) {
67
+ args.push('--toc');
68
+ if (this.config.tocDepth) {
69
+ args.push(`--toc-depth=${this.config.tocDepth}`);
70
+ }
71
+ }
72
+ if (this.config.highlightStyle) {
73
+ args.push(`--syntax-highlighting=${this.config.highlightStyle}`);
74
+ }
75
+ // Metadata
76
+ if (this.config.metadata) {
77
+ Object.entries(this.config.metadata).forEach(([key, value]) => {
78
+ args.push(`--metadata=${key}:"${value}"`);
79
+ });
80
+ }
81
+ return args;
82
+ }
83
+ }
@@ -0,0 +1,36 @@
1
+ import { Parser, ParserType } from './types.js';
2
+ import { PandocConfig } from '../../config/types.js';
3
+ /**
4
+ * Factory for creating parser instances.
5
+ * Provides methods to create parsers by type and with fallback support.
6
+ */
7
+ export declare class ParserFactory {
8
+ /**
9
+ * Create a parser instance by type.
10
+ * @param type - The type of parser to create
11
+ * @param pandocConfig - Optional configuration for pandoc parser
12
+ * @returns A parser instance
13
+ * @throws Error if the parser type is unknown
14
+ */
15
+ static create(type: ParserType, pandocConfig?: Partial<PandocConfig>): Parser;
16
+ /**
17
+ * Create a parser with fallback support.
18
+ * If the preferred parser is not available, falls back to markdown-it.
19
+ * @param preferred - The preferred parser type
20
+ * @param pandocConfig - Optional configuration for pandoc parser
21
+ * @returns A parser instance that is guaranteed to be available
22
+ * @throws Error if pandoc is preferred but not installed (no silent fallback)
23
+ */
24
+ static createWithFallback(preferred: ParserType, pandocConfig?: Partial<PandocConfig>): Promise<Parser>;
25
+ /**
26
+ * Get the default parser type for dev mode.
27
+ * @returns 'markdown-it' as the default for fast preview
28
+ */
29
+ static getDefaultDevParser(): ParserType;
30
+ /**
31
+ * Get the default parser type for build mode.
32
+ * @returns 'pandoc' as the default for high-quality output
33
+ */
34
+ static getDefaultBuildParser(): ParserType;
35
+ }
36
+ //# sourceMappingURL=parser-factory.d.ts.map
@@ -0,0 +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;AAGhD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD;;;GAGG;AACH,qBAAa,aAAa;IACxB;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,MAAM;IAa7E;;;;;;;OAOG;WACU,kBAAkB,CAC7B,SAAS,EAAE,UAAU,EACrB,YAAY,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GACnC,OAAO,CAAC,MAAM,CAAC;IAmBlB;;;OAGG;IACH,MAAM,CAAC,mBAAmB,IAAI,UAAU;IAIxC;;;OAGG;IACH,MAAM,CAAC,qBAAqB,IAAI,UAAU;CAG3C"}
@@ -0,0 +1,63 @@
1
+ // src/core/parser/parser-factory.ts
2
+ import { MarkdownItParser } from './markdown-it-parser.js';
3
+ import { PandocParser } from './pandoc-parser.js';
4
+ /**
5
+ * Factory for creating parser instances.
6
+ * Provides methods to create parsers by type and with fallback support.
7
+ */
8
+ export class ParserFactory {
9
+ /**
10
+ * Create a parser instance by type.
11
+ * @param type - The type of parser to create
12
+ * @param pandocConfig - Optional configuration for pandoc parser
13
+ * @returns A parser instance
14
+ * @throws Error if the parser type is unknown
15
+ */
16
+ static create(type, pandocConfig) {
17
+ switch (type) {
18
+ case 'markdown-it':
19
+ return new MarkdownItParser();
20
+ case 'pandoc':
21
+ return new PandocParser(pandocConfig);
22
+ default:
23
+ // TypeScript exhaustive check
24
+ const _exhaustive = type;
25
+ throw new Error(`Unknown parser type: ${_exhaustive}`);
26
+ }
27
+ }
28
+ /**
29
+ * Create a parser with fallback support.
30
+ * If the preferred parser is not available, falls back to markdown-it.
31
+ * @param preferred - The preferred parser type
32
+ * @param pandocConfig - Optional configuration for pandoc parser
33
+ * @returns A parser instance that is guaranteed to be available
34
+ * @throws Error if pandoc is preferred but not installed (no silent fallback)
35
+ */
36
+ static async createWithFallback(preferred, pandocConfig) {
37
+ const parser = this.create(preferred, pandocConfig);
38
+ if (await parser.isAvailable()) {
39
+ return parser;
40
+ }
41
+ // If pandoc was requested but not available, throw an error
42
+ // (we don't silently fall back to markdown-it for explicit pandoc requests)
43
+ if (preferred === 'pandoc') {
44
+ throw new Error('pandoc is not installed. Please install pandoc or use markdown-it parser.');
45
+ }
46
+ // For markdown-it, it's always available
47
+ return parser;
48
+ }
49
+ /**
50
+ * Get the default parser type for dev mode.
51
+ * @returns 'markdown-it' as the default for fast preview
52
+ */
53
+ static getDefaultDevParser() {
54
+ return 'markdown-it';
55
+ }
56
+ /**
57
+ * Get the default parser type for build mode.
58
+ * @returns 'pandoc' as the default for high-quality output
59
+ */
60
+ static getDefaultBuildParser() {
61
+ return 'pandoc';
62
+ }
63
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Parser interface for markdown to HTML conversion.
3
+ * Both markdown-it and pandoc parsers implement this interface.
4
+ */
5
+ export interface Parser {
6
+ /**
7
+ * Convert markdown content to HTML.
8
+ * @param markdown - The markdown content to convert
9
+ * @returns The converted HTML string
10
+ */
11
+ parse(markdown: string): Promise<string>;
12
+ /**
13
+ * Check if the parser is available for use.
14
+ * @returns true if the parser can be used
15
+ */
16
+ isAvailable(): Promise<boolean>;
17
+ /**
18
+ * The name of the parser.
19
+ */
20
+ readonly name: string;
21
+ }
22
+ /**
23
+ * Available parser types.
24
+ */
25
+ export type ParserType = 'markdown-it' | 'pandoc';
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/parser/types.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzC;;;OAGG;IACH,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ // src/core/parser/types.ts
2
+ export {};