Skip to main content

simple/
simple.rs

1use smart_markdown::Markdown;
2
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let mut md = Markdown::parse(MARKDOWN);
5    md.render();
6
7    Ok(())
8}
9
10const MARKDOWN: &str = r##"
11# Smart Markdown Render
12
13A rust crate that **renders markdown** to the terminal with *full* inline formatting support.
14
15## Features
16
17- Headings with unicode symbol prefixes
18- **Bold**, *italic*, ~~strikethrough~~, and `inline code`
19- [Links](https://example.com) rendered with underline
20- Lists and blockquotes
21
22### Table Support
23
24| name  | age | description                               |
25|-------|-----|-------------------------------------------|
26| Alice | 30  | senior engineer                           |
27| Bob   | 25  | junior dev who writes very long descriptions that span multiple lines |
28| Carol | 28  | product manager                           |
29
30> This is a blockquote that demonstrates the dimmed gutter style.
31> It wraps text to fit the terminal width.
32
33---
34
35### Ordered List
36
371. First item with **bold text**
382. Second item with `code`
393. Third item
40
41### Unordered List
42
43- Simple item
44- Item with ~~strikethrough~~
45- Another item
46
47### Code Blocks
48
49```rust
50/// A simple struct with fields
51pub struct Point {
52    pub x: f64,
53    pub y: f64,
54}
55
56impl Point {
57    pub fn distance(&self, other: &Point) -> f64 {
58        let dx = self.x - other.x;
59        let dy = self.y - other.y;
60        (dx * dx + dy * dy).sqrt()
61    }
62}
63```
64
65```python
66def fibonacci(n: int) -> list[int]:
67    """Return the first n Fibonacci numbers."""
68    a, b = 0, 1
69    result = []
70    for _ in range(n):
71        result.append(a)
72        a, b = b, a + b
73    return result
74
75print(fibonacci(10))
76```
77
78```go
79package main
80
81import "fmt"
82
83func main() {
84    greet := "Hello, 世界"
85    fmt.Println(greet)
86}
87```
88
89---
90
91### Backslash Escapes
92
93Use a backslash to escape formatting characters:
94
95\*this is not bold\* — \_not italic\_ — \`not code\` — \[not a link\]
96
97---
98
99### Indented Code Blocks
100
101A code block can also be created by indenting lines with 4 spaces:
102
103    fn main() {
104        println!("Hello from indented code!");
105    }
106
107---
108
109### Reference-Style Links
110
111Visit the [Rust website][rust] for documentation.
112
113[rust]: https://www.rust-lang.org
114
115---
116
117### Autolinks
118
119Project URLs like <https://github.com> and emails like <hello@example.com> are auto-detected and rendered as underlined links.
120
121---
122
123### Images
124
125Here is an image: ![Rust Logo](https://example.com/rust.png)
126
127---
128
129### HTML Inline & Blocks
130
131Inline HTML tags like <b>bold</b>, <i>italic</i>, <u>underline</u>, and <br> line breaks are stripped from output.
132
133<div>
134  <p>This HTML block is rendered as dimmed text.</p>
135</div>
136
137---
138
139### Nested Lists
140
141- Level 1 item
142- Another level 1
143    - Level 2 sub-item
144    - Another level 2
145        1. Level 3 ordered
146        2. Another ordered
147
148---
149
150### Task Lists
151
152- [x] Complete the parser
153- [x] Add inline formatting
154- [ ] Write documentation
155- [ ] Publish to crates.io
156
157---
158
159### Highlight / Mark
160
161This feature allows you to ==highlight== important text inline.
162
163---
164
165### Subscript & Superscript
166
167Water is H~2~O, and the formula for area is x^2^ + y^2^ = r^2^.
168
169---
170
171### Inline Math
172
173The quadratic formula is $x = (-b \pm \sqrt{b^2 - 4ac}) / 2a$.
174
175---
176
177### Emoji Shortcodes
178
179Common emoji shortcodes are expanded: :rocket: :fire: :tada: :sparkles:
180
181Built with :heart: using Rust.
182
183---
184
185### Footnotes
186
187The Rust programming language[^1] is known for its memory safety[^2].
188
189[^1]: Rust was first released in 2015 by Mozilla Research.
190
191[^2]: Memory safety is achieved through ownership and borrowing, without a garbage collector.
192
193---
194
195### Definition Lists
196
197Rust
198: A systems programming language focused on safety and performance.
199: First stable release in 2015.
200
201Markdown
202: A lightweight markup language for formatting text.
203
204---
205
206"##;