Add linenumbering Fix rocket dependencies
Diff
Cargo.toml | 2 +-
src/main.rs | 17 +++++++++++++++--
templates/paste.html | 18 ++++++++++++++++++
3 files changed, 30 insertions(+), 7 deletions(-)
@@ -10,7 +10,7 @@
[dependencies]
owning_ref = "0.4"
linked-hash-map = "0.5"
rocket = { version = "0.4", default-features = false }
rocket = { version = "0.4.4", default-features = false }
askama = "0.8"
lazy_static = "1.2"
rand = { version = "0.6", features = ["nightly"] }
@@ -1,5 +1,4 @@
#![feature(proc_macro_hygiene, decl_macro)]
#![feature(type_alias_enum_variants)]
#[macro_use]
extern crate lazy_static;
@@ -19,7 +18,7 @@
use askama::{Html as AskamaHtml, MarkupDisplay, Template};
use rocket::http::{ContentType, Status};
use rocket::http::{ContentType, RawStr, Status};
use rocket::request::Form;
use rocket::response::content::{Content, Html};
use rocket::response::Redirect;
@@ -100,13 +99,21 @@
if *plaintext {
Ok(Content(ContentType::Plain, entry.to_string()))
} else {
let content = match ext {
let code_highlighted = match ext {
Some(extension) => match highlight(&entry, extension) {
Some(html) => MarkupDisplay::new_safe(Cow::Owned(html), AskamaHtml),
Some(html) => html,
None => return Err(Status::NotFound),
},
None => MarkupDisplay::new_unsafe(Cow::Borrowed(entry), AskamaHtml),
None => String::from(RawStr::from_str(entry).html_escape()),
};
let html = format!(
"<code>{}</code>",
code_highlighted.replace("\n", "</code><code>")
);
let content = MarkupDisplay::new_safe(Cow::Borrowed(&html), AskamaHtml);
let template = ShowPaste { content };
match template.render() {
@@ -9,7 +9,23 @@
font-family: inherit;
font-size: 1rem;
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 %}
{% block content %}<pre><code>{{ content|safe }}</code></pre>{% endblock content %}
{% block content %}<pre>{{ content|safe }}</pre>{% endblock content %}