Plain-Text Fallback Syntax Highlighting For Rust's Syntect Crate
rust
```cargo
= "5.2"
```
use HighlightLines;
use ThemeSet;
use ;
use SyntaxSet;
syntect
some string of code
This is a basic approach for providing a fallback to plain-text when using Rust's syntect crate for syntax highlighting. This provides a way to process everything through the same syntax highlighting even if syntect doesn't recognize the requested language.
The key is:
rust
let syntax = ss.find_syntax_by_name .unwrap_or_else;
That line attempts to local the requested syntax. If it can't, it falls back to plain-text.