markdown2typst 0.1.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 zhaoyiqun
4
+ Copyright (c) 2026 Mapaor
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # markdown2typst
2
+
3
+ A JavaScript library for converting Markdown to [Typst](https://typst.app/) code.
4
+
5
+ ## Try it online
6
+ See an example use case in this demo website: [https://markdown2typst.vercel.app](https://markdown2typst.vercel.app).
7
+
8
+ ## Supported Markdown features
9
+ ### GitHub Flavored Markdown (GFM)
10
+ - ✔ Headings
11
+ - ✔ Bold, italics, striketrought, code
12
+ - ✔ Bulleted lists, numbered lists
13
+ - ✔ Links
14
+ - ✔ Images (only local)
15
+ - ✔ Math (inline and block equations)
16
+ - ✔ Tables
17
+ - ✔ Quotes
18
+ - ✔ Code blocks (with highlighting)
19
+ - ✔ Dividers (horizontal rule)
20
+ - ✔ Footnotes
21
+ - ✔ Table of Contents (ToC)
22
+ - ✘ Mermaid diagrams --> Coming soon(!)
23
+ - ✘ Checklists --> Coming soon(!)
24
+ - ✘ HTML, GeoJSON, STL --> Not Typst compatible.
25
+
26
+ ### Markdown Frontmatter
27
+ Only works with YAML for now, TOML support is planned.
28
+
29
+ Currently supported keys:
30
+ - `title` (rich text string)
31
+ - `author` (string or array of strings)
32
+ - `description` (string)
33
+ - `keywords` (array of strings)
34
+ - `date` (YYYY-MM-DD string)
35
+ - `abstract` (rich text string)
36
+ - `lang` (string)
37
+ - `region` (string)
38
+
39
+ For more information see [Typst Document Function](https://typst.app/docs/reference/model/document/), [Jekyll Frontmatter Docs](https://jekyllrb.com/docs/front-matter/) or check the [examples](./examples/full-frontmatter.md).
40
+
41
+ <details>
42
+ <summary>Chosen display of the front-matter keys or custom options parameters (example)</summary>
43
+
44
+ ### Chosen design
45
+ By design the choice has been to support mainly the Typst document parameters, that in principle are just metadata. However the title, and author and date are also displayed. Those could be displayed in any way in Typst, the chosen one has been the more basic and default way: simply non-style top-centered Title, author and date. With newlines between them. Support for setting the language and a custom abstract in the frontmatter (or custom options) has also been added.
46
+
47
+ ### Example
48
+
49
+ The following is a complete Markdown example of all the supported front-matter keys:
50
+ ```
51
+ ---
52
+ title: The Fellowship of the Ring
53
+ author:
54
+ - John Doe
55
+ - Jack Doe
56
+ - Jane Doe
57
+ description: This is just an example document, this information is in principle stored as metadata only but it can be displayed using context document.
58
+ keywords:
59
+ - example
60
+ - document
61
+ - lotr
62
+ - typst
63
+ date: 2026-01-12
64
+ abstract: In this paper we assess the impacts of the One Ring on Middle Earth and its inhabitants, analyzing both economic and social factors.
65
+ lang: en
66
+ region: gb
67
+ ---
68
+ ```
69
+
70
+ And the corresponding Typst output is:
71
+ ```
72
+ // =============== FRONTMATTER ===============
73
+
74
+ #set document(
75
+ title: [The Fellowship of the Ring],
76
+ author: ("John Doe", "Jack Doe", "Jane Doe"),
77
+ description: [This is just an example document, this information is in principle stored as metadata only but it can be displayed using context document.],
78
+ keywords: ("example", "document", "lotr", "typst"),
79
+ date: datetime(day: 12, month: 1, year: 2026)
80
+ )
81
+
82
+ #let abstract = [In this paper we assess the impacts of the One Ring on Middle Earth and its inhabitants, analyzing both economic and social factors.]
83
+
84
+ #align(center)[
85
+ #title() \ \ #context document.author.join(", ", last: " & ") \ \ #context document.date.display() \ \ \ *Abstract* \ #abstract
86
+ ]
87
+
88
+ #set text(lang: "en", region: "gb")
89
+
90
+ // ============================================
91
+ ```
92
+ </details>
93
+
94
+ <br>
95
+
96
+ Note: any non-standard key is simply ignored, all keys are optional. The front-matter as a whole is obviously also optional.
97
+
98
+ ## Installation
99
+
100
+ ### NPM package (for Node.js projects)
101
+
102
+ ```bash
103
+ npm install tex2typst
104
+ ```
105
+
106
+ ### JS Bundle
107
+
108
+ Available both on JSDeliver and Unpkg.
109
+
110
+ #### JSDelivr
111
+
112
+ ##### JSDelivr NPM
113
+
114
+ ```
115
+ <script src="https://cdn.jsdelivr.net/npm/..."></script>
116
+ ```
117
+
118
+ ##### JSDelivr GitHub Link
119
+
120
+ ```
121
+ <script src="https://cdn.jsdelivr.net/gh/..."></script>
122
+ ```
123
+
124
+ The link points to the `markdown2typst.min.js` file of this repository (inside the `dist` folder).
125
+
126
+ #### Unpkg (NPM link)
127
+
128
+ ```
129
+ <script src="https://unpkg.com/..."></script>
130
+ ```
131
+
132
+ ### Build from source
133
+
134
+ ```bash
135
+ # Clone the repository
136
+ git clone https://github.com/Mapaor/markdown2typst.git
137
+ cd markdown2typst
138
+
139
+ # Install dependencies
140
+ npm install
141
+ ```
142
+ Make the desired changes to the library (`markdown2typst.ts` file) and then build from source
143
+ ```bash
144
+ # Build the bundle
145
+ npm run build
146
+ ```
147
+ The updated javascript bundle will appear in the `dist` folder.
148
+
149
+ ## Usage
150
+
151
+ ### Simple usage
152
+
153
+ #### Using the bundle
154
+
155
+ ##### In Node.js (ESM) - Locally
156
+ ```javascript
157
+ import { markdown2typst } from './dist/markdown2typst.min.js';
158
+
159
+ const markdown = '# Hello Typst\n\nThis is a **test**.';
160
+ const typst = markdown2typst(markdown);
161
+ console.log(typst);
162
+ ```
163
+
164
+ ##### In the browser - Locally
165
+ ```html
166
+ <script type="module">
167
+ import { markdown2typst } from './dist/markdown2typst.min.js';
168
+
169
+ const markdown = '# Hello Typst';
170
+ const typst = markdown2typst(markdown);
171
+ console.log(typst);
172
+ </script>
173
+ ```
174
+
175
+
176
+ #### Using the library - Locally
177
+
178
+ ```typescript
179
+ import { markdown2typst } from './src/markdown2typst';
180
+
181
+ const markdown = `
182
+ # My Document
183
+
184
+ This is a paragraph with **bold** and *italic* text.
185
+
186
+ ## Features
187
+
188
+ - Item 1
189
+ - Item 2
190
+ `;
191
+
192
+ const typst = markdown2typst(markdown);
193
+ console.log(typst);
194
+ ```
195
+
196
+ ### Advanced usage
197
+
198
+ See the [Examples](/examples/README.md) page for advanced examples on how to use the library.
199
+
200
+ ## Internal architecture
201
+ Check the [Architecture](./ARCHITECTURE.md) doc for getting a better understanding of how the library works under the hood.
202
+
203
+ ## Contributing
204
+ Contributions are more than welcome! See the [Contributing](./CONTRIBUTING.md) guide.
205
+
206
+ ## License
207
+
208
+ [MIT License](LICENSE)
209
+
210
+ ## Acknowledgments
211
+
212
+ Built thanks to the following open-source projects:
213
+ - [unified](https://unifiedjs.com/) - Text processing framework
214
+ - [remark](https://github.com/remarkjs/remark) - Markdown processor. Plugins used:
215
+ - [remark-frontmatter](https://github.com/remarkjs/remark-frontmatter)
216
+ - [remark-gfm](https://github.com/remarkjs/remark-gfm)
217
+ - [remark-math](https://github.com/remarkjs/remark-math)
218
+ - [remark-parse](https://github.com/remarkjs/remark/tree/main)
219
+ - [esbuild](https://esbuild.github.io/) - Fast bundler
220
+ - [tex2typst](https://github.com/qwinsi/tex2typst) - Typst conversion for LaTeX equations
221
+
222
+ This code is mainly based on the code by zhaoyiqun (@cosformula on GitHub), more specifically in his [markdownToTypst.ts](https://github.com/cosformula/mdxport/blob/main/src/lib/pipeline/markdownToTypst.ts) custom conversion library (renderer to Typst code) built for his open source project [MDXport](https://mdxport.com).
223
+
224
+ ## Roadmap
225
+
226
+ - [X] Finish an initial working version
227
+ - [X] Add frontmatter support and also allow to pass the keys as custom options of the main function
228
+ - [ ] Publish to npm
229
+ - [ ] Add a comprehensive test suite
230
+ - [ ] Add CLI tool
231
+ - [ ] Support custom templates
232
+ - [ ] Support more Markdown extensions/flavors/specs