mirror of
https://github.com/Ellpeck/ObsidianJustSharePlease.git
synced 2024-11-26 20:28:34 +01:00
92 lines
4.2 KiB
HTML
92 lines
4.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Just Share Please</title>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.0/dist/jquery.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.0.5/dist/purify.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/highlight.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/markdown-it-texmath@1.0.0/texmath.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/markdown-it-anchor@8.6.7/dist/markdownItAnchor.umd.js"></script>
|
|
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter&display=swap">
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=JetBrains+Mono&display=swap">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/styles/github-dark.min.css" media="(prefers-color-scheme: dark)">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/styles/github.min.css" media="not (prefers-color-scheme: dark)">
|
|
<link rel="stylesheet" href="style.css">
|
|
<link rel="icon" href="favicon.ico">
|
|
</head>
|
|
|
|
<body>
|
|
<div class="content">
|
|
<div id="main">
|
|
<script>
|
|
let md = markdownit({
|
|
html: true,
|
|
linkify: true,
|
|
langPrefix: "hljs language-",
|
|
highlight: (c, l) => {
|
|
const language = hljs.getLanguage(l) ? l : "plaintext";
|
|
return hljs.highlight(c, {language}).value;
|
|
}
|
|
});
|
|
md.use(texmath, {
|
|
engine: katex,
|
|
delimiters: ["dollars", "beg_end"]
|
|
});
|
|
md.use(markdownItAnchor, {
|
|
permalink: markdownItAnchor.permalink.linkInsideHeader({
|
|
placement: "after",
|
|
ariaHidden: true
|
|
}),
|
|
// prepend current file id to the anchor permalink (see getId)
|
|
slugify: s => `${getId() ?? ""}-${encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, "-").replace(/[^A-Za-z0-9_-]/g, ""))}`
|
|
});
|
|
|
|
let main = $("#main");
|
|
$(window).on("hashchange", display);
|
|
display();
|
|
|
|
function display() {
|
|
let id = getId();
|
|
$.ajax({
|
|
method: "get",
|
|
url: id ? `share.php?id=${id}` : "index.md",
|
|
success: t => {
|
|
main.html(DOMPurify.sanitize(md.render(t)));
|
|
|
|
// scroll to anchor
|
|
$(() => {
|
|
let element = $(window.location.hash);
|
|
if (element.length)
|
|
$(window).scrollTop(element.offset().top);
|
|
});
|
|
},
|
|
error: (r, s, e) => main.html(`<div class="error"><p>Error loading shared note with id <code>${id}</code>: ${e}</p><p><a href="#">Home</a></p></div>`)
|
|
});
|
|
}
|
|
|
|
function getId() {
|
|
let hash = window.location.hash;
|
|
if (!hash)
|
|
return undefined;
|
|
// hashes consist of the file id, a dash and then the permalink anchor name
|
|
let dash = hash.indexOf("-");
|
|
return hash.substring(1, dash > 0 ? dash : hash.length);
|
|
}
|
|
</script>
|
|
</div>
|
|
<div id="footer">
|
|
Created using <a href="/">Just Share Please</a> for <a href="https://obsidian.md">Obsidian</a>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|