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    /// Installs syntax highlighting and the language names offered by pickers.
14    fn set_highlighter(
15        &mut self,
16        highlighter: crate::Highlighter,
17        languages: impl IntoIterator<Item = impl Into<gpui::SharedString>>,
18    );
19
20    /// Configures markdown layout.
21    fn set_markdown_layout(&mut self, layout: crate::Layout);
22
23    /// Handles link clicks; without a handler links use `App::open_url`.
24    fn set_link_handler(&mut self, handler: crate::LinkHandler);
25
26    /// Installs the mark dialect shared by document readers and editors.
27    fn set_marks(&mut self, marks: crate::Marks);
28
29    /// Installs custom mark paint without changing how marks are parsed.
30    fn set_mark_paint(&mut self, paint: crate::marks::Painter);
31
32    /// Sets the paint for reader highlights.
33    fn set_highlight_paint(&mut self, paint: crate::HighlightPaint);
34
35    /// Installs the provider for link cards, chips and embeds.
36    fn set_link_preview(&mut self, preview: crate::LinkPreview);
37
38    /// Resolves source styles against the current theme and refreshes windows.
39    fn set_source_style(&mut self, style: impl Fn(&theme::Theme) -> crate::SourceStyle + 'static);
40
41    /// Sets the metrics used by document renderers.
42    fn set_typography(&mut self, typography: crate::Typography);
43
44    /// Reads highlight languages.
45    fn highlight_languages(&self) -> &[gpui::SharedString];
46
47    /// Reads markdown layout.
48    fn markdown_layout(&self) -> crate::Layout;
49
50    /// Reads typography.
51    fn typography(&self) -> crate::Typography;
52
53    /// Reads marks.
54    fn marks(&self) -> crate::Marks;
55
56    /// Reads source style.
57    fn source_style(&self) -> crate::SourceStyle;
58}
59
60impl AppExt for App {
61    fn set_block_renderer(&mut self, renderer: crate::BlockRenderer) {
62        crate::block::set_block_renderer(self, renderer)
63    }
64
65    fn set_find_paint(&mut self, paint: crate::FindPaint) {
66        crate::find::set_find_paint(self, paint)
67    }
68
69    fn set_highlighter(
70        &mut self,
71        highlighter: crate::Highlighter,
72        languages: impl IntoIterator<Item = impl Into<gpui::SharedString>>,
73    ) {
74        crate::highlight::set_highlighter(self, highlighter, languages)
75    }
76
77    fn set_markdown_layout(&mut self, layout: crate::Layout) {
78        crate::layout::set_layout(self, layout)
79    }
80
81    fn set_link_handler(&mut self, handler: crate::LinkHandler) {
82        crate::link::set_link_handler(self, handler)
83    }
84
85    fn set_marks(&mut self, marks: crate::Marks) {
86        crate::marks::set_marks(self, marks)
87    }
88
89    fn set_mark_paint(&mut self, paint: crate::marks::Painter) {
90        crate::marks::set_mark_paint(self, paint)
91    }
92
93    fn set_highlight_paint(&mut self, paint: crate::HighlightPaint) {
94        crate::marks::set_highlight_paint(self, paint)
95    }
96
97    fn set_link_preview(&mut self, preview: crate::LinkPreview) {
98        crate::preview::set_link_preview(self, preview)
99    }
100
101    fn set_source_style(&mut self, style: impl Fn(&theme::Theme) -> crate::SourceStyle + 'static) {
102        crate::source_style::set_source_style(self, style)
103    }
104
105    fn set_typography(&mut self, typography: crate::Typography) {
106        crate::typography::set_typography(self, typography)
107    }
108
109    fn highlight_languages(&self) -> &[gpui::SharedString] {
110        crate::highlight::languages(self)
111    }
112
113    fn markdown_layout(&self) -> crate::Layout {
114        crate::layout::Layout::of(self)
115    }
116
117    fn typography(&self) -> crate::Typography {
118        crate::typography::Typography::of(self)
119    }
120
121    fn marks(&self) -> crate::Marks {
122        crate::marks::Marks::of(self)
123    }
124
125    fn source_style(&self) -> crate::SourceStyle {
126        crate::source_style::SourceStyle::of(self)
127    }
128}