@leadertechie/md2html 0.1.0-alpha.2 → 0.1.0-alpha.21

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/dist/parser.js DELETED
@@ -1,117 +0,0 @@
1
- import { marked } from 'marked';
2
- export class MarkdownParser {
3
- constructor(options) {
4
- this.imagePathPrefix = options?.imagePathPrefix || '';
5
- this.imageBaseUrl = options?.imageBaseUrl || '';
6
- }
7
- processImagePath(src) {
8
- if (src.startsWith('http') || src.startsWith('/')) {
9
- return src;
10
- }
11
- let path = this.imagePathPrefix ? `${this.imagePathPrefix}${src}` : src;
12
- if (this.imageBaseUrl && !path.startsWith('http')) {
13
- path = `${this.imageBaseUrl}${path}`;
14
- }
15
- return path;
16
- }
17
- processInlineFormatting(text) {
18
- return text
19
- .replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
20
- .replace(/\*(.+?)\*/g, '<em>$1</em>');
21
- }
22
- parseTokens(tokens) {
23
- const nodes = [];
24
- for (const token of tokens) {
25
- const node = this.parseToken(token);
26
- if (node) {
27
- nodes.push(node);
28
- }
29
- }
30
- return nodes;
31
- }
32
- parseToken(token) {
33
- switch (token.type) {
34
- case 'heading':
35
- return {
36
- type: 'heading',
37
- content: token.text,
38
- attributes: { level: String(token.depth) }
39
- };
40
- case 'paragraph':
41
- const tokens = token.tokens || [];
42
- const hasInlineImage = tokens.some(t => t.type === 'image');
43
- if (hasInlineImage) {
44
- const children = tokens.map(t => {
45
- if (t.type === 'image') {
46
- return {
47
- type: 'image',
48
- src: this.processImagePath(t.href),
49
- alt: t.text || ''
50
- };
51
- }
52
- return {
53
- type: 'text',
54
- content: this.processInlineFormatting(t.text || '')
55
- };
56
- });
57
- return {
58
- type: 'paragraph',
59
- children
60
- };
61
- }
62
- return {
63
- type: 'paragraph',
64
- content: this.processInlineFormatting(token.text)
65
- };
66
- case 'list':
67
- return {
68
- type: 'list',
69
- ordered: token.ordered,
70
- children: token.items.map((item) => ({
71
- type: 'list-item',
72
- content: this.processInlineFormatting(item.text)
73
- }))
74
- };
75
- case 'image':
76
- return {
77
- type: 'image',
78
- src: this.processImagePath(token.href),
79
- alt: token.title || ''
80
- };
81
- case 'code':
82
- return {
83
- type: 'code',
84
- content: token.text,
85
- attributes: { lang: token.lang || '' }
86
- };
87
- case 'hr':
88
- return { type: 'container', attributes: { tag: 'hr' } };
89
- case 'blockquote':
90
- return {
91
- type: 'container',
92
- attributes: { tag: 'blockquote' },
93
- children: this.parseTokens(token.tokens || [])
94
- };
95
- case 'html':
96
- return { type: 'container', content: token.raw };
97
- default:
98
- return null;
99
- }
100
- }
101
- parse(markdown, options) {
102
- const parseOptions = {
103
- gfm: options?.gfm ?? true,
104
- breaks: options?.breaks ?? false,
105
- pedantic: options?.pedantic ?? false
106
- };
107
- const tokens = marked.lexer(markdown, parseOptions);
108
- const content = this.parseTokens(tokens);
109
- return {
110
- title: '',
111
- content
112
- };
113
- }
114
- parseToNodes(markdown, options) {
115
- return this.parse(markdown, options).content;
116
- }
117
- }
@@ -1,17 +0,0 @@
1
- import { ContentNode, MarkdownContent, PipelineConfig } from './types';
2
- export declare class MarkdownPipeline {
3
- private parser;
4
- private renderer;
5
- private config;
6
- constructor(config?: PipelineConfig);
7
- parse(markdown: string): ContentNode[];
8
- parseWithMetadata(markdown: string): MarkdownContent;
9
- render(nodes: ContentNode[]): string;
10
- renderMarkdown(markdown: string): string;
11
- renderPage(title: string, nodes: ContentNode[], options?: {
12
- lang?: string;
13
- charset?: string;
14
- }): string;
15
- getConfig(): Readonly<Required<PipelineConfig>>;
16
- }
17
- //# sourceMappingURL=pipeline.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEvE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,MAAM,CAA2B;gBAE7B,MAAM,GAAE,cAAmB;IAkBvC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,EAAE;IAItC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe;IAIpD,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM;IAIpC,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAKxC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE;QACxD,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,MAAM;IAeV,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;CAGhD"}
package/dist/pipeline.js DELETED
@@ -1,50 +0,0 @@
1
- import { MarkdownParser } from './parser';
2
- import { HTMLRenderer } from './renderer';
3
- export class MarkdownPipeline {
4
- constructor(config = {}) {
5
- this.config = {
6
- imagePathPrefix: config.imagePathPrefix || '',
7
- imageBaseUrl: config.imageBaseUrl || '',
8
- parseOptions: {
9
- gfm: config.parseOptions?.gfm ?? true,
10
- breaks: config.parseOptions?.breaks ?? false,
11
- pedantic: config.parseOptions?.pedantic ?? false
12
- }
13
- };
14
- this.parser = new MarkdownParser({
15
- imagePathPrefix: this.config.imagePathPrefix,
16
- imageBaseUrl: this.config.imageBaseUrl
17
- });
18
- this.renderer = new HTMLRenderer();
19
- }
20
- parse(markdown) {
21
- return this.parser.parseToNodes(markdown, this.config.parseOptions);
22
- }
23
- parseWithMetadata(markdown) {
24
- return this.parser.parse(markdown, this.config.parseOptions);
25
- }
26
- render(nodes) {
27
- return this.renderer.renderNodes(nodes);
28
- }
29
- renderMarkdown(markdown) {
30
- const nodes = this.parse(markdown);
31
- return this.render(nodes);
32
- }
33
- renderPage(title, nodes, options) {
34
- const html = this.render(nodes);
35
- return `<!DOCTYPE html>
36
- <html lang="${options?.lang || 'en'}">
37
- <head>
38
- <meta charset="${options?.charset || 'UTF-8'}">
39
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
40
- <title>${title}</title>
41
- </head>
42
- <body>
43
- ${html}
44
- </body>
45
- </html>`;
46
- }
47
- getConfig() {
48
- return { ...this.config };
49
- }
50
- }
@@ -1,8 +0,0 @@
1
- import { ContentNode } from './types';
2
- export declare class HTMLRenderer {
3
- renderNode(node: ContentNode): string;
4
- renderNodes(nodes: ContentNode[]): string;
5
- renderToHTMLString(nodes: ContentNode[]): string;
6
- render(markdown: string): string;
7
- }
8
- //# sourceMappingURL=renderer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,YAAY;IACvB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM;IAiDrC,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM;IAOzC,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM;IAIhD,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;CAGjC"}
package/dist/renderer.js DELETED
@@ -1,54 +0,0 @@
1
- export class HTMLRenderer {
2
- renderNode(node) {
3
- switch (node.type) {
4
- case 'heading':
5
- const level = node.attributes?.level || '2';
6
- return `<h${level}>${node.content || ''}</h${level}>`;
7
- case 'paragraph':
8
- if (node.children) {
9
- return `<p>${node.children.map(child => this.renderNode(child)).join('')}</p>`;
10
- }
11
- return `<p>${node.content || ''}</p>`;
12
- case 'list':
13
- const tag = node.ordered ? 'ol' : 'ul';
14
- const items = node.children?.map(child => this.renderNode(child)).join('') || '';
15
- return `<${tag}>${items}</${tag}>`;
16
- case 'list-item':
17
- return `<li>${node.content || ''}</li>`;
18
- case 'image':
19
- const src = node.src || node.attributes?.src || '';
20
- const alt = node.alt || node.attributes?.alt || '';
21
- return `<img src="${src}" alt="${alt}" class="${node.className || ''}">`;
22
- case 'code':
23
- return `<pre><code class="language-${node.attributes?.lang || ''}">${node.content || ''}</code></pre>`;
24
- case 'container':
25
- if (node.attributes?.tag === 'hr')
26
- return '<hr>';
27
- if (node.attributes?.tag === 'blockquote') {
28
- const children = node.children?.map(child => this.renderNode(child)).join('') || '';
29
- return `<blockquote>${children}</blockquote>`;
30
- }
31
- const containerChildren = node.children?.map(child => this.renderNode(child)).join('') || '';
32
- return `<div class="${node.className || ''}">${containerChildren}</div>`;
33
- case 'strong':
34
- return `<strong>${node.content || ''}</strong>`;
35
- case 'emphasis':
36
- return `<em>${node.content || ''}</em>`;
37
- case 'text':
38
- default:
39
- return node.content || '';
40
- }
41
- }
42
- renderNodes(nodes) {
43
- if (!nodes || nodes.length === 0) {
44
- return '';
45
- }
46
- return nodes.map(node => this.renderNode(node)).join('\n');
47
- }
48
- renderToHTMLString(nodes) {
49
- return this.renderNodes(nodes);
50
- }
51
- render(markdown) {
52
- return markdown;
53
- }
54
- }
package/dist/types.d.ts DELETED
@@ -1,27 +0,0 @@
1
- export type ContentNodeType = 'text' | 'heading' | 'paragraph' | 'list' | 'list-item' | 'image' | 'code' | 'container' | 'strong' | 'emphasis';
2
- export interface ContentNode {
3
- type: ContentNodeType;
4
- content?: string;
5
- children?: ContentNode[];
6
- attributes?: Record<string, unknown>;
7
- className?: string;
8
- src?: string;
9
- alt?: string;
10
- ordered?: boolean;
11
- }
12
- export interface MarkdownContent {
13
- title: string;
14
- metadata?: Record<string, unknown>;
15
- content: ContentNode[];
16
- }
17
- export interface ParseOptions {
18
- gfm?: boolean;
19
- breaks?: boolean;
20
- pedantic?: boolean;
21
- }
22
- export interface PipelineConfig {
23
- imagePathPrefix?: string;
24
- imageBaseUrl?: string;
25
- parseOptions?: ParseOptions;
26
- }
27
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,SAAS,GACT,WAAW,GACX,MAAM,GACN,WAAW,GACX,OAAO,GACP,MAAM,GACN,WAAW,GACX,QAAQ,GACR,UAAU,CAAC;AAEf,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B"}
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};