Skip to content

Commit 4d8389d

Browse files
committed
docs update
1 parent a0e547d commit 4d8389d

6 files changed

Lines changed: 33 additions & 317 deletions

File tree

ARCHITECTURE.md

Lines changed: 13 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Architecture
22

3-
This document explains the internal architecture of the markdown2typst.
4-
53
## Overview
4+
Here is an overview of the phases the library has when processing Markdown code to Typst code.
65

76
```
87
Markdown Input
@@ -28,24 +27,24 @@ The converter uses the unified/remark ecosystem to parse Markdown:
2827
- **remark-parse**: Parses Markdown to MDAST (Markdown Abstract Syntax Tree)
2928
- **remark-gfm**: Adds GitHub Flavored Markdown support (tables, strikethrough, code blocks...)
3029
- **remark-math**: Adds math equation support
31-
- **remark-frontmatter**: Parses YAML frontmatter
30+
- **remark-frontmatter (and js-yaml)**: Parses YAML frontmatter
3231

3332
### 2. AST Processing
3433

3534
After parsing, we process the AST to:
3635

3736
1. **Extract Metadata**:
3837
- Parse YAML frontmatter for title, authors, date, language, region, description and abstract
39-
- Find leading H1 as potential title (metadata only in that case)
40-
- Merge with user-provided options and in case of conflict options override front-matter
38+
- Find leading H1 as potential title
39+
- Merge with custom options if provided and in case of conflict options override front-matter
4140

4241
2. **Collect Definitions**:
4342
- Link reference definitions: `[id]: url`
4443
- Footnote definitions: `[^id]: content`
4544

4645

4746
### 3. Rendering
48-
The rendering phase walks the AST and converts each node to Typst syntax:
47+
The rendering phase iterates the AST and converts each node to Typst syntax:
4948

5049
#### Block-Level Rendering
5150

@@ -70,33 +69,7 @@ The rendering phase walks the AST and converts each node to Typst syntax:
7069
- **Footnotes**: Inline with `#footnote[]`
7170

7271

73-
## Key Design Decisions
74-
75-
### 1. Function Form for Formatting
76-
77-
We use Typst function forms (`#strong[]`, `#emph[]`) instead of markup forms (`*text*`, `_text_`):
78-
79-
**Advantages**:
80-
- Unambiguous parsing (no conflicts with `*` in comments or math)
81-
- Consistent with other Typst features
82-
- Easier to nest and compose
83-
84-
**Trade-off**: Slightly more verbose output
85-
86-
### 2. Reference Resolution
87-
88-
Link and footnote references are resolved at render time:
89-
90-
```typescript
91-
const definitions = collectDefinitions(tree);
92-
const footnoteDefinitions = collectFootnotes(tree);
93-
// Later, during rendering:
94-
const def = definitions.get(identifier);
95-
```
96-
97-
This allows reference-style links to work correctly.
98-
99-
### 3. Indentation Handling
72+
### Note on indentation handling
10073

10174
All rendering functions accept an `indentLevel` parameter for proper nesting:
10275

