Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-hall authored May 27, 2024
2 parents 44ca57f + 62154b3 commit 6d5ad97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ Below is a list of projects using Syntect, in approximate order by how long they
- [Broot](https://github.com/Canop/broot), a terminal file manager, uses `syntect` for file previews.
- [Rusty Slider](https://ollej.github.io/rusty-slider/), a markdown slideshow presentation application, uses `syntect` for code blocks.
- [bingus-blog](https://git.slonk.ing/slonk/bingus-blog), a blog software written in Rust, uses `syntect` for fenced code blocks.
- [BugStalker](https://github.com/godzie44/BugStalker/), modern debugger for Linux x86-64. Written in Rust for Rust programs.
- [Yazi](https://github.com/sxyazi/yazi), blazing fast terminal file manager based on async I/O, uses `syntect` for text file previews.


## License and Acknowledgements
Expand Down
11 changes: 11 additions & 0 deletions src/parsing/syntax_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl SyntaxSet {
/// This uses regexes that come with some sublime syntax grammars for matching things like
/// shebangs and mode lines like `-*- Mode: C -*-`
pub fn find_syntax_by_first_line<'a>(&'a self, s: &str) -> Option<&'a SyntaxReference> {
let s = s.strip_prefix("\u{feff}").unwrap_or(s); // Strip UTF-8 BOM
let cache = self.first_line_cache();
for &(ref reg, i) in cache.regexes.iter().rev() {
if reg.search(s, 0, s.len(), None) {
Expand Down Expand Up @@ -1401,6 +1402,16 @@ mod tests {
assert_prototype_only_on(&["main"], &rebuilt, &rebuilt.syntaxes()[0]);
}

#[test]
fn find_syntax_set_from_line_with_bom() {
// Regression test for #529
let syntax_set = SyntaxSet::load_defaults_newlines();
let syntax_ref = syntax_set
.find_syntax_by_first_line("\u{feff}<?xml version=\"1.0\"?>")
.unwrap();
assert_eq!(syntax_ref.name, "XML");
}

fn assert_ops_contain(ops: &[(usize, ScopeStackOp)], expected: &(usize, ScopeStackOp)) {
assert!(
ops.contains(expected),
Expand Down
12 changes: 10 additions & 2 deletions tests/public_api.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#[test]
fn public_api() {
// NOTE: consider switching back to using `public_api::MINIMUM_NIGHTLY_RUST_VERSION` after the
// version is newer than the one set here
let nightly_version = "nightly-2023-09-18";
assert_eq!(
public_api::MINIMUM_NIGHTLY_RUST_VERSION,
"nightly-2023-08-25"
);

// Install a compatible nightly toolchain if it is missing
rustup_toolchain::install(public_api::MINIMUM_NIGHTLY_RUST_VERSION).unwrap();
rustup_toolchain::install(nightly_version).unwrap();

// Build rustdoc JSON
let rustdoc_json = rustdoc_json::Builder::default()
.toolchain(public_api::MINIMUM_NIGHTLY_RUST_VERSION)
.toolchain(nightly_version)
.build()
.unwrap();

Expand Down

0 comments on commit 6d5ad97

Please sign in to comment.