Skip to content

Commit ff087b4

Browse files
committed
feat: toml highlighting
1 parent 9912e53 commit ff087b4

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "grammars/sublime_toml_highlighting"]
2+
path = grammars/sublime_toml_highlighting
3+
url = https://github.com/jasonwilliams/sublime_toml_highlighting

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ askama = { version = "0.11.1", features = ["with-actix-web"] }
2929
askama_actix = "0.13.0"
3030
chrono = { version = "0.4.19", features = ["serde"] }
3131
actix-utils = "3.0.0"
32+
include_dir = { version = "0.7.2", features = ["glob"] }
3233

3334
[dependencies.figment]
3435
version = "0.10.6"

grammars/sublime_toml_highlighting

src/main.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use std::{env, path::PathBuf};
33
use actix_web::{web::Data, App, HttpServer};
44
use anyhow::Result;
55
use bonsaidb::local::config::StorageConfiguration;
6+
use include_dir::include_dir;
67
use log::{error, info};
7-
use syntect::parsing::SyntaxSet;
8+
use syntect::parsing::{SyntaxDefinition, SyntaxSet};
89

910
use config::Config;
1011
use db::DB;
@@ -14,7 +15,6 @@ mod db;
1415
mod simple;
1516
mod util;
1617

17-
1818
pub const RESERVED_URLS: &[&str] = &["raw", "download", "delete"];
1919

2020
#[tokio::main]
@@ -37,7 +37,24 @@ async fn main() -> Result<()> {
3737

3838
let database = Data::new(DB::new().await?);
3939
let config = Data::new(config);
40-
let syntaxes = Data::new(SyntaxSet::load_defaults_newlines());
40+
let mut syntaxes = SyntaxSet::load_defaults_newlines().into_builder();
41+
for file in include_dir!("$CARGO_MANIFEST_DIR/grammars")
42+
.find("**/*.sublime-syntax")
43+
.expect("correct glob")
44+
{
45+
syntaxes.add(
46+
SyntaxDefinition::load_from_str(
47+
file.as_file()
48+
.expect("matches only files")
49+
.contents_utf8()
50+
.expect("files contain valid utf8"),
51+
true,
52+
None,
53+
)
54+
.expect("valid syntax file"),
55+
);
56+
}
57+
let syntaxes = Data::new(syntaxes.build());
4158

4259
HttpServer::new(move || {
4360
App::new()

0 commit comments

Comments
 (0)