mirror of
https://github.com/coalaura/whiskr.git
synced 2025-12-02 20:22:52 +00:00
file parsing and previewing
This commit is contained in:
44
internal/preview.html
Normal file
44
internal/preview.html
Normal file
@@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<link href="/lib/catppuccin.min.css" rel="stylesheet" />
|
||||
<link href="/css/preview.css" rel="stylesheet" />
|
||||
|
||||
<title>File Preview</title>
|
||||
|
||||
<script>
|
||||
const data = {{ . | json }};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<pre><code></code></pre>
|
||||
|
||||
<script src="/lib/highlight.min.js"></script>
|
||||
<script>
|
||||
const title = document.querySelector("title"),
|
||||
body = document.querySelector("code");
|
||||
|
||||
title.innerText = data.name;
|
||||
|
||||
body.innerHTML = hljs.highlightAuto(data.content).value;
|
||||
|
||||
addEventListener("keydown", event => {
|
||||
if ((event.ctrlKey || event.metaKey) && event.key === "S") {
|
||||
event.preventDefault();
|
||||
|
||||
const el = document.createElement("a");
|
||||
|
||||
el.download = data.name;
|
||||
el.href = `data:text/plain;base64,${btoa(data.content)}`;
|
||||
|
||||
el.click();
|
||||
} else if (event.key === "Escape") {
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user