Skip to main content

markdown/
app.rs

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