reovim_lang_markdown/
lib.rs1mod config;
6
7pub mod decorator;
8pub mod factory;
9pub mod stage;
10
11#[cfg(test)]
12mod tests;
13
14use std::{any::TypeId, sync::Arc};
15
16pub use config::MarkdownConfig;
17
18use {
19 reovim_core::{
20 event_bus::EventBus,
21 plugin::{Plugin, PluginContext, PluginId, PluginStateRegistry},
22 },
23 reovim_plugin_treesitter::{LanguageSupport, RegisterLanguage, TreesitterPlugin},
24};
25
26use {factory::MarkdownDecorationFactory, stage::MarkdownTableBorderStage};
27
28pub struct MarkdownLanguage;
30
31impl LanguageSupport for MarkdownLanguage {
32 fn language_id(&self) -> &'static str {
33 "markdown"
34 }
35
36 fn file_extensions(&self) -> &'static [&'static str] {
37 &["md", "markdown"]
38 }
39
40 fn tree_sitter_language(&self) -> reovim_plugin_treesitter::Language {
41 tree_sitter_md::LANGUAGE.into()
42 }
43
44 fn highlights_query(&self) -> &'static str {
45 include_str!("queries/highlights.scm")
46 }
47
48 fn decorations_query(&self) -> Option<&'static str> {
49 Some(include_str!("queries/decorations.scm"))
50 }
51
52 fn injections_query(&self) -> Option<&'static str> {
53 Some(include_str!("queries/injections.scm"))
54 }
55
56 fn context_query(&self) -> Option<&'static str> {
57 Some(include_str!("queries/context.scm"))
58 }
59}
60
61pub struct MarkdownInlineLanguage;
63
64impl LanguageSupport for MarkdownInlineLanguage {
65 fn language_id(&self) -> &'static str {
66 "markdown_inline"
67 }
68
69 fn file_extensions(&self) -> &'static [&'static str] {
70 &[]
72 }
73
74 fn tree_sitter_language(&self) -> reovim_plugin_treesitter::Language {
75 tree_sitter_md::INLINE_LANGUAGE.into()
76 }
77
78 fn highlights_query(&self) -> &'static str {
79 include_str!("queries_inline/highlights.scm")
80 }
81
82 fn decorations_query(&self) -> Option<&'static str> {
83 Some(include_str!("queries_inline/decorations.scm"))
84 }
85}
86
87pub struct MarkdownPlugin;
89
90impl Plugin for MarkdownPlugin {
91 fn id(&self) -> PluginId {
92 PluginId::new("reovim:lang-markdown")
93 }
94
95 fn name(&self) -> &'static str {
96 "Markdown Language"
97 }
98
99 fn description(&self) -> &'static str {
100 "Markdown language support with syntax highlighting and decorations"
101 }
102
103 fn dependencies(&self) -> Vec<TypeId> {
104 vec![TypeId::of::<TreesitterPlugin>()]
105 }
106
107 fn build(&self, ctx: &mut PluginContext) {
108 ctx.register_render_stage(Arc::new(MarkdownTableBorderStage::new()));
110 }
111
112 fn init_state(&self, registry: &PluginStateRegistry) {
113 registry.set_decoration_factory(MarkdownDecorationFactory::shared());
115 }
116
117 fn subscribe(&self, bus: &EventBus, _state: Arc<PluginStateRegistry>) {
118 bus.emit(RegisterLanguage {
121 language: Arc::new(MarkdownLanguage),
122 });
123 bus.emit(RegisterLanguage {
124 language: Arc::new(MarkdownInlineLanguage),
125 });
126 }
127}