Skip to content

Commit ff65b05

Browse files
committed
feat(markdown): Optionally use CodeEditor in the new crate freya-markdown
1 parent e11d21b commit ff65b05

25 files changed

Lines changed: 609 additions & 232 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Freya is split in various crates, each with it's own meaning and purpose, here i
101101
- `freya-material-design`: Material Design Components for Freya apps.
102102
- `freya-plotters-backend`: Freya's skia-safe backend for plotters.
103103
- `freya-code-editor`: Set of APIs to create text Code Editors in Freya.
104+
- `freya-markdown`: Markdown rendering component for Freya.
104105
- `freya-camera`: Camera capture support for Freya.
105106

106107
## Examples

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ members = [
2525
"./crates/freya-edit",
2626
"./crates/freya-winit",
2727
"./crates/freya-components",
28+
"./crates/freya-markdown",
2829
"./crates/pathgraph",
2930
"./crates/freya-animation",
3031
"./crates/freya-router",
@@ -60,6 +61,7 @@ freya-clipboard = { path = "./crates/freya-clipboard", version = "0.4.0-rc.22" }
6061
freya-edit = { path = "./crates/freya-edit", version = "0.4.0-rc.22" }
6162
freya-winit = { path = "./crates/freya-winit", version = "0.4.0-rc.22" }
6263
freya-components = { path = "./crates/freya-components", version = "0.4.0-rc.22" }
64+
freya-markdown = { path = "./crates/freya-markdown", version = "0.4.0-rc.22" }
6365
pathgraph = { path = "./crates/pathgraph/", version = "0.4.0-rc.22" }
6466
freya-animation = { path = "./crates/freya-animation", version = "0.4.0-rc.22" }
6567
freya-router = { path = "./crates/freya-router", version = "0.4.0-rc.22" }

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,23 @@ fn app() -> impl IntoElement {
220220
</div>
221221

222222

223+
### Markdown
224+
225+
Render Markdown documents with the `MarkdownViewer` component.
226+
Enable with the `markdown` feature.
227+
228+
<details>
229+
<summary>Code</summary>
230+
231+
```rust
232+
fn app() -> impl IntoElement {
233+
MarkdownViewer::new("# Hello World\n\nThis is **bold** and *italic* text.")
234+
}
235+
```
236+
237+
</details>
238+
239+
223240
### Routing & Navigation
224241

225242
Define routes, manage navigation state, and transition between different views.

crates/freya-code-editor/src/editor_data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ropey::Rope;
1717
use tree_sitter::InputEdit;
1818

1919
use crate::{
20-
editor_theme::SyntaxTheme,
20+
editor_theme::EditorSyntaxTheme,
2121
languages::LanguageId,
2222
metrics::EditorMetrics,
2323
syntax::InputEditExt,
@@ -33,7 +33,7 @@ pub struct CodeEditorData {
3333
pub(crate) scrolls: (i32, i32),
3434
pub(crate) pending_edit: Option<InputEdit>,
3535
pub language_id: LanguageId,
36-
theme: SyntaxTheme,
36+
theme: EditorSyntaxTheme,
3737
}
3838

3939
impl CodeEditorData {
@@ -48,7 +48,7 @@ impl CodeEditorData {
4848
scrolls: (0, 0),
4949
pending_edit: None,
5050
language_id,
51-
theme: SyntaxTheme::default(),
51+
theme: EditorSyntaxTheme::default(),
5252
}
5353
}
5454

@@ -71,7 +71,7 @@ impl CodeEditorData {
7171
.measure_longest_line(font_size, font_family, &self.rope);
7272
}
7373

74-
pub fn set_theme(&mut self, theme: SyntaxTheme) {
74+
pub fn set_theme(&mut self, theme: EditorSyntaxTheme) {
7575
self.theme = theme;
7676
}
7777

crates/freya-code-editor/src/editor_line.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct EditorLineUI {
2828
pub(crate) gutter: bool,
2929
pub(crate) show_whitespace: bool,
3030
pub(crate) font_family: Cow<'static, str>,
31-
pub(crate) theme: Readable<EditorTheme>,
31+
pub(crate) theme: EditorTheme,
3232
pub(crate) a11y_id: AccessibilityId,
3333
}
3434

@@ -53,7 +53,6 @@ impl Component for EditorLineUI {
5353
let holder = use_state(ParagraphHolder::default);
5454

5555
let editor_data = editor.read();
56-
let theme = theme.read();
5756

5857
let longest_width = editor_data.metrics.longest_width;
5958
let line = editor_data.metrics.syntax_blocks.get_line(line_index);

0 commit comments

Comments
 (0)