-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer.html
More file actions
102 lines (97 loc) · 3.63 KB
/
viewer.html
File metadata and controls
102 lines (97 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!doctype html>
<html lang="tr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Problem Görüntüleyici</title>
<meta name="description" content="Markdown + LaTeX görüntüleyici">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github-dark.min.css">
<link href="assets/styles.css" rel="stylesheet">
<script>
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath: [['$$','$$'], ['\\[','\\]']]
},
svg: { fontCache: 'global' }
};
</script>
<script defer src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.1.7/dist/purify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/lib/common.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg bg-body-tertiary border-bottom">
<div class="container">
<a class="navbar-brand" href="./">Elektromanyetik Teori I</a>
<a class="btn btn-sm btn-outline-secondary ms-auto" href="./">Ana Sayfa</a>
</div>
</nav>
<main class="container my-4">
<article id="content" class="markdown-body"></article>
<div id="loading" class="text-secondary mt-3">Yükleniyor...</div>
<div id="error" class="alert alert-danger d-none mt-3">Dosya yüklenemedi.</div>
</main>
<script>
// Parse query param
const params = new URLSearchParams(location.search);
const src = params.get('src') || '';
const safe = src.startsWith('problems/') && src.endsWith('.md');
const contentEl = document.getElementById('content');
const loadingEl = document.getElementById('loading');
const errorEl = document.getElementById('error');
marked.setOptions({
gfm: true,
breaks: false,
highlight: function(code, lang) {
try { return hljs.highlight(code, {language: lang}).value; }
catch { try { return hljs.highlightAuto(code).value; } catch { return code; } }
}
});
async function typesetNow() {
if (!window.MathJax) return;
try {
// MathJax v3: hazır olana kadar bekle
if (MathJax.startup && MathJax.startup.promise) {
await MathJax.startup.promise;
}
if (MathJax.typesetPromise) {
await MathJax.typesetPromise([contentEl]);
} else if (MathJax.typeset) {
MathJax.typeset([contentEl]);
}
} catch (e) {
console.error('MathJax typeset error:', e);
}
}
async function load(){
if(!safe){
loadingEl.classList.add('d-none');
errorEl.classList.remove('d-none');
errorEl.textContent = 'Geçersiz kaynak yolu.';
return;
}
try{
const resp = await fetch(src, {cache:'no-store'});
if(!resp.ok) throw new Error('HTTP ' + resp.status);
const md = await resp.text();
const html = DOMPurify.sanitize(marked.parse(md));
contentEl.innerHTML = html;
// Başlıktan sayfa başlığı üret
const h1 = contentEl.querySelector('h1');
if(h1) document.title = h1.textContent + ' · EM Problemleri';
// MathJax typeset (hazır olduktan sonra)
await typesetNow();
}catch(e){
errorEl.classList.remove('d-none');
console.error(e);
}finally{
loadingEl.classList.add('d-none');
}
}
load();
</script>
</body>
</html>