Skip to content

Commit 1031279

Browse files
committed
Docs.
1 parent 709a698 commit 1031279

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/why-djot.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,54 @@ Markdown was designed in 2004 as a simple format for writing blog posts. Twenty
1010
2. **Ambiguous syntax** - `_` and `*` behave differently based on context
1111
3. **Limited features** - no highlighting, attributes, or consistent extensions
1212
4. **HTML dependency** - raw HTML is the escape hatch for everything
13+
5. **Complex parsing** - requires backtracking and lookahead
14+
15+
## Parser Design: No Backtracking
16+
17+
One of Djot's most significant technical advantages is its parser design.
18+
19+
### The Markdown Parsing Problem
20+
21+
Markdown requires **backtracking** - the parser must sometimes go back and reinterpret what it already parsed. Consider:
22+
23+
```markdown
24+
*foo *bar* baz*
25+
```
26+
27+
A Markdown parser sees `*foo ` and thinks "this might be emphasis." It continues, finds `*bar*` (definitely emphasis), then hits `baz*`. Now it must decide: is the outer `*...*` emphasis too?
28+
29+
The parser has to backtrack and try different interpretations. This leads to:
30+
31+
- **Unpredictable results** - different parsers make different choices
32+
- **Performance costs** - worst-case exponential time complexity
33+
- **Edge case bugs** - complex nesting creates surprising output
34+
35+
### Djot's Solution
36+
37+
Djot was designed from the ground up to parse **without backtracking**:
38+
39+
- `*` always means strong, `_` always means emphasis
40+
- Delimiters must be "matched" - `*foo*` works, `*foo _bar* baz_` doesn't cross
41+
- The parser never needs to reconsider previous decisions
42+
43+
**Benefits:**
44+
45+
| Aspect | Markdown | Djot |
46+
|--------|----------|------|
47+
| Parse complexity | Can require backtracking | Linear, single-pass |
48+
| Predictability | Context-dependent | Always consistent |
49+
| Edge cases | Many surprising results | Minimal surprises |
50+
| Error recovery | Varies by parser | Predictable fallback |
51+
52+
### Real-World Example
53+
54+
```markdown
55+
_(_foo_)_
56+
```
57+
58+
Different Markdown parsers produce different output for this. Some treat it as emphasis around `(_foo_)`, others as `_(_foo` followed by `)_`.
59+
60+
In Djot, the rules are clear: underscores must balance, and the result is always predictable.
1361

1462
## Side-by-Side Comparison
1563

0 commit comments

Comments
 (0)