mr-md 1.0.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.
- package/README.md +24 -0
- package/dist/builder.d.ts +169 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +545 -0
- package/dist/client/app.js +314 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/renderer/blocks.d.ts +15 -0
- package/dist/renderer/blocks.d.ts.map +1 -0
- package/dist/renderer/blocks.js +365 -0
- package/dist/renderer/html.d.ts +8 -0
- package/dist/renderer/html.d.ts.map +1 -0
- package/dist/renderer/html.js +141 -0
- package/dist/renderer/index.d.ts +4 -0
- package/dist/renderer/index.d.ts.map +1 -0
- package/dist/renderer/index.js +381 -0
- package/dist/renderer/markdown.d.ts +13 -0
- package/dist/renderer/markdown.d.ts.map +1 -0
- package/dist/renderer/markdown.js +143 -0
- package/dist/renderer/utils.d.ts +10 -0
- package/dist/renderer/utils.d.ts.map +1 -0
- package/dist/renderer/utils.js +59 -0
- package/dist/styles/theme.css +1258 -0
- package/dist/types.d.ts +207 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/package.json +62 -0
- package/src/builder.ts +708 -0
- package/src/client/app.js +314 -0
- package/src/index.ts +34 -0
- package/src/renderer/blocks.ts +452 -0
- package/src/renderer/html.ts +163 -0
- package/src/renderer/index.ts +401 -0
- package/src/renderer/markdown.ts +193 -0
- package/src/renderer/utils.ts +84 -0
- package/src/styles/theme.css +1258 -0
- package/src/types.ts +288 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Mr Markdown
|
|
2
|
+
|
|
3
|
+
Mr Markdown is an opinionated TypeScript SDK for building interactive, single-file learning pages. It is designed for lessons that mix prose, LaTeX, simulations, media, video, and quizzes without making every author build layout and interaction chrome from scratch.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
The documentation has been split into dedicated guides. Start with the Quick Start, and then explore the core features:
|
|
8
|
+
|
|
9
|
+
1. [Quick Start](./docs/quickstart.md) - Learn how to build your first lesson.
|
|
10
|
+
2. [Core Blocks](./docs/core-blocks.md) - An overview of the API and layout components (markdown, math, media, callouts).
|
|
11
|
+
3. [Simulations & Interactivity](./docs/simulations.md) - The definitive guide for building and integrating sandboxed JavaScript simulations, including zero-config companion files.
|
|
12
|
+
4. [Themes and Styling](./docs/themes-and-styling.md) - Learn how to customize fonts, colors, and hook into Dark Mode.
|
|
13
|
+
5. [Quizzes](./docs/quizzes.md) - Learn the JSON format for injecting interactive quizzes.
|
|
14
|
+
6. [Production Checks](./docs/production-checks.md) - Understand Mr Markdown's strict mode and quality enforcement.
|
|
15
|
+
|
|
16
|
+
## Example
|
|
17
|
+
|
|
18
|
+
To see a full example in action, compile the included `charge.lesson.ts`:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx ts-node example/charge.lesson.ts
|
|
22
|
+
# or
|
|
23
|
+
bun example/charge.lesson.ts
|
|
24
|
+
```
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { AnimationOptions, BuildOptions, CalloutBlock, Chapter, ColumnItem, ColumnsOptions, LatexOptions, Lesson, LessonMeta, MediaOptions, QuizBlock, SimulationOptions, YouTubeOptions } from "./types.js";
|
|
2
|
+
export declare class LessonBuilder {
|
|
3
|
+
private meta;
|
|
4
|
+
private blocks;
|
|
5
|
+
private options;
|
|
6
|
+
private _rawOptions;
|
|
7
|
+
constructor(title: string, options?: BuildOptions);
|
|
8
|
+
/**
|
|
9
|
+
* Sets the URL slug for the generated HTML file.
|
|
10
|
+
* Automatically generated from the title by default.
|
|
11
|
+
*/
|
|
12
|
+
slug(slug: string): this;
|
|
13
|
+
/**
|
|
14
|
+
* Sets the SEO meta description and subheading for the lesson.
|
|
15
|
+
*/
|
|
16
|
+
description(text: string): this;
|
|
17
|
+
/** Assigns taxonomy tags to the lesson. */
|
|
18
|
+
tags(...tags: string[]): this;
|
|
19
|
+
/** Sets the author name for this lesson. */
|
|
20
|
+
author(name: string): this;
|
|
21
|
+
/**
|
|
22
|
+
* Sets the progression status of the lesson.
|
|
23
|
+
* Used to visually distinguish read/unread/locked lessons in Chapter timelines.
|
|
24
|
+
*/
|
|
25
|
+
status(status: "read" | "unread" | "locked"): this;
|
|
26
|
+
/** Curated production defaults for the generated lesson shell. */
|
|
27
|
+
preset(preset: NonNullable<BuildOptions["preset"]>): this;
|
|
28
|
+
/** @internal Used by ChapterBuilder to push down shared config */
|
|
29
|
+
_inheritOptions(parentOpts: BuildOptions): void;
|
|
30
|
+
/** @internal Used by ChapterBuilder */
|
|
31
|
+
_setParentSlug(slug: string): void;
|
|
32
|
+
/** @internal Used by ChapterBuilder */
|
|
33
|
+
_setPrev(slug: string, title: string): void;
|
|
34
|
+
/** @internal Used by ChapterBuilder */
|
|
35
|
+
_setNext(slug: string, title: string): void;
|
|
36
|
+
/** @internal Used by ChapterBuilder */
|
|
37
|
+
_getMeta(): LessonMeta;
|
|
38
|
+
/**
|
|
39
|
+
* Smart helper that automatically infers the correct block type from the file extension or URL.
|
|
40
|
+
* Allows authors to quickly sequence a lesson without memorizing specific block methods.
|
|
41
|
+
*/
|
|
42
|
+
add(src: `${string}.md` | `${string}.mdx`): this;
|
|
43
|
+
add(src: `${string}.json`, opts?: Pick<QuizBlock, "label" | "caption">): this;
|
|
44
|
+
add(src: `${string}.mp4` | `${string}.webm` | `${string}.mov`, opts?: Omit<MediaOptions, "kind">): this;
|
|
45
|
+
add(src: `${string}.mp3` | `${string}.wav` | `${string}.ogg` | `${string}.m4a`, opts?: Omit<MediaOptions, "kind">): this;
|
|
46
|
+
add(src: `${string}.png` | `${string}.jpg` | `${string}.jpeg` | `${string}.gif` | `${string}.svg` | `${string}.webp` | `${string}.avif`, opts?: Omit<MediaOptions, "kind">): this;
|
|
47
|
+
add(src: string, opts?: any): this;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a major chapter heading (H2) and a top-level sidebar navigation entry.
|
|
50
|
+
* @param src Path to a markdown file or raw markdown string.
|
|
51
|
+
* @param title Optional title override for the sidebar and heading.
|
|
52
|
+
* @example lesson.heading("# Welcome to Physics")
|
|
53
|
+
*/
|
|
54
|
+
heading(src: string, title?: string): this;
|
|
55
|
+
/**
|
|
56
|
+
* Adds standard markdown prose into the current section.
|
|
57
|
+
* @param src Path to a markdown file or raw markdown string.
|
|
58
|
+
* @example lesson.markdown("This is a **bold** statement.")
|
|
59
|
+
*/
|
|
60
|
+
markdown(src: string): this;
|
|
61
|
+
/**
|
|
62
|
+
* Alias for `markdown()`. Keeps authoring readable in long lessons.
|
|
63
|
+
* @example lesson.content("content/intro.md")
|
|
64
|
+
*/
|
|
65
|
+
content(src: string): this;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new subsection heading (H3) and a sub-entry in the sidebar.
|
|
68
|
+
* @param src Path to a markdown file or raw markdown string.
|
|
69
|
+
* @param label Optional title override for the sidebar label.
|
|
70
|
+
* @example lesson.section("### 1. Kinematics")
|
|
71
|
+
*/
|
|
72
|
+
section(src: string, label?: string): this;
|
|
73
|
+
/**
|
|
74
|
+
* Adds an 'Important' highlighted callout.
|
|
75
|
+
* @example lesson.important("Do not touch the exposed wire.")
|
|
76
|
+
*/
|
|
77
|
+
important(src: string): this;
|
|
78
|
+
/**
|
|
79
|
+
* Adds a 'Warning' highlighted callout.
|
|
80
|
+
* @example lesson.warning("This is deprecated.")
|
|
81
|
+
*/
|
|
82
|
+
warning(src: string): this;
|
|
83
|
+
/**
|
|
84
|
+
* Adds a 'Tip' highlighted callout.
|
|
85
|
+
*/
|
|
86
|
+
tip(src: string): this;
|
|
87
|
+
/**
|
|
88
|
+
* Adds a 'Note' highlighted callout.
|
|
89
|
+
*/
|
|
90
|
+
note(src: string): this;
|
|
91
|
+
callout(type: CalloutBlock["type"], src: string): this;
|
|
92
|
+
/**
|
|
93
|
+
* Adds a syntax-highlighted code block.
|
|
94
|
+
* @param src Path to a code file or raw code string.
|
|
95
|
+
* @param lang Explicit language for highlighting (e.g. "ts", "python").
|
|
96
|
+
* @param label Optional file name or label to display above the code block.
|
|
97
|
+
*/
|
|
98
|
+
code(src: string, lang?: string, label?: string): this;
|
|
99
|
+
latex(tex: string, opts?: LatexOptions): this;
|
|
100
|
+
columns(columns: ColumnItem[], opts?: ColumnsOptions): this;
|
|
101
|
+
private loadSimulationConfig;
|
|
102
|
+
/**
|
|
103
|
+
* Mounts a sandboxed JavaScript simulation or interactive applet.
|
|
104
|
+
* @param src Path to the JavaScript simulation code.
|
|
105
|
+
* @param opts Configuration options including tunables, height, and aspect ratio.
|
|
106
|
+
* @param height Optional fixed iframe height in pixels.
|
|
107
|
+
* @example lesson.simulation("sims/pendulum.js", { height: 500 })
|
|
108
|
+
*/
|
|
109
|
+
simulation(src: string, opts?: SimulationOptions | Record<string, unknown>, height?: number): this;
|
|
110
|
+
/**
|
|
111
|
+
* Opinionated alias for `simulation()`, configured specifically for interactive physics/math labs.
|
|
112
|
+
* Sets the default interaction mode to fully interactive.
|
|
113
|
+
* @param src Path to the JavaScript simulation code.
|
|
114
|
+
* @param opts Configuration options.
|
|
115
|
+
* @example lesson.lab("sims/optics-lab.js")
|
|
116
|
+
*/
|
|
117
|
+
lab(src: string, opts?: SimulationOptions): this;
|
|
118
|
+
/** Passive animation player */
|
|
119
|
+
animation(src: string, opts?: AnimationOptions): this;
|
|
120
|
+
media(src: string, opts?: MediaOptions): this;
|
|
121
|
+
image(src: string, opts?: Omit<MediaOptions, "kind">): this;
|
|
122
|
+
video(src: string, opts?: Omit<MediaOptions, "kind">): this;
|
|
123
|
+
youtube(idOrUrl: string, opts?: YouTubeOptions): this;
|
|
124
|
+
audio(src: string, opts?: Omit<MediaOptions, "kind">): this;
|
|
125
|
+
/**
|
|
126
|
+
* Injects an interactive multiple-choice quiz block.
|
|
127
|
+
* @param src Path to a .json file conforming to the `QuizFile` schema.
|
|
128
|
+
* @param opts Optional label and caption for the quiz block wrapper.
|
|
129
|
+
*/
|
|
130
|
+
quiz(src: string, opts?: Pick<QuizBlock, "label" | "caption">): this;
|
|
131
|
+
/** Visual separator */
|
|
132
|
+
divider(): this;
|
|
133
|
+
/** Returns the raw Lesson object (useful for testing or custom rendering) */
|
|
134
|
+
toJSON(): Lesson;
|
|
135
|
+
/** Compiles everything and writes a single .html file to outDir */
|
|
136
|
+
build(): string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Starts building a new interactive lesson.
|
|
140
|
+
* @param title The display title for the lesson.
|
|
141
|
+
* @param options Build configuration for this specific lesson.
|
|
142
|
+
* @example const l = lesson("Introduction to Kinematics").markdown("intro.md");
|
|
143
|
+
*/
|
|
144
|
+
export declare function lesson(title: string, options?: BuildOptions): LessonBuilder;
|
|
145
|
+
export declare class ChapterBuilder {
|
|
146
|
+
private meta;
|
|
147
|
+
private lessonBuilders;
|
|
148
|
+
private options;
|
|
149
|
+
constructor(title: string, options?: BuildOptions);
|
|
150
|
+
slug(slug: string): this;
|
|
151
|
+
description(text: string): this;
|
|
152
|
+
status(status: "completed" | "active" | "locked"): this;
|
|
153
|
+
lesson(lessonBuilder: LessonBuilder): this;
|
|
154
|
+
build(): string;
|
|
155
|
+
/** Returns the raw Chapter object */
|
|
156
|
+
toJSON(): Chapter;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Starts building a new chapter that groups multiple lessons together.
|
|
160
|
+
* @param title The display title for the chapter.
|
|
161
|
+
* @param options Shared build configuration that cascades to all child lessons.
|
|
162
|
+
* @example
|
|
163
|
+
* chapter("Mechanics")
|
|
164
|
+
* .lesson(kinematicsLesson)
|
|
165
|
+
* .lesson(dynamicsLesson)
|
|
166
|
+
* .build();
|
|
167
|
+
*/
|
|
168
|
+
export declare function chapter(title: string, options?: BuildOptions): ChapterBuilder;
|
|
169
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.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