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    /// Installs the painter of cards for links the app owns.
39    fn set_link_card(&mut self, card: crate::LinkCard);
40
41    /// Resolves source styles against the current theme and refreshes windows.
42    fn set_source_style(&mut self, style: impl Fn(&theme::Theme) -> crate::SourceStyle + 'static);
43
44    /// Sets the metrics used by document renderers.
45    fn set_typography(&mut self, typography: crate::Typography);
46
47    /// Reads highlight languages.
48    fn highlight_languages(&self) -> &[gpui::SharedString];
49
50    /// Reads markdown layout.
51    fn markdown_layout(&self) -> crate::Layout;
52
53    /// Reads typography.
54    fn typography(&self) -> crate::Typography;
55
56    /// Reads marks.
57    fn marks(&self) -> crate::Marks;
58
59    /// Reads source style.
60    fn source_style(&self) -> crate::SourceStyle;
61}
62
63impl AppExt for App {
64    fn set_block_renderer(&mut self, renderer: crate::BlockRenderer) {
65        crate::block::set_block_renderer(self, renderer)
66    }
67
68    fn set_find_paint(&mut self, paint: crate::FindPaint) {
69        crate::find::set_find_paint(self, paint)
70    }
71
72    fn set_highlighter(
73        &mut self,
74        highlighter: crate::Highlighter,
75        languages: impl IntoIterator<Item = impl Into<gpui::SharedString>>,
76    ) {
77        crate::highlight::set_highlighter(self, highlighter, languages)
78    }
79
80    fn set_markdown_layout(&mut self, layout: crate::Layout) {
81        crate::layout::set_layout(self, layout)
82    }
83
84    fn set_link_handler(&mut self, handler: crate::LinkHandler) {
85        crate::link::set_link_handler(self, handler)
86    }
87
88    fn set_marks(&mut self, marks: crate::Marks) {
89        crate::marks::set_marks(self, marks)
90    }
91
92    fn set_mark_paint(&mut self, paint: crate::marks::Painter) {
93        crate::marks::set_mark_paint(self, paint)
94    }
95
96    fn set_highlight_paint(&mut self, paint: crate::HighlightPaint) {
97        crate::marks::set_highlight_paint(self, paint)
98    }
99
100    fn set_link_preview(&mut self, preview: crate::LinkPreview) {
101        crate::preview::set_link_preview(self, preview)
102    }
103
104    fn set_link_card(&mut self, card: crate::LinkCard) {
105        crate::preview::set_link_card(self, card)
106    }
107
108    fn set_source_style(&mut self, style: impl Fn(&theme::Theme) -> crate::SourceStyle + 'static) {
109        crate::source_style::set_source_style(self, style)
110    }
111
112    fn set_typography(&mut self, typography: crate::Typography) {
113        crate::typography::set_typography(self, typography)
114    }
115
116    fn highlight_languages(&self) -> &[gpui::SharedString] {
117        crate::highlight::languages(self)
118    }
119
120    fn markdown_layout(&self) -> crate::Layout {
121        crate::layout::Layout::of(self)
122    }
123
124    fn typography(&self) -> crate::Typography {
125        crate::typography::Typography::of(self)
126    }
127
128    fn marks(&self) -> crate::Marks {
129        crate::marks::Marks::of(self)
130    }
131
132    fn source_style(&self) -> crate::SourceStyle {
133        crate::source_style::SourceStyle::of(self)
134    }
135}