Markdown support

This commit is contained in:
Joshua Barretto 2025-09-24 11:58:26 +01:00
parent f2a9876b81
commit 6580432286

View file

@ -10,35 +10,42 @@ pub struct LangPack {
impl LangPack { impl LangPack {
pub fn from_file_name(file_name: &Path) -> Self { pub fn from_file_name(file_name: &Path) -> Self {
match file_name.extension().and_then(|e| e.to_str()).unwrap_or("") { match (
"rs" => Self { file_name.file_name().and_then(|e| e.to_str()).unwrap_or(""),
file_name.extension().and_then(|e| e.to_str()).unwrap_or(""),
) {
(_, "rs") => Self {
highlighter: Highlighter::default().rust(), highlighter: Highlighter::default().rust(),
comment_syntax: Some(vec!['/', '/', ' ']), comment_syntax: Some(vec!['/', '/', ' ']),
}, },
"md" => Self { (_, "md") => Self {
highlighter: Highlighter::default().markdown(), highlighter: Highlighter::default().markdown(),
comment_syntax: None, comment_syntax: None,
}, },
"toml" => Self { (_, "toml") => Self {
highlighter: Highlighter::default().toml(), highlighter: Highlighter::default().toml(),
comment_syntax: Some(vec!['#', ' ']), comment_syntax: Some(vec!['#', ' ']),
}, },
"c" | "h" | "cpp" | "hpp" | "cxx" | "js" | "ts" | "go" => Self { (_, "c" | "h" | "cpp" | "hpp" | "cxx" | "js" | "ts" | "go") => Self {
highlighter: Highlighter::default().generic_clike(), highlighter: Highlighter::default().generic_clike(),
comment_syntax: Some(vec!['/', '/', ' ']), comment_syntax: Some(vec!['/', '/', ' ']),
}, },
"glsl" | "vert" | "frag" => Self { (_, "glsl" | "vert" | "frag") => Self {
highlighter: Highlighter::default().glsl(), highlighter: Highlighter::default().glsl(),
comment_syntax: Some(vec!['/', '/', ' ']), comment_syntax: Some(vec!['/', '/', ' ']),
}, },
"py" => Self { (_, "py") => Self {
highlighter: Highlighter::default().python(), highlighter: Highlighter::default().python(),
comment_syntax: Some(vec!['#', ' ']), comment_syntax: Some(vec!['#', ' ']),
}, },
"tao" => Self { (_, "tao") => Self {
highlighter: Highlighter::default().tao(), highlighter: Highlighter::default().tao(),
comment_syntax: Some(vec!['#', ' ']), comment_syntax: Some(vec!['#', ' ']),
}, },
("makefile" | "Makefile", _) => Self {
highlighter: Highlighter::default().makefile(),
comment_syntax: Some(vec!['#', ' ']),
},
_ => Self { _ => Self {
highlighter: Highlighter::default(), highlighter: Highlighter::default(),
comment_syntax: None, comment_syntax: None,
@ -243,4 +250,31 @@ impl Highlighter {
// Comments // Comments
.with(TokenKind::Comment, r"#[^$]*$") .with(TokenKind::Comment, r"#[^$]*$")
} }
pub fn makefile(self) -> Self {
self
// Keywords
.with(
TokenKind::Keyword,
r"\b[(if(n)?[(eq)(def)]?)(endif)(else)]\b",
)
// Operators
.with(TokenKind::Operator, r"[=,:\@]")
// Double-quoted strings
.with(
TokenKind::String,
r#"b?"[(\\[nrt\\0(x[0-7A-Za-z][0-7A-Za-z])])[^"]]*""#,
)
// Single-quoted strings
.with(
TokenKind::String,
r#"b?'[(\\[nrt\\0(x[0-7A-Za-z][0-7A-Za-z])])[^']]*'"#,
)
// Rules
.with(TokenKind::Type, r"^[A-Za-z0-9_\-\.]*:")
// Variables
.with(TokenKind::Constant, r"\$\([A-Za-z_][A-Za-z0-9_\-]*\)")
// Comments
.with(TokenKind::Comment, r"#[^$]*$")
}
} }