@mathcrowd/mmarked 2.0.3 → 3.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 CHANGED
@@ -1,110 +1,346 @@
1
1
  # mmarked
2
2
 
3
- [![npm version](https://badge.fury.io/js/%40mathcrowd%2Fmmarked.svg)](https://badge.fury.io/js/%40mathcrowd%2Fmmarked)
4
- [![License: Custom](https://img.shields.io/badge/License-Custom-yellow.svg)](https://creativecommons.org/licenses/by-nc/4.0)
3
+ [![npm version](https://badge.fury.io/js/%40mathcrowd%2Fmmarked.svg)](https://www.npmjs.com/package/@mathcrowd/mmarked)
4
+ [![npm downloads](https://img.shields.io/npm/dt/@mathcrowd/mmarked.svg)](https://www.npmjs.com/package/@mathcrowd/mmarked)
5
+ [![License: CC BY-NC 4.0](https://img.shields.io/badge/License-CC%20BY--NC%204.0-yellow.svg)](https://creativecommons.org/licenses/by-nc/4.0)
5
6
 
6
7
  ![icon.png](./icon.png)
7
8
 
8
- [中文](./README.zh.md)
9
+ [中文文档](./README.zh.md) | [Demo](https://mathedu4all.github.io/mmarked/) | [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=MCLab.mmarked) | [Logseq Plugin](https://github.com/mathedu4all/mmarked-logseq-extension)
9
10
 
10
- A powerful TypeScript library for rendering customized markdown syntax with LaTeX support, designed for mathematical visualization in educational contexts.
11
+ ## 📖 Overview
11
12
 
12
- ## 🌟 Features
13
+ Transform your Markdown experience with **mmarked** - a powerful TypeScript library designed for educational and mathematical content. Built for real-time rendering of complex LaTeX formulas, theorem blocks, and custom educational syntax.
13
14
 
14
- - ✅ **Full CommonMark syntax support:** Comprehensive compatibility with CommonMark standards
15
- - 🔢 **Footnotes Blocks:** Support for auto-numbered footnotes with easy reference links
16
- - 📘 **Theorem-like blocks:** Support for mathematical theorems, lemmas, and examples in a block format with titles, auto-numbering, and reference links
17
- - 🖼️ **Image resizing capabilities:** Customizable rendering of images and videos using simple syntax
18
- - 🔍 **Hidden/Show solution blocks:** Solution blocks with toggle buttons for easy visibility control, implemented with straightforward syntax
19
- - 🧮 **TeX to SVG conversion:** Conversion of TeX equations to scalable vector graphics for high-quality rendering
20
- - 🔗 **Easy Integration with Existing Systems:** Support for both server-side and browser-side implementations
15
+ **Perfect for:**
21
16
 
22
- ## 🚀 Quick Start
17
+ - 📚 **Educators** creating math course materials
18
+ - 🎓 **Students** writing technical notes and assignments
19
+ - 📝 **Researchers** authoring academic papers
20
+ - 💻 **Developers** building educational platforms
21
+ - 💡 **Anyone** working with mathematical notation in Markdown
22
+
23
+ ## ✨ Features
24
+
25
+ ### Core Capabilities
26
+
27
+ - ✅ **Full CommonMark Support** - Complete compatibility with standard Markdown syntax
28
+ - 🔗 **Easy Integration** - Works seamlessly in Node.js and browser environments
29
+ - 📦 **Lightweight Core** - Minimal dependencies, extensible architecture
30
+ - ⚡ **High Performance** - Optimized rendering pipeline for fast output
31
+
32
+ ### Mathematical Content
33
+
34
+ - 🧮 **Advanced LaTeX Rendering** - Powered by MathJax for professional-quality formulas
35
+ - 📐 **TeX to SVG Conversion** - High-quality SVG output for equations
36
+ - 🔢 **Auto-Numbered Footnotes** - Easy-to-use reference system with automatic numbering
23
37
 
24
- ### Editor Integration
38
+ ### Educational Features
25
39
 
26
- Use mmarked in VSCode: https://marketplace.visualstudio.com/items?itemName=MCLab.mmarked
40
+ - 📘 **Theorem-Like Blocks** - Dedicated syntax for theorems, lemmas, definitions, and examples
41
+ - Auto-numbering support
42
+ - Cross-reference linking with `[~id]` syntax
43
+ - Customizable titles
44
+ - 🔍 **Collapsible Solution Blocks** - Hide/show answers and proofs with toggle functionality
45
+ - 🎯 **Syntax Highlighting** - Code blocks enhanced by highlight.js
27
46
 
28
- Use mmarked in Logseq: https://github.com/mathedu4all/mmarked-logseq-extension
47
+ ### Media & Customization
29
48
 
30
- ### Server-Side Integration
49
+ - 🖼️ **Enhanced Images** - Flexible sizing with simple `=WIDTHxHEIGHT` syntax
50
+ - 📹 **Video Support** - Same sizing options for video elements
51
+ - 🎨 **Extensible** - Built on marked.js for easy customization
31
52
 
32
- #### Installation
53
+ ## 🚀 Quick Start
54
+
55
+ ### Installation
33
56
 
34
57
  ```bash
35
58
  npm install @mathcrowd/mmarked mathjax-full highlight.js
36
59
  ```
37
60
 
38
- #### Basic Usage
61
+ ### Basic Usage
62
+
63
+ ```typescript
64
+ import { renderMarkdown } from '@mathcrowd/mmarked'
65
+
66
+ // Render markdown with LaTeX support
67
+ const result = renderMarkdown(`
68
+ # Pythagorean Theorem
69
+
70
+ \`\`\`[theorem,pythagoras,Pythagorean Theorem]
71
+ For a right triangle with sides $a$, $b$ and hypotenuse $c$:
72
+ $$a^2 + b^2 = c^2$$
73
+ \`\`\`
74
+
75
+ This fundamental theorem (see [~pythagoras]) relates the sides of right triangles.
76
+ `)
77
+
78
+ console.log(result.parsed) // HTML output
79
+ console.log(result.time) // Rendering time in ms
80
+ ```
81
+
82
+ ### License Configuration (Node.js Only)
83
+
84
+ **Important:** License validation is **only required for Node.js server-side usage**. Browser environments do not require license configuration.
85
+
86
+ For commercial use in Node.js applications, you must configure a valid license:
39
87
 
40
88
  ```typescript
41
- import { tex2svg, renderMarkdown } from '@mathcrowd/mmarked'
89
+ import { configureLicense, renderMarkdown } from '@mathcrowd/mmarked'
42
90
 
43
- // Convert TeX to SVG
44
- const svg = tex2svg('$x^2$')
91
+ // Configure your license (do this once at application startup)
92
+ configureLicense({
93
+ apiKey: 'MMARKED-XXXX-XXXX-XXXX-XXXX'
94
+ })
45
95
 
46
- // Render Markdown to HTML
47
- const html = renderMarkdown('### Heading').parsed
96
+ // Now you can use the library
97
+ const result = renderMarkdown('# Hello World')
48
98
  ```
49
99
 
50
- ### Browser-Side Integration
100
+ **Without license configuration in Node.js:**
101
+ ```typescript
102
+ import { renderMarkdown } from '@mathcrowd/mmarked'
103
+
104
+ // This will work but show a warning in console
105
+ const result = renderMarkdown('# Hello')
106
+ // Console output:
107
+ // ⚠️ No valid license configured for Node.js server-side usage.
108
+ // For commercial use, please configure a license using configureLicense().
109
+ // Contact charles@mathcrowd.cn for commercial licensing.
110
+ // Browser usage does not require a license.
111
+ ```
112
+
113
+ **Requirements:**
114
+ - **Node.js 18+** for remote license validation (uses fetch API)
115
+
116
+ **Get Your License:**
117
+ - 📧 Email: **charles@mathcrowd.cn**
118
+ - 🌐 Visit: [lab.mathcrowd.cn](https://lab.mathcrowd.cn)
119
+
120
+ ### Browser Usage
51
121
 
52
122
  ```html
53
123
  <!DOCTYPE html>
54
124
  <html>
55
125
  <head>
56
126
  <meta charset="utf-8">
57
- <title>Marked in the browser</title>
127
+ <title>mmarked Demo</title>
58
128
  </head>
59
129
  <body>
60
130
  <div id="content"></div>
61
- <script src="dist/browser.umd.js"></script>
62
- <script>
63
- const { tex2svg, renderMarkdown } = marked;
64
- document.getElementById('content').innerHTML =
65
- tex2svg(renderMarkdown('# Marked in the browser \n\n $x^2+y^2=1$ \n\nRendered by **mmarked**.').parsed);
66
- console.log(renderMarkdown('# Marked in the browser\n\nRendered by **mmarked**.').lexed);
131
+ <script type="module">
132
+ import { renderMarkdown } from 'https://cdn.jsdelivr.net/npm/@mathcrowd/mmarked/dist/index.mjs'
133
+
134
+ const markdown = `
135
+ # Einstein's Mass-Energy Equivalence
136
+
137
+ The famous equation $E = mc^2$ relates energy and mass.
138
+
139
+ **Where:**
140
+ - $E$ is energy
141
+ - $m$ is mass
142
+ - $c$ is the speed of light
143
+ `
144
+
145
+ document.getElementById('content').innerHTML = renderMarkdown(markdown).parsed
67
146
  </script>
68
147
  </body>
69
148
  </html>
70
149
  ```
71
150
 
72
- ## 📚 API Reference
151
+ ## 📚 Extended Syntax Guide
152
+
153
+ ### Theorem Blocks with Auto-Numbering
154
+
155
+ ```markdown
156
+ \`\`\`[theorem,fermat,Fermat's Last Theorem]
157
+ No three positive integers $a$, $b$, and $c$ satisfy the equation
158
+ $a^n + b^n = c^n$ for any integer value of $n > 2$.
159
+ \`\`\`
160
+
161
+ \`\`\`[lemma,helper,Helper Lemma]
162
+ This lemma supports the proof of [~fermat].
163
+ \`\`\`
164
+ ```
165
+
166
+ **Supported block types:** `theorem`, `lemma`, `corollary`, `axiom`, `definition`, `example`
167
+
168
+ **Custom blocks:** Use any keyword for custom theorem-like blocks with independent numbering.
169
+
170
+ **Hide numbering:** Add `*` after the keyword (e.g., `theorem*`) to hide the number while maintaining sequence.
171
+
172
+ ### Interactive Solution Blocks
173
+
174
+ ```markdown
175
+ **Problem:** Solve the quadratic equation $x^2 - 5x + 6 = 0$
176
+
177
+ ~~~[solution]
178
+ **Solution:**
179
+
180
+ Factoring the equation:
181
+ $$(x-2)(x-3) = 0$$
182
+
183
+ Therefore, the solutions are:
184
+ - $x = 2$
185
+ - $x = 3$
186
+ ~~~
187
+
188
+ ~~~[proof]
189
+ **Verification:** Substituting $x=2$: $(2)^2 - 5(2) + 6 = 4 - 10 + 6 = 0$ ✓
190
+ ~~~
191
+ ```
192
+
193
+ ### Enhanced Images and Videos
73
194
 
74
- | Function | Description |
75
- |----------|-------------|
76
- | `tex2svg(tex: string): string` | Converts TeX to SVG in HTML format |
77
- | `renderMarkdown(markdown: string): {parsed: string, lexed: Token[], time: number}` | Renders Markdown to HTML |
78
- | `renderMarkdownCompact(markdown: string): {parsed: string, lexed: Token[], time: number}` | Renders Markdown to HTML without `<p>` tags |
195
+ ```markdown
196
+ ![Logo](https://example.com/logo.svg "Company Logo =300x100")
79
197
 
80
- ⚠️ **Important**: Always purify the output HTML using [DOMPurify](https://github.com/cure53/DOMPurify) to prevent XSS attacks.
198
+ ![Screenshot](./images/demo.png "Demo Screenshot =800x600")
199
+ ```
200
+
201
+ ### Auto-Numbered Footnotes
202
+
203
+ ```markdown
204
+ The Riemann Hypothesis[^riemann] is one of the most important unsolved problems.
81
205
 
82
- ## 📖 Documentation
206
+ Another famous conjecture is the Twin Prime Conjecture[^twin].
83
207
 
84
- For detailed documentation in Chinese, visit our [Product Page](https://lab.mathcrowd.cn/mmarked).
208
+ [^riemann]: Proposed by Bernhard Riemann in 1859.
209
+ [^twin]: States that there are infinitely many twin primes.
210
+ ```
85
211
 
86
- ## 🎮 Demo
212
+ ## 🔧 API Reference
87
213
 
88
- Try out our interactive demo [here](https://mathedu4all.github.io/mmarked/).
214
+ ### License Management (Node.js Only)
89
215
 
90
- ## 👥 About Mathcrowd
216
+ #### `configureLicense(config: LicenseConfig)`
91
217
 
92
- Mathcrowd is an innovative startup founded by experienced independent developers and mathematics educators. We're on a mission to revolutionize math education in China through cutting-edge technology. Our goal is to create an engaging online community for math enthusiasts and self-learners, offering rich, interactive, and visualized learning content.
218
+ Configure license for commercial use in Node.js environments. Must be called before using render functions.
93
219
 
94
- 🌐 MCLab Official Website: [https://lab.mathcrowd.cn](https://lab.mathcrowd.cn)
95
- 🌐 Our Online Math Community: [https://www.mathcrowd.cn](https://www.mathcrowd.cn)
96
- 💬 Join Our Discord: [https://discord.gg/6VMUVA5Yq2](https://discord.gg/6VMUVA5Yq2)
220
+ **Parameters:**
221
+ ```typescript
222
+ interface LicenseConfig {
223
+ apiKey: string // Your license key (format: MMARKED-XXXX-XXXX-XXXX-XXXX)
224
+ }
225
+ ```
226
+
227
+ **Example:**
228
+ ```typescript
229
+ // Minimal configuration (recommended)
230
+ configureLicense({
231
+ apiKey: 'MMARKED-XXXX-XXXX-XXXX-XXXX'
232
+ })
233
+ ```
234
+
235
+ ### Core Functions
236
+
237
+ #### `renderMarkdown(markdown: string)`
238
+
239
+ Renders Markdown to HTML with full feature support.
240
+
241
+ **License:** Requires valid license for commercial use in Node.js. Free in browsers.
242
+
243
+ **Returns:**
244
+ ```typescript
245
+ {
246
+ parsed: string, // HTML output
247
+ lexed: Token[], // Marked.js tokens
248
+ time: number // Rendering time in milliseconds
249
+ }
250
+ ```
251
+
252
+ **Example:**
253
+ ```typescript
254
+ const { parsed, time } = renderMarkdown('# Hello $x^2$')
255
+ console.log(`Rendered in ${time}ms`)
256
+ ```
257
+
258
+ #### `renderMarkdownCompact(markdown: string)`
259
+
260
+ Renders Markdown without wrapping `<p>` tags, ideal for inline content.
261
+
262
+ **License:** Requires valid license for commercial use in Node.js. Free in browsers.
263
+
264
+ **Returns:** Same structure as `renderMarkdown()`
265
+
266
+ **Use case:** Rendering single-line content without block-level elements.
267
+
268
+ ```typescript
269
+ const { parsed } = renderMarkdownCompact('**Bold** and $x^2$ inline')
270
+ // Output: <strong>Bold</strong> and <svg>...</svg> inline
271
+ ```
272
+
273
+ #### `tex2svg(html: string): string`
274
+
275
+ Converts LaTeX expressions to SVG within HTML content.
276
+
277
+ **Parameters:**
278
+ - `html`: HTML string containing LaTeX expressions (`$...$` for inline, `$$...$$` for block)
279
+
280
+ **Returns:** HTML with LaTeX converted to SVG graphics
281
+
282
+ **Example:**
283
+ ```typescript
284
+ const html = '<p>Einstein: $E=mc^2$</p>'
285
+ const withSvg = tex2svg(html)
286
+ ```
287
+
288
+ ### ⚠️ Security Warning
289
+
290
+ **Always sanitize HTML output** using [DOMPurify](https://github.com/cure53/DOMPurify) before inserting into the DOM:
291
+
292
+ ```typescript
293
+ import DOMPurify from 'dompurify'
294
+ import { renderMarkdown } from '@mathcrowd/mmarked'
295
+
296
+ // Safe rendering of user input
297
+ const userMarkdown = getUserInput()
298
+ const { parsed } = renderMarkdown(userMarkdown)
299
+ const safeHtml = DOMPurify.sanitize(parsed)
300
+
301
+ document.getElementById('content').innerHTML = safeHtml
302
+ ```
303
+
304
+ ## 🔌 Editor Integrations
305
+
306
+ Enhance your editing experience with official integrations:
307
+
308
+ - **[VSCode Extension](https://marketplace.visualstudio.com/items?itemName=MCLab.mmarked)** - Real-time preview with theme support
309
+ - **[Logseq Plugin](https://github.com/mathedu4all/mmarked-logseq-extension)** - Seamless integration for note-taking
310
+
311
+ ## 📖 Documentation & Resources
312
+
313
+ - 🏠 **[Product Homepage](https://lab.mathcrowd.cn/products/mmarked)** - Official product page
314
+ - 📘 **[Complete Documentation](https://lab.mathcrowd.cn/docs/mmarked)** - Full syntax guide (Chinese)
315
+ - 🎮 **[Interactive Demo](https://mathedu4all.github.io/mmarked/)** - Try it live with quick reference built-in
316
+
317
+ ## 🏗️ Built With
318
+
319
+ - **[marked.js](https://marked.js.org/)** - Fast Markdown parser
320
+ - **[MathJax](https://www.mathjax.org/)** - Beautiful math rendering
321
+ - **[highlight.js](https://highlightjs.org/)** - Syntax highlighting
322
+
323
+ ## 🏢 About Mathcrowd
324
+
325
+ **Mathcrowd** is revolutionizing mathematics education in China through innovative technology. Founded by experienced developers and math educators, we're building tools and communities that make math learning more accessible and engaging.
326
+
327
+ - 🌐 **Mathcrowd Labs:** [lab.mathcrowd.cn](https://lab.mathcrowd.cn)
328
+ - 💬 **Join Discord:** [discord.gg/6VMUVA5Yq2](https://discord.gg/6VMUVA5Yq2)
97
329
 
98
330
  ## 📄 License
99
331
 
100
- See [LICENSE](./LICENSE.md)
332
+ Licensed under [CC BY-NC 4.0](./LICENSE.md) - Free for non-commercial use.
333
+
334
+ For commercial licensing, contact: **charles@mathcrowd.cn**
335
+
336
+ ## 💬 Support
101
337
 
102
- For commercial use, please contact charles@mathcrowd.cn for licensing details.
338
+ - 💡 **Feature Requests:** [GitHub Discussions](https://github.com/mathedu4all/mmarked/discussions)
103
339
 
104
- ## 🤝 Contributing
340
+ ---
105
341
 
106
- We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for more details.
342
+ <div align="center">
107
343
 
108
- ## 📞 Support
344
+ Made with ❤️ by the [Mathcrowd](https://mathcrowd.cn) team
109
345
 
110
- For questions or issues, please [open an issue](https://github.com/mathedu4all/mathcrowd-marked-lib/issues) on our GitHub repository.
346
+ </div>