Repository navigation
Expand file tree
/
Copy pathmarkdown.ts
More file actions
154 lines (143 loc) · 4.27 KB
/
Copy pathmarkdown.ts
File metadata and controls
154 lines (143 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* markdown.ts :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dlesieur <dlesieur@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/28 22:26:00 by dlesieur #+# #+# */
/* Updated: 2026/05/11 21:03:59 by dlesieur ### ########.fr */
/* */
/* ************************************************************************** */
import { parseMarkdown as parseDocument } from "./src/block-parser";
import { parseInlines as parseInlineNodes } from "./src/inline-parser";
import {
renderHtml as renderDocumentHtml,
type RenderHtmlOptions,
} from "./src/renderer";
import {
renderMarkdownSource,
type SourceRenderOptions,
} from "./src/source-renderer";
import { incrementalParse as incrementalParseFromSource } from "./src/incremental";
import {
resolveIndexedMarkdownMode,
resolveMarkdownMode,
// ReadingMode,
// LivePreviewMode,
// SourceMode,
type MarkdownModeResolver,
type MarkdownModeState,
type MarkdownViewMode,
} from "./src/render-mode";
import type {
DocumentNode,
IncrementalParseResult,
IncrementalPatch,
InlineNode,
ParseOptions,
ParseResult,
} from "./src/types";
export type {
BlockNode,
DocumentNode,
IncrementalParseResult,
IncrementalPatch,
InlineNode,
ParseOptions,
ParseResult,
} from "./src/types";
export type { SourceRenderOptions } from "./src/source-renderer";
export type { RenderHtmlOptions } from "./src/renderer";
export type {
MarkdownModeResolver,
MarkdownModeState,
MarkdownViewMode,
} from "./src/render-mode";
export { ReadingMode, LivePreviewMode, SourceMode } from "./src/render-mode";
export {
DEFAULT_MARKENGINE_WORKER_SYNC_THRESHOLD_BYTES,
MarkEngineWorker,
createBrowserMarkEngineWorkerClient,
type MarkEngineWorkerEndpoint,
type MarkEngineWorkerOptions,
type MarkEngineWorkerRenderOptions,
} from "./src/worker-client";
export {
createNodeMarkEngineWorkerClient,
type NodeMarkEngineWorkerOptions,
} from "./src/node-worker-client";
export function parseMarkdown(
source: string,
options: ParseOptions = {},
): ParseResult {
return parseDocument(source, options);
}
export function parseInlines(source: string, line = 0): InlineNode[] {
return parseInlineNodes(source, line);
}
export function renderHtml(
ast: DocumentNode,
options: RenderHtmlOptions = {},
): string {
return renderDocumentHtml(ast, options);
}
export function compileMarkdownToHtml(
source: string,
options: ParseOptions = {},
renderOptions: RenderHtmlOptions = {},
): {
html: string;
ast: DocumentNode;
} {
const result = parseMarkdown(source, options);
return {
html: renderHtml(result.ast, renderOptions),
ast: result.ast,
};
}
export function renderSource(
source: string,
options: SourceRenderOptions = {},
): string {
return renderMarkdownSource(source, options);
}
export function compileMarkdownToSourceView(
source: string,
options: ParseOptions = {},
sourceOptions: SourceRenderOptions = {},
): {
html: string;
ast: DocumentNode;
} {
const result = parseMarkdown(source, options);
return {
html: renderSource(source, sourceOptions),
ast: result.ast,
};
}
export function resolveModeState(mode?: MarkdownViewMode): MarkdownModeState {
return resolveMarkdownMode(mode);
}
export function resolveIndexedModeState<TNode>(
fallbackMode: MarkdownViewMode | undefined,
index: number,
node: TNode,
indexedModes?: readonly MarkdownViewMode[],
resolver?: MarkdownModeResolver<TNode>,
): MarkdownModeState {
return resolveIndexedMarkdownMode(
fallbackMode,
index,
node,
indexedModes,
resolver,
);
}
export function incrementalParse(
previousText: string,
previousResult: ParseResult,
patch: IncrementalPatch,
): IncrementalParseResult {
return incrementalParseFromSource(previousText, previousResult, patch);
}