Skip to main content

render

Function render 

Source
pub fn render(markdown: &str) -> View
Expand description

Render markdown text into a View.

Handles common markdown elements:

  • Paragraphs
  • Headers (h1-h6)
  • Code blocks (fenced and indented)
  • Inline code
  • Bold and italic text
  • Lists (ordered and unordered)
  • Blockquotes

§Example

let view = telex::markdown::render("# Hello\n\nThis is **bold** text.");
Examples found in repository?
examples/15_markdown.rs (line 63)
54    fn render(&self, cx: Scope) -> View {
55        let show_help = state!(cx, || false);
56
57        // F1 toggles help
58        cx.use_command(
59            KeyBinding::key(KeyCode::F(1)),
60            with!(show_help => move || show_help.update(|v| *v = !*v)),
61        );
62
63        let rendered = telex::markdown::render(DEMO_MARKDOWN);
64
65        View::vstack()
66            .child(
67                View::styled_text("Markdown Rendering Demo")
68                    .color(Color::Cyan)
69                    .bold()
70                    .build(),
71            )
72            .child(
73                View::boxed()
74                    .flex(1)
75                    .child(
76                        View::split()
77                            .horizontal()
78                            .ratio(0.4)
79                            .first(
80                                View::vstack()
81                                    .child(View::styled_text(" Source ").bold().build())
82                                    .child(
83                                        View::boxed()
84                                            .flex(1)
85                                            .border(true)
86                                            .scroll(true)
87                                            .child(View::text(DEMO_MARKDOWN))
88                                            .build(),
89                                    )
90                                    .build(),
91                            )
92                            .second(
93                                View::vstack()
94                                    .child(View::styled_text(" Rendered ").bold().build())
95                                    .child(
96                                        View::boxed()
97                                            .flex(1)
98                                            .border(true)
99                                            .scroll(true)
100                                            .child(rendered)
101                                            .build(),
102                                    )
103                                    .build(),
104                            )
105                            .build(),
106                    )
107                    .build(),
108            )
109            .child(
110                View::styled_text("Tab: switch panes | ↑↓/jk: scroll | F1 help | Ctrl+Q: quit")
111                    .dim()
112                    .build(),
113            )
114            .child(
115                View::modal()
116                    .visible(show_help.get())
117                    .title("Example 15: Markdown")
118                    .on_dismiss(with!(show_help => move || show_help.set(false)))
119                    .child(
120                        View::vstack()
121                            .child(View::styled_text("What you're seeing").bold().build())
122                            .child(View::text("• Side-by-side markdown source and rendered"))
123                            .child(View::text("• Full markdown syntax support"))
124                            .child(View::text("• Scrollable panes for long content"))
125                            .child(View::gap(1))
126                            .child(View::styled_text("Key concepts").bold().build())
127                            .child(View::text("• telex::markdown::render() parses markdown"))
128                            .child(View::text("• Returns a View tree with styled text"))
129                            .child(View::text("• Code blocks, lists, quotes, headers"))
130                            .child(View::text("• Split view for comparison"))
131                            .child(View::gap(1))
132                            .child(View::styled_text("Try this").bold().build())
133                            .child(View::text("• Tab between source and rendered panes"))
134                            .child(View::text("• Scroll with arrow keys or j/k"))
135                            .child(View::text("• Compare source with rendered output"))
136                            .child(View::gap(1))
137                            .child(View::styled_text("Next up").bold().build())
138                            .child(View::text("→ 16_progress: progress bars"))
139                            .child(View::gap(1))
140                            .child(View::styled_text("Press Escape to close").dim().build())
141                            .build(),
142                    )
143                    .build(),
144            )
145            .build()
146    }