feat(templates): Add syntax highlighting for code via highlight.js
Includes a static distribution of highlight.js for syntax highlighting. A sane set of languages has been chosen.
This commit is contained in:
parent
ab3f7d888a
commit
cda66c4cd3
4 changed files with 115 additions and 0 deletions
11
src/main.rs
11
src/main.rs
|
@ -78,6 +78,7 @@ use oidc::OidcExecutor;
|
|||
use rand::{OsRng, Rng};
|
||||
use render::Renderer;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use tera::Tera;
|
||||
|
||||
fn config(name: &str) -> String {
|
||||
|
@ -173,6 +174,15 @@ fn start_http_server(base_url: String,
|
|||
let bind_host = config_default("CONVERSE_BIND_HOST", "127.0.0.1:4567");
|
||||
let key = gen_session_key();
|
||||
let require_login = config_default("REQUIRE_LOGIN", "true".into()) == "true";
|
||||
let static_dir = env::var("CONVERSE_STATIC_DIR")
|
||||
.map(PathBuf::from)
|
||||
.or_else(|_| env::current_dir().map(|mut p| {
|
||||
p.push("static");
|
||||
p
|
||||
}))
|
||||
.expect("Could not determine static file directory");
|
||||
|
||||
info!("Serving static files from {:?}", static_dir);
|
||||
|
||||
server::new(move || {
|
||||
let state = AppState {
|
||||
|
@ -191,6 +201,7 @@ fn start_http_server(base_url: String,
|
|||
let app = App::with_state(state)
|
||||
.middleware(Logger::default())
|
||||
.middleware(identity)
|
||||
.handler("/static", fs::StaticFiles::new(static_dir.clone()))
|
||||
.resource("/", |r| r.method(Method::GET).with(forum_index))
|
||||
.resource("/thread/new", |r| r.method(Method::GET).with(new_thread))
|
||||
.resource("/thread/submit", |r| r.method(Method::POST).with3(submit_thread))
|
||||
|
|
99
static/highlight.css
Normal file
99
static/highlight.css
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
|
||||
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
|
||||
|
||||
*/
|
||||
|
||||
.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 0.5em;
|
||||
color: #333;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: #998;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag,
|
||||
.hljs-subst {
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hljs-number,
|
||||
.hljs-literal,
|
||||
.hljs-variable,
|
||||
.hljs-template-variable,
|
||||
.hljs-tag .hljs-attr {
|
||||
color: #008080;
|
||||
}
|
||||
|
||||
.hljs-string,
|
||||
.hljs-doctag {
|
||||
color: #d14;
|
||||
}
|
||||
|
||||
.hljs-title,
|
||||
.hljs-section,
|
||||
.hljs-selector-id {
|
||||
color: #900;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hljs-subst {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.hljs-type,
|
||||
.hljs-class .hljs-title {
|
||||
color: #458;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hljs-tag,
|
||||
.hljs-name,
|
||||
.hljs-attribute {
|
||||
color: #000080;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.hljs-regexp,
|
||||
.hljs-link {
|
||||
color: #009926;
|
||||
}
|
||||
|
||||
.hljs-symbol,
|
||||
.hljs-bullet {
|
||||
color: #990073;
|
||||
}
|
||||
|
||||
.hljs-built_in,
|
||||
.hljs-builtin-name {
|
||||
color: #0086b3;
|
||||
}
|
||||
|
||||
.hljs-meta {
|
||||
color: #999;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hljs-deletion {
|
||||
background: #fdd;
|
||||
}
|
||||
|
||||
.hljs-addition {
|
||||
background: #dfd;
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hljs-strong {
|
||||
font-weight: bold;
|
||||
}
|
2
static/highlight.js
Normal file
2
static/highlight.js
Normal file
File diff suppressed because one or more lines are too long
|
@ -9,6 +9,9 @@
|
|||
<!-- Custom CSS additions -->
|
||||
<style>img { max-width:100%; height:auto; }</style>
|
||||
<title>Converse: {{ title | safe }}</title>
|
||||
<!-- Syntax highlighting for code -->
|
||||
<link rel="stylesheet" href="/static/highlight.css">
|
||||
<script src="/static/highlight.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
|
|
Loading…
Reference in a new issue