Skip to main content

markdown/app/
mod.rs

1//! App-owned configuration.
2
3pub mod layout;
4pub mod link;
5pub mod picture;
6pub mod preview;
7pub mod typography;
8
9use gpui::App;
10
11/// Configuration carried by the application. Import as `use markdown::AppExt as _;`.
12pub trait AppExt {
13    /// Installs the renderer for custom fenced blocks.
14    fn set_block_renderer(&mut self, renderer: crate::BlockRenderer);
15
16    /// Sets match and current washes; the callback keeps the current match stronger.
17    fn set_find_paint(&mut self, paint: crate::FindPaint);
18
19    /// Sets the washes behind comment ranges.
20    fn set_comment_paint(&mut self, paint: crate::CommentPaint);
21
22    /// Installs syntax highlighting and the language names offered by pickers.
23    fn set_highlighter(
24        &mut self,
25        highlighter: crate::Highlighter,
26        languages: impl IntoIterator<Item = impl Into<gpui::SharedString>>,
27    );
28
29    /// Configures markdown layout.
30    fn set_markdown_layout(&mut self, layout: crate::Layout);
31
32    /// Sets how far a mermaid diagram zooms.
33    #[cfg(feature = "mermaid")]
34    fn set_mermaid_zoom(&mut self, zoom: crate::fence::mermaid::Zoom);
35
36    /// Installs what the app does with links — see [`crate::Links`].
37    fn set_links<L: crate::Links>(&mut self);
38
39    /// Installs the mark dialect shared by document readers and editors.
40    fn set_marks(&mut self, marks: crate::Marks);
41
42    /// Installs custom mark paint without changing how marks are parsed.
43    fn set_mark_paint(&mut self, paint: crate::paint::marks::Painter);
44
45    /// Sets the paint for reader highlights.
46    fn set_highlight_paint(&mut self, paint: crate::HighlightPaint);
47
48    /// Resolves source styles against the current theme and refreshes windows.
49    fn set_source_style(&mut self, style: impl Fn(&theme::Theme) -> crate::SourceStyle + 'static);
50
51    /// Sets the metrics used by document renderers.
52    fn set_typography(&mut self, typography: crate::Typography);
53
54    /// Reads highlight languages.
55    fn highlight_languages(&self) -> &[gpui::SharedString];
56
57    /// Reads markdown layout.
58    fn markdown_layout(&self) -> crate::Layout;
59
60    /// Reads typography.
61    fn typography(&self) -> crate::Typography;
62
63    /// Reads marks.
64    fn marks(&self) -> crate::Marks;
65
66    /// Reads source style.
67    fn source_style(&self) -> crate::SourceStyle;
68}
69
70impl AppExt for App {
71    fn set_block_renderer(&mut self, renderer: crate::BlockRenderer) {
72        crate::fence::set_block_renderer(self, renderer)
73    }
74
75    fn set_find_paint(&mut self, paint: crate::FindPaint) {
76        crate::paint::find::set_find_paint(self, paint)
77    }
78
79    fn set_comment_paint(&mut self, paint: crate::CommentPaint) {
80        crate::paint::comment::set_comment_paint(self, paint)
81    }
82
83    fn set_highlighter(
84        &mut self,
85        highlighter: crate::Highlighter,
86        languages: impl IntoIterator<Item = impl Into<gpui::SharedString>>,
87    ) {
88        crate::fence::highlight::set_highlighter(self, highlighter, languages)
89    }
90
91    fn set_markdown_layout(&mut self, layout: crate::Layout) {
92        crate::app::layout::set_layout(self, layout)
93    }
94
95    #[cfg(feature = "mermaid")]
96    fn set_mermaid_zoom(&mut self, zoom: crate::fence::mermaid::Zoom) {
97        crate::fence::mermaid::set_zoom(self, zoom)
98    }
99
100    fn set_links<L: crate::Links>(&mut self) {
101        crate::app::link::set_links::<L>(self)
102    }
103
104    fn set_marks(&mut self, marks: crate::Marks) {
105        crate::paint::marks::set_marks(self, marks)
106    }
107
108    fn set_mark_paint(&mut self, paint: crate::paint::marks::Painter) {
109        crate::paint::marks::set_mark_paint(self, paint)
110    }
111
112    fn set_highlight_paint(&mut self, paint: crate::HighlightPaint) {
113        crate::paint::marks::set_highlight_paint(self, paint)
114    }
115
116    fn set_source_style(&mut self, style: impl Fn(&theme::Theme) -> crate::SourceStyle + 'static) {
117        crate::source::style::set_source_style(self, style)
118    }
119
120    fn set_typography(&mut self, typography: crate::Typography) {
121        crate::app::typography::set_typography(self, typography)
122    }
123
124    fn highlight_languages(&self) -> &[gpui::SharedString] {
125        crate::fence::highlight::languages(self)
126    }
127
128    fn markdown_layout(&self) -> crate::Layout {
129        crate::app::layout::Layout::of(self)
130    }
131
132    fn typography(&self) -> crate::Typography {
133        crate::app::typography::Typography::of(self)
134    }
135
136    fn marks(&self) -> crate::Marks {
137        crate::marks::Marks::of(self)
138    }
139
140    fn source_style(&self) -> crate::SourceStyle {
141        crate::source::style::SourceStyle::of(self)
142    }
143}