Optionally parse as markdown if requested on query params
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
62b3c30a48
commit
1156085333
3 changed files with 20 additions and 7 deletions
|
@ -18,6 +18,7 @@ struct Template {
|
|||
#[derive(Deserialize)]
|
||||
struct Paste {
|
||||
paste_id: Option<String>,
|
||||
parse_md: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
@ -59,6 +60,9 @@ async fn paste_render(data: Data<Template>, paste: Query<Paste>) -> impl Respond
|
|||
paste_content = "Provide a Paste ID".to_string();
|
||||
}
|
||||
context.insert("paste_content", &paste_content);
|
||||
if paste.parse_md.is_some() {
|
||||
context.insert("md", "true");
|
||||
}
|
||||
let rendered = my_data.paste.render("paste.html", &context);
|
||||
HttpResponse::Ok()
|
||||
.insert_header(ContentType(TEXT_HTML))
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
document.addEventListener("DOMContentLoaded", (event) => {
|
||||
const elem = document.getElementById("pastecontent");
|
||||
hljs.highlightElement(elem);
|
||||
});
|
|
@ -5,14 +5,27 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="/static/tailwind.css" />
|
||||
<link rel="stylesheet" href="/static/styles.css" />
|
||||
<script src="/static/scripts.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>
|
||||
</head>
|
||||
<body class="bg-zinc-800">
|
||||
<div class="flex flex-col items-center space-y-12">
|
||||
<h2 class="text-3xl font-bold text-gray-300">Obsolute Paste</h2>
|
||||
{% block content %}
|
||||
{% if md %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<div class="w-10/12 text-gray-100 border border-solid border-emerald-200 rounded bg-zinc-800 p-2" id="pastecontent"></div>
|
||||
<script>
|
||||
document.getElementById('pastecontent').innerHTML = marked.parse(`{{paste_content}}`);
|
||||
</script>
|
||||
{% else %}
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", (event) => {
|
||||
const elem = document.getElementById("pastecontent");
|
||||
hljs.highlightElement(elem);
|
||||
});
|
||||
</script>
|
||||
<pre class="w-10/12 text-gray-100 border border-solid border-emerald-200 rounded bg-zinc-800 p-2" id="pastecontent">{{paste_content}}</pre>
|
||||
{% endif %}
|
||||
{% endblock content %}
|
||||
</div>
|
||||
<br />
|
||||
|
|
Loading…
Reference in a new issue