Move business logic out of main, use askama and bound the ENTRIES
This commit is contained in:
parent
3093b06b4e
commit
9d4b3ecafc
8 changed files with 156 additions and 578 deletions
21
src/highlight.rs
Normal file
21
src/highlight.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
extern crate syntect;
|
||||
|
||||
use syntect::parsing::SyntaxSet;
|
||||
use syntect::highlighting::ThemeSet;
|
||||
use syntect::easy::HighlightLines;
|
||||
use syntect::html::{styled_line_to_highlighted_html, IncludeBackground};
|
||||
|
||||
/// Takes the content of a paste and the extension passed in by the viewer and will return the content
|
||||
/// highlighted in the appropriate format in HTML.
|
||||
pub fn highlight(content: &str, ext: &str) -> Option<String> {
|
||||
lazy_static! {
|
||||
static ref SS: SyntaxSet = SyntaxSet::load_defaults_newlines();
|
||||
static ref TS: ThemeSet = ThemeSet::load_defaults();
|
||||
}
|
||||
|
||||
let syntax = SS.find_syntax_by_extension(ext)?;
|
||||
let mut h = HighlightLines::new(syntax, &TS.themes["base16-ocean.dark"]);
|
||||
let regions = h.highlight(content, &SS);
|
||||
|
||||
Some(styled_line_to_highlighted_html(®ions[..], IncludeBackground::No))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue