Optionally parse as markdown if requested on query params

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-12-26 00:16:19 +05:30
parent 62b3c30a48
commit 1156085333
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5
3 changed files with 20 additions and 7 deletions

View file

@ -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))

View file

@ -1,4 +0,0 @@
document.addEventListener("DOMContentLoaded", (event) => {
const elem = document.getElementById("pastecontent");
hljs.highlightElement(elem);
});

View file

@ -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 %}
<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>
{% 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 />