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    /// Sets how far a mermaid diagram zooms.
24    #[cfg(feature = "mermaid")]
25    fn set_mermaid_zoom(&mut self, zoom: crate::mermaid::Zoom);
26
27    /// Handles link clicks; without a handler links use `App::open_url`.
28    fn set_link_handler(&mut self, handler: crate::LinkHandler);
29
30    /// Installs the mark dialect shared by document readers and editors.
31    fn set_marks(&mut self, marks: crate::Marks);
32
33    /// Installs custom mark paint without changing how marks are parsed.
34    fn set_mark_paint(&mut self, paint: crate::marks::Painter);
35
36    /// Sets the paint for reader highlights.
37    fn set_highlight_paint(&mut self, paint: crate::HighlightPaint);
38
39    /// Installs the provider for link cards, chips and embeds.
40    fn set_link_preview(&mut self, preview: crate::LinkPreview);
41
42    /// Installs the painter of cards for links the app owns.
43    fn set_link_card(&mut self, card: crate::LinkCard);
44
45    /// Installs the painter of hover cards for links the app owns.
46    fn set_link_hover(&mut self, hover: crate::LinkHover);
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::block::set_block_renderer(self, renderer)
73    }
74
75    fn set_find_paint(&mut self, paint: crate::FindPaint) {
76        crate::find::set_find_paint(self, paint)
77    }
78
79    fn set_highlighter(
80        &mut self,
81        highlighter: crate::Highlighter,
82        languages: impl IntoIterator<Item = impl Into<gpui::SharedString>>,
83    ) {
84        crate::highlight::set_highlighter(self, highlighter, languages)
85    }
86
87    fn set_markdown_layout(&mut self, layout: crate::Layout) {
88        crate::layout::set_layout(self, layout)
89    }
90
91    #[cfg(feature = "mermaid")]
92    fn set_mermaid_zoom(&mut self, zoom: crate::mermaid::Zoom) {
93        crate::mermaid::set_zoom(self, zoom)
94    }
95
96    fn set_link_handler(&mut self, handler: crate::LinkHandler) {
97        crate::link::set_link_handler(self, handler)
98    }
99
100    fn set_marks(&mut self, marks: crate::Marks) {
101        crate::marks::set_marks(self, marks)
102    }
103
104    fn set_mark_paint(&mut self, paint: crate::marks::Painter) {
105        crate::marks::set_mark_paint(self, paint)
106    }
107
108    fn set_highlight_paint(&mut self, paint: crate::HighlightPaint) {
109        crate::marks::set_highlight_paint(self, paint)
110    }
111
112    fn set_link_preview(&mut self, preview: crate::LinkPreview) {
113        crate::preview::set_link_preview(self, preview)
114    }
115
116    fn set_link_card(&mut self, card: crate::LinkCard) {
117        crate::preview::set_link_card(self, card)
118    }
119
120    fn set_link_hover(&mut self, hover: crate::LinkHover) {
121        crate::preview::set_link_hover(self, hover)
122    }
123
124    fn set_source_style(&mut self, style: impl Fn(&theme::Theme) -> crate::SourceStyle + 'static) {
125        crate::source_style::set_source_style(self, style)
126    }
127
128    fn set_typography(&mut self, typography: crate::Typography) {
129        crate::typography::set_typography(self, typography)
130    }
131
132    fn highlight_languages(&self) -> &[gpui::SharedString] {
133        crate::highlight::languages(self)
134    }
135
136    fn markdown_layout(&self) -> crate::Layout {
137        crate::layout::Layout::of(self)
138    }
139
140    fn typography(&self) -> crate::Typography {
141        crate::typography::Typography::of(self)
142    }
143
144    fn marks(&self) -> crate::Marks {
145        crate::marks::Marks::of(self)
146    }
147
148    fn source_style(&self) -> crate::SourceStyle {
149        crate::source_style::SourceStyle::of(self)
150    }
151}