@@ -107,19 +80,14 @@ function renderBlock(node, indentLevel, definitions, footnotes) {
10780
}
10881
```
10982

110-
This ensures nested lists and blockquotes are properly formatted.
111-
112-
### 4. Type Safety
83+
## Contributing
11384

114-
The codebase uses TypeScript with strict mode for maximum type safety:
85+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on extending the code.
11586

116-
- All MDAST node types are imported from `@types/mdast`
117-
- Custom node types (math, mark, etc.) extend standard types
118-
- Exported options are fully typed
11987

120-
## Extension Points
88+
### How to add new Markdown features
12189

122-
### Adding New Markdown Features
90+
Here are some hints:
12391

12492
1. Add remark plugin to parser:
12593
```typescript
@@ -128,108 +96,19 @@ const processor = unified()
12896
.use(remarkNewFeature)
12997
```
13098

131-
2. Define custom node type if needed:
99+
1. Define custom node type if needed:
132100
```typescript
133101
interface NewFeatureNode extends Literal {
134102
type: 'newFeature';
135103
// additional fields
136104
}
137105
```
138106

139-
3. Add rendering logic:
107+
1. Add rendering logic:
140108
```typescript
141109
function renderNewFeature(node: NewFeatureNode): string {
142110
// Convert to Typst
143111
}
144112
```
145113

146-
4. Update the main switch statement in `renderBlock` or `renderInline`
147-
148-
## Performance Considerations
149-
150-
### Current Performance
151-
152-
The converter is designed for **clarity over performance**, suitable for:
153-
- Interactive editors (sub-second conversion for typical documents)
154-
- Build processes (hundreds of documents per minute)
155-
- Browser environments (client-side conversion)
156-
157-
### Optimization Opportunities
158-
159-
If performance becomes critical:
160-
161-
1. **Memoization**: Cache rendered subtrees
162-
2. **Streaming**: Process large documents in chunks
163-
3. **Worker Threads**: Parallelize conversion of multiple files
164-
4. **AST Caching**: Cache parsed AST for unchanged documents
165-
166-
## Testing Strategy
167-
168-
Currently, the project focuses on:
169-
170-
1. **Manual Testing**: Example files in `examples/`
171-
2. **Type Checking**: TypeScript used for type safety
172-
3. **Visual Inspection**: Compare Markdown input with Typst output
173-
174-
### Future Testing
175-
176-
Recommended additions:
177-
178-
1. **Unit Tests**: Test individual rendering functions
179-
2. **Integration Tests**: Full Markdown → Typst conversion
180-
3. **Snapshot Tests**: Compare against known-good outputs
181-
4. **Fuzz Testing**: Random/malformed input handling
182-
5. **Users Testing**: In the work in progress demo website
183-
184-
## Build System
185-
186-
The build system uses esbuild for fast bundling:
187-
188-
### Output Formats
189-
190-
1. **dist/markdown2typst.min.js**: Production bundle (minified)
191-
2. **dist/markdown2typst.js**: Development bundle (readable)
192-
3. **Source maps**: For debugging bundled code
193-
194-
### Configuration
195-
196-
```javascript
197-
{
198-
format: "esm", // ES modules
199-
target: ["es2020"], // Modern JavaScript
200-
platform: "browser", // Browser-compatible
201-
bundle: true // Single file output
202-
}
203-
```
204-
205-
## Dependencies
206-
207-
### Runtime Dependencies
208-
209-
- **unified**: Text processing framework
210-
- **remark-parse**: Markdown parser
211-
- **remark-gfm**: GitHub Flavored Markdown
212-
- **remark-math**: Math equation support
213-
- **remark-frontmatter**: YAML frontmatter parser
214-
215-
### Development Dependencies
216-
217-
- **typescript**: Type checking and definitions
218-
- **esbuild**: Fast bundler
219-
- **@types/mdast**: MDAST type definitions
220-
221-
## Future Enhancements
222-
223-
Potential improvements:
224-
225-
1. **CLI Tool**: Command-line interface for file conversion
226-
2. **VS Code Extension**: Live preview and conversion
227-
3. **Custom Templates**: User-provided template system
228-
4. **Plugin System**: Allow third-party extensions
229-
5. **Caching**: Improve performance for large documents
230-
6. **Validation**: Verify Typst output syntax
231-
7. **Source Maps**: Map Typst back to Markdown for errors
232-
233-
## Contributing
234-
235-
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on extending the codebase.
114+
1. Update the main switch statement in `renderBlock` or `renderInline`

CHANGELOG.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [0.1.1 (Unreleased)] - 2026-01-14
9-
10-
### Added
11-
- Comprehensive documentation with examples
12-
- JSDoc comments throughout codebase
13-
- Enhanced build system with multiple output formats
14-
- Example files demonstrating usage
15-
- TypeScript support with type definitions
16-
17-
### Changed
18-
- Improved package.json metadata
19-
- Enhanced README with API documentation
20-
- Better project structure
21-
228
## [0.1.0] - 2026-01-11
239

2410
### Added

CONTRIBUTING.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
Thank you for considering contributing to markdown2typst! This document provides guidelines for contributing to the project.
44

5-
## Code of Conduct
6-
7-
Be respectful, constructive, and professional in all interactions.
8-
95
## How Can I Contribute?
106

117
### Reporting Bugs
@@ -40,6 +36,9 @@ npm run typecheck
4036

4137
# Or...
4238
npx tsc --noEmit
39+
40+
# And test
41+
npm run test
4342
```
4443

4544
## Guidelines
@@ -52,7 +51,7 @@ npx tsc --noEmit
5251
- Use meaningful variable and function names
5352
- Provide usage examples if you add a new feature
5453

55-
#### Example:
54+
#### Example JSDoc comments:
5655

5756
```typescript
5857
/**
@@ -74,18 +73,18 @@ export function markdown2typst(markdown: string, options?: Options): string {
7473

7574
### Testing guidelines
7675
When adding new features:
77-
78-
- Test with various Markdown inputs
79-
- Verify Typst output is syntactically correct
76+
- Ensure all tests pass (`npm run test`)
77+
- Test with various Markdown inputs related to your new feature
78+
- Verify Typst output is syntactically correct and can compile in the [Typst.app](https://typst.app)
8079
- Check edge cases (empty strings, special characters, etc.)
8180

8281
### Documentation guidelines
83-
If you add a new features or make important changes to the code
82+
If you add a new features or make important changes to the code please document them as well
8483

85-
1. Update the main README.md documenting it
84+
1. Update the main README.md if needed
8685
2. If possible add examples to the `examples/` directory
8786

8887
## Questions?
8988

90-
Feel free to open an issue with your question or reach out to pardo.marti@gmail.com.
89+
Feel free to open an issue with your question or reach out at pardo.marti@gmail.com.
9190

0 commit comments

Comments
 (0)