Skip to main content

oak_markdown/language/
mod.rs

1#![doc = include_str!("readme.md")]
2use oak_core::{Language, LanguageCategory};
3
4/// Configuration for the Markdown language features.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub struct MarkdownLanguage {
8    /// Enable math formulas.
9    ///
10    /// Example: `$a^2 + b^2 = c^2$` or `$$E = mc^2$$`
11    pub allow_math: bool,
12    /// Enable tables.
13    ///
14    /// Example:
15    /// | Header |
16    /// | ------ |
17    /// | Cell   |
18    pub allow_tables: bool,
19    /// Enable task lists.
20    ///
21    /// Example: `- [ ] Task` or `- [x] Done`
22    pub allow_task_lists: bool,
23    /// Enable strikethrough.
24    ///
25    /// Example: `~~deleted~~`
26    pub allow_strikethrough: bool,
27    /// Enable footnotes.
28    ///
29    /// Example: `[^1]` and `[^1]: Note`
30    pub allow_footnotes: bool,
31    /// Enable front matter (YAML/TOML/JSON).
32    ///
33    /// Example:
34    /// ---
35    /// title: Hello
36    /// ---
37    pub allow_front_matter: bool,
38    /// Enable definition lists.
39    ///
40    /// Example:
41    /// Term
42    /// : Definition
43    pub allow_definition_lists: bool,
44    /// Enable superscript and subscript.
45    ///
46    /// Example: `^sup^` or `~sub~`
47    pub allow_subscript: bool,
48    /// Enable autolinks.
49    ///
50    /// Example: `<https://example.com>`
51    pub allow_autolinks: bool,
52    /// Enable abbreviations.
53    ///
54    /// Example: `*[HTML]: HyperText Markup Language`
55    pub allow_abbreviations: bool,
56    /// Enable indented code blocks.
57    ///
58    /// Example:
59    ///     code block
60    pub allow_indented_code_blocks: bool,
61    /// Enable inline HTML tags.
62    ///
63    /// Example: `<div>` or `<!-- comment -->`
64    pub allow_html: bool,
65    /// Enable hard line breaks.
66    ///
67    /// Example: Two spaces at the end of a line or a backslash.
68    pub allow_hard_line_breaks: bool,
69    /// Enable GFM-style autolinks.
70    ///
71    /// Example: `https://example.com`
72    pub allow_gfm_autolinks: bool,
73    /// Enable ATX headings.
74    ///
75    /// Example: `# Heading`
76    pub allow_headings: bool,
77    /// Enable lists.
78    ///
79    /// Example: `- Item` or `1. Item`
80    pub allow_lists: bool,
81    /// Enable blockquotes.
82    ///
83    /// Example: `> Quote`
84    pub allow_blockquotes: bool,
85    /// Enable fenced code blocks.
86    ///
87    /// Example: ` ```rust `
88    pub allow_fenced_code_blocks: bool,
89    /// Enable horizontal rules.
90    ///
91    /// Example: `---` or `***`
92    pub allow_horizontal_rules: bool,
93    /// Enable Setext headings.
94    ///
95    /// Example:
96    /// Heading
97    /// =======
98    pub allow_setext_headings: bool,
99    /// Enable GFM Tagfilter.
100    ///
101    /// Filters certain HTML tags like `<script>`.
102    pub allow_html_tagfilter: bool,
103    /// Enable XML/TSX syntax.
104    ///
105    /// Example: `<Component />`
106    pub allow_xml: bool,
107}
108
109impl MarkdownLanguage {
110    /// Creates a new Markdown language configuration with default settings.
111    pub fn new() -> Self {
112        Self::default()
113    }
114}
115
116impl Language for MarkdownLanguage {
117    const NAME: &'static str = "markdown";
118    const CATEGORY: LanguageCategory = LanguageCategory::Markup;
119
120    type TokenType = crate::lexer::token_type::MarkdownTokenType;
121    type ElementType = crate::parser::element_type::MarkdownElementType;
122    type TypedRoot = crate::ast::MarkdownRoot;
123}
124
125impl Default for MarkdownLanguage {
126    fn default() -> Self {
127        Self {
128            allow_math: true,
129            allow_tables: true,
130            allow_task_lists: true,
131            allow_strikethrough: true,
132            allow_footnotes: true,
133            allow_front_matter: true,
134            allow_definition_lists: false,
135            allow_subscript: false,
136            allow_autolinks: true,
137            allow_abbreviations: true,
138            allow_indented_code_blocks: true,
139            allow_html: true,
140            allow_hard_line_breaks: true,
141            allow_gfm_autolinks: true,
142            allow_headings: true,
143            allow_lists: true,
144            allow_blockquotes: true,
145            allow_fenced_code_blocks: true,
146            allow_horizontal_rules: true,
147            allow_setext_headings: true,
148            allow_html_tagfilter: false,
149            allow_xml: false,
150        }
151    }
152}