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