feat: add graphql code highlighting

This commit is contained in:
Graham Vasquez 2024-10-28 03:45:14 -04:00
parent 6cf25e5eb9
commit 43e53b74ea
No known key found for this signature in database
GPG Key ID: 04E905940935080B
2 changed files with 10 additions and 10 deletions

View File

@ -1,6 +1,5 @@
use super::padding::NumberPadder;
use crate::{
PresentationTheme,
markdown::{
elements::{Percent, PercentParseError},
text::{WeightedText, WeightedTextBlock},
@ -12,6 +11,7 @@ use crate::{
},
style::{Color, TextStyle},
theme::{Alignment, CodeBlockStyle},
PresentationTheme,
};
use serde::Deserialize;
use serde_with::DeserializeFromStr;
@ -438,6 +438,7 @@ pub enum SnippetLanguage {
File,
Fish,
Go,
GraphQL,
Haskell,
Html,
Java,
@ -506,6 +507,7 @@ impl FromStr for SnippetLanguage {
"file" => File,
"fish" => Fish,
"go" => Go,
"graphql" => GraphQL,
"haskell" => Haskell,
"html" => Html,
"java" => Java,
@ -622,8 +624,8 @@ pub(crate) struct ExternalFile {
#[cfg(test)]
mod test {
use super::*;
use Highlight::*;
use rstest::rstest;
use Highlight::*;
fn parse_language(input: &str) -> SnippetLanguage {
let (language, _) = CodeBlockParser::parse_block_info(input).expect("parse failed");
@ -725,13 +727,10 @@ mod test {
#[test]
fn highlight_line_range() {
let attributes = parse_attributes("bash { 1, 2-4,6 , all , 10 - 12 }");
assert_eq!(attributes.highlight_groups, &[HighlightGroup::new(vec![
Single(1),
Range(2..5),
Single(6),
All,
Range(10..13)
])]);
assert_eq!(
attributes.highlight_groups,
&[HighlightGroup::new(vec![Single(1), Range(2..5), Single(6), All, Range(10..13)])]
);
}
#[test]

View File

@ -9,10 +9,10 @@ use once_cell::sync::Lazy;
use serde::Deserialize;
use std::{cell::RefCell, collections::BTreeMap, fs, path::Path, rc::Rc};
use syntect::{
LoadingError,
easy::HighlightLines,
highlighting::{Style, Theme, ThemeSet},
parsing::SyntaxSet,
LoadingError,
};
static SYNTAX_SET: Lazy<SyntaxSet> = Lazy::new(|| {
@ -123,6 +123,7 @@ impl CodeHighlighter {
File => "txt",
Fish => "fish",
Go => "go",
GraphQL => "graphql",
Haskell => "hs",
Html => "html",
Java => "java",