Add linenumbering
Fix rocket dependencies
This commit is contained in:
parent
275ace8356
commit
be88df22f7
3 changed files with 30 additions and 7 deletions
|
@ -10,7 +10,7 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
owning_ref = "0.4"
|
owning_ref = "0.4"
|
||||||
linked-hash-map = "0.5"
|
linked-hash-map = "0.5"
|
||||||
rocket = { version = "0.4", default-features = false }
|
rocket = { version = "0.4.4", default-features = false }
|
||||||
askama = "0.8"
|
askama = "0.8"
|
||||||
lazy_static = "1.2"
|
lazy_static = "1.2"
|
||||||
rand = { version = "0.6", features = ["nightly"] }
|
rand = { version = "0.6", features = ["nightly"] }
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -1,5 +1,4 @@
|
||||||
#![feature(proc_macro_hygiene, decl_macro)]
|
#![feature(proc_macro_hygiene, decl_macro)]
|
||||||
#![feature(type_alias_enum_variants)]
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
@ -19,7 +18,7 @@ use params::{HostHeader, IsPlaintextRequest};
|
||||||
|
|
||||||
use askama::{Html as AskamaHtml, MarkupDisplay, Template};
|
use askama::{Html as AskamaHtml, MarkupDisplay, Template};
|
||||||
|
|
||||||
use rocket::http::{ContentType, Status};
|
use rocket::http::{ContentType, RawStr, Status};
|
||||||
use rocket::request::Form;
|
use rocket::request::Form;
|
||||||
use rocket::response::content::{Content, Html};
|
use rocket::response::content::{Content, Html};
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
|
@ -100,14 +99,22 @@ fn show_paste(key: String, plaintext: IsPlaintextRequest) -> Result<Content<Stri
|
||||||
if *plaintext {
|
if *plaintext {
|
||||||
Ok(Content(ContentType::Plain, entry.to_string()))
|
Ok(Content(ContentType::Plain, entry.to_string()))
|
||||||
} else {
|
} else {
|
||||||
let content = match ext {
|
let code_highlighted = match ext {
|
||||||
Some(extension) => match highlight(&entry, extension) {
|
Some(extension) => match highlight(&entry, extension) {
|
||||||
Some(html) => MarkupDisplay::new_safe(Cow::Owned(html), AskamaHtml),
|
Some(html) => html,
|
||||||
None => return Err(Status::NotFound),
|
None => return Err(Status::NotFound),
|
||||||
},
|
},
|
||||||
None => MarkupDisplay::new_unsafe(Cow::Borrowed(entry), AskamaHtml),
|
None => String::from(RawStr::from_str(entry).html_escape()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add <code> tags to enable line numbering with CSS
|
||||||
|
let html = format!(
|
||||||
|
"<code>{}</code>",
|
||||||
|
code_highlighted.replace("\n", "</code><code>")
|
||||||
|
);
|
||||||
|
|
||||||
|
let content = MarkupDisplay::new_safe(Cow::Borrowed(&html), AskamaHtml);
|
||||||
|
|
||||||
let template = ShowPaste { content };
|
let template = ShowPaste { content };
|
||||||
match template.render() {
|
match template.render() {
|
||||||
Ok(html) => Ok(Content(ContentType::HTML, html)),
|
Ok(html) => Ok(Content(ContentType::HTML, html)),
|
||||||
|
|
|
@ -9,7 +9,23 @@
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
|
counter-reset: line;
|
||||||
}
|
}
|
||||||
|
code {
|
||||||
|
counter-increment: line;
|
||||||
|
}
|
||||||
|
|
||||||
|
code::before {
|
||||||
|
content: counter(line);
|
||||||
|
display: inline-block;
|
||||||
|
width: 2em; /* Fixed width */
|
||||||
|
padding: 0 1em 0.3em 0;
|
||||||
|
margin-right: .5em;
|
||||||
|
color: #888;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
{% endblock styles %}
|
{% endblock styles %}
|
||||||
|
|
||||||
{% block content %}<pre><code>{{ content|safe }}</code></pre>{% endblock content %}
|
{% block content %}<pre>{{ content|safe }}</pre>{% endblock content %}
|
Loading…
Add table
Add a link
Reference in a new issue