@awni/mdplus 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +177 -2
- package/dist/base.css +213 -0
- package/dist/cli.js +4 -0
- package/dist/comments.css +55 -0
- package/dist/comments.js +211 -0
- package/dist/hljs.cjs +4 -0
- package/dist/index.js +497 -0
- package/dist/katex-fonts.json +1 -0
- package/dist/katex.css +1 -0
- package/dist/main.js +528 -0
- package/dist/page.js +28 -0
- package/dist/reload.js +14 -0
- package/dist/tips.css +19 -0
- package/dist/tips.js +95 -0
- package/mdplus.vsix +0 -0
- package/package.json +40 -4
package/dist/page.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Theme toggle, ToC highlighting, and opening <details> for printing.
|
|
2
|
+
(function () {
|
|
3
|
+
var root = document.documentElement;
|
|
4
|
+
document.querySelector(".theme-toggle").addEventListener("click", function () {
|
|
5
|
+
var current = root.dataset.theme || (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
|
6
|
+
var next = current === "dark" ? "light" : "dark";
|
|
7
|
+
root.dataset.theme = next;
|
|
8
|
+
try { localStorage.setItem("mdplus-theme", next); } catch (e) {}
|
|
9
|
+
});
|
|
10
|
+
function update() {
|
|
11
|
+
var links = document.querySelectorAll(".toc a");
|
|
12
|
+
if (!links.length) return;
|
|
13
|
+
var current = null;
|
|
14
|
+
links.forEach(function (a) {
|
|
15
|
+
var h = document.getElementById(decodeURIComponent(a.getAttribute("href").slice(1)));
|
|
16
|
+
if (h && h.getBoundingClientRect().top < 120) current = a;
|
|
17
|
+
});
|
|
18
|
+
links.forEach(function (a) { a.classList.toggle("active", a === (current || links[0])); });
|
|
19
|
+
}
|
|
20
|
+
addEventListener("scroll", update, { passive: true });
|
|
21
|
+
addEventListener("mdplus:update", update);
|
|
22
|
+
update();
|
|
23
|
+
var opened = [];
|
|
24
|
+
addEventListener("beforeprint", function () {
|
|
25
|
+
document.querySelectorAll("details:not([open])").forEach(function (d) { d.open = true; opened.push(d); });
|
|
26
|
+
});
|
|
27
|
+
addEventListener("afterprint", function () { opened.forEach(function (d) { d.open = false; }); opened = []; });
|
|
28
|
+
})();
|
package/dist/reload.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// mdplus serve: swaps the page content in place on every save, keeping the scroll position.
|
|
2
|
+
(function () {
|
|
3
|
+
var es = new EventSource("/__mdplus/events?page=" + encodeURIComponent(location.pathname));
|
|
4
|
+
es.addEventListener("update", function (ev) {
|
|
5
|
+
var msg = JSON.parse(ev.data);
|
|
6
|
+
if (msg.styleKey !== window.__mdplusStyle) { location.reload(); return; }
|
|
7
|
+
var y = scrollY;
|
|
8
|
+
document.getElementById("mdplus-root").innerHTML = msg.root;
|
|
9
|
+
document.title = msg.title;
|
|
10
|
+
if (window.__mdplusEdit) window.__mdplusEdit.rev = msg.rev;
|
|
11
|
+
scrollTo(0, y);
|
|
12
|
+
dispatchEvent(new Event("mdplus:update"));
|
|
13
|
+
});
|
|
14
|
+
})();
|
package/dist/tips.css
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* Tooltips for citations and cross-references (tips.js); loaded only on pages that have them.
|
|
2
|
+
A card (raised in dark mode only) in the UI font for reference entries; the body font for statements, equations and figures. */
|
|
3
|
+
.mdplus-tip {
|
|
4
|
+
position: absolute; z-index: 20; max-width: min(30rem, calc(100vw - 16px)); padding: 0.6rem 0.8rem;
|
|
5
|
+
background: var(--bg);
|
|
6
|
+
background: light-dark(var(--bg), color-mix(in srgb, var(--fg) 6%, var(--bg))); color: var(--fg); border: 1px solid var(--rule); border-radius: 6px;
|
|
7
|
+
box-shadow: 0 4px 16px rgb(0 0 0 / 0.12); font-family: var(--font-ui); font-size: 0.82rem; line-height: 1.45; text-align: left;
|
|
8
|
+
}
|
|
9
|
+
.mdplus-tip > * { margin: 0; }
|
|
10
|
+
.tip-n { color: var(--muted); }
|
|
11
|
+
.mdplus-tip.tip-ref { max-width: min(36rem, calc(100vw - 16px)); max-height: 45vh; overflow: auto; font-family: var(--font-body); font-size: 0.9rem; line-height: 1.55; }
|
|
12
|
+
.tip-ref .env { margin: 0; padding: 0; border-left: 0; }
|
|
13
|
+
.tip-ref .math-display { margin: 0; overflow: visible; }
|
|
14
|
+
.tip-ref .katex-display .tag { display: none; }
|
|
15
|
+
.tip-ref figure { margin: 0; }
|
|
16
|
+
.tip-ref figure img { max-height: 12rem; width: auto; }
|
|
17
|
+
.tip-ref table { margin: 0.6rem 0 0; }
|
|
18
|
+
.tip-ref h1, .tip-ref h2, .tip-ref h3, .tip-ref h4, .tip-ref h5 { margin: 0; font-size: 1rem; }
|
|
19
|
+
@media print { .mdplus-tip { display: none !important; } }
|
package/dist/tips.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Tooltips: hovering, focusing or tapping a link with data-tip (citation or cross-reference)
|
|
2
|
+
// shows a copy of its target (reference entry, theorem, equation, figure, table or heading).
|
|
3
|
+
// Loaded only on pages with such links; in VS Code, on every preview (it then does nothing).
|
|
4
|
+
(function () {
|
|
5
|
+
if (window.__mdplusTips) return;
|
|
6
|
+
window.__mdplusTips = true;
|
|
7
|
+
var tip = null, cur = null, timer = 0, touch = false;
|
|
8
|
+
|
|
9
|
+
function linkOf(e) {
|
|
10
|
+
var a = e.target.closest && e.target.closest("a[data-tip]");
|
|
11
|
+
return a && !a.closest(".mdplus-tip") ? a : null;
|
|
12
|
+
}
|
|
13
|
+
function target(a) {
|
|
14
|
+
var id = a.getAttribute("href").slice(1), t;
|
|
15
|
+
try { id = decodeURIComponent(id); } catch (e) {}
|
|
16
|
+
t = document.getElementById(id);
|
|
17
|
+
// VS Code replaces heading ids with its own slugs; mdplus then keeps an empty anchor inside the heading.
|
|
18
|
+
if (t && !t.firstChild && t.parentElement && /^H[1-6]$/.test(t.parentElement.tagName)) t = t.parentElement;
|
|
19
|
+
return t;
|
|
20
|
+
}
|
|
21
|
+
function content(t) {
|
|
22
|
+
var c;
|
|
23
|
+
if (t.tagName === "LI") {
|
|
24
|
+
c = document.createElement("p");
|
|
25
|
+
c.innerHTML = (t.dataset.n ? '<span class="tip-n">[' + t.dataset.n + "]</span> " : "") + t.innerHTML;
|
|
26
|
+
} else c = t.cloneNode(true);
|
|
27
|
+
// No duplicate ids, and nothing VS Code's scroll sync would match (data-line, code-line).
|
|
28
|
+
[c].concat([].slice.call(c.querySelectorAll("[id], [data-line], .code-line"))).forEach(function (e) {
|
|
29
|
+
e.removeAttribute("id"); e.removeAttribute("data-line"); e.classList.remove("code-line");
|
|
30
|
+
});
|
|
31
|
+
return c;
|
|
32
|
+
}
|
|
33
|
+
// Below the link, or above when there is no room below; inside the window horizontally.
|
|
34
|
+
function place(a) {
|
|
35
|
+
tip.style.left = tip.style.top = "0px";
|
|
36
|
+
var o = tip.getBoundingClientRect(), rs = a.getClientRects(), f = rs[0], l = rs[rs.length - 1];
|
|
37
|
+
var w = tip.offsetWidth, h = tip.offsetHeight, vw = document.documentElement.clientWidth, gap = 6;
|
|
38
|
+
var below = l.bottom + gap + h <= innerHeight || f.top - gap - h < 0;
|
|
39
|
+
var x = Math.max(8, Math.min((below ? l : f).left, vw - w - 8)), y = below ? l.bottom + gap : f.top - gap - h;
|
|
40
|
+
tip.style.left = x - o.left + "px";
|
|
41
|
+
tip.style.top = y - o.top + "px";
|
|
42
|
+
}
|
|
43
|
+
function show(a) {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
if (cur === a) return;
|
|
46
|
+
hide();
|
|
47
|
+
var t = target(a);
|
|
48
|
+
if (!t) return;
|
|
49
|
+
tip = document.createElement("div");
|
|
50
|
+
tip.id = "mdplus-tip";
|
|
51
|
+
tip.className = "mdplus-tip" + (a.classList.contains("cite") ? "" : " tip-ref");
|
|
52
|
+
tip.setAttribute("role", "tooltip");
|
|
53
|
+
tip.appendChild(content(t));
|
|
54
|
+
tip.addEventListener("mouseenter", function () { clearTimeout(timer); });
|
|
55
|
+
tip.addEventListener("mouseleave", later);
|
|
56
|
+
document.body.appendChild(tip);
|
|
57
|
+
place(a);
|
|
58
|
+
cur = a;
|
|
59
|
+
a.setAttribute("aria-describedby", "mdplus-tip");
|
|
60
|
+
}
|
|
61
|
+
function hide() {
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
if (tip) tip.remove();
|
|
64
|
+
if (cur) cur.removeAttribute("aria-describedby");
|
|
65
|
+
tip = cur = null;
|
|
66
|
+
}
|
|
67
|
+
function later() { clearTimeout(timer); timer = setTimeout(hide, 200); }
|
|
68
|
+
|
|
69
|
+
document.addEventListener("pointerdown", function (e) { touch = e.pointerType === "touch"; }, true);
|
|
70
|
+
document.addEventListener("pointerover", function (e) {
|
|
71
|
+
var a = e.pointerType !== "touch" && linkOf(e);
|
|
72
|
+
if (a) { clearTimeout(timer); timer = setTimeout(function () { show(a); }, 120); }
|
|
73
|
+
});
|
|
74
|
+
document.addEventListener("pointerout", function (e) { if (e.pointerType !== "touch" && linkOf(e)) later(); });
|
|
75
|
+
// Keyboard focus only: a mouse click also focuses the link, but hover already handles the mouse.
|
|
76
|
+
document.addEventListener("focusin", function (e) {
|
|
77
|
+
var a = !touch && linkOf(e), kb = true;
|
|
78
|
+
try { kb = a && a.matches(":focus-visible"); } catch (err) {}
|
|
79
|
+
if (a && kb) show(a);
|
|
80
|
+
});
|
|
81
|
+
document.addEventListener("focusout", function (e) { if (linkOf(e)) later(); });
|
|
82
|
+
// Touch: the first tap shows the tip, a second tap on the same link follows it.
|
|
83
|
+
document.addEventListener("click", function (e) {
|
|
84
|
+
if (!touch) return;
|
|
85
|
+
var a = linkOf(e);
|
|
86
|
+
if (a && a !== cur) { e.preventDefault(); show(a); }
|
|
87
|
+
else if (!(tip && tip.contains(e.target))) hide();
|
|
88
|
+
});
|
|
89
|
+
document.addEventListener("keydown", function (e) { touch = false; if (e.key === "Escape") hide(); }, true);
|
|
90
|
+
// Phones fire resize when the address bar slides during a scroll: hide only when the width changes.
|
|
91
|
+
var width = innerWidth;
|
|
92
|
+
addEventListener("resize", function () { if (innerWidth !== width) { width = innerWidth; hide(); } });
|
|
93
|
+
// mdplus serve swaps the page in place; VS Code updates its preview.
|
|
94
|
+
["beforeprint", "mdplus:update", "vscode.markdown.updateContent"].forEach(function (ev) { addEventListener(ev, hide); });
|
|
95
|
+
})();
|
package/mdplus.vsix
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awni/mdplus",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Markdown plus math, callouts, theorems, cross-references and citations, rendered to fast, self-contained HTML pages.",
|
|
5
|
+
"keywords": ["markdown", "math", "katex", "latex", "theorem", "callouts", "cross-references", "citations", "bibtex", "criticmarkup", "html", "notes", "cli", "quarto"],
|
|
6
|
+
"author": "Awni Altabaa (https://github.com/Awni00)",
|
|
7
|
+
"repository": { "type": "git", "url": "git+https://github.com/Awni00/mdplus.git" },
|
|
8
|
+
"homepage": "https://github.com/Awni00/mdplus#readme",
|
|
9
|
+
"bugs": "https://github.com/Awni00/mdplus/issues",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"bin": { "mdplus": "dist/cli.js" },
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"exports": { ".": "./dist/index.js", "./package.json": "./package.json" },
|
|
14
|
+
"files": ["dist", "mdplus.vsix"],
|
|
15
|
+
"publishConfig": { "access": "public" },
|
|
16
|
+
"engines": { "node": ">=20" },
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "node build.mjs",
|
|
19
|
+
"prepare": "node build.mjs",
|
|
20
|
+
"prepublishOnly": "npm run typecheck && npm test",
|
|
21
|
+
"prepack": "npm run vsix",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"test": "node build.mjs && node --test --test-concurrency=1 test/*.test.mjs",
|
|
24
|
+
"bench": "node build.mjs && node --test test/bench.test.mjs",
|
|
25
|
+
"vsix": "node build.mjs && cd vscode && vsce package --no-dependencies --skip-license -o ../mdplus.vsix"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/markdown-it": "^14.1.2",
|
|
30
|
+
"@types/node": "^22.10.0",
|
|
31
|
+
"@types/vscode": "^1.90.0",
|
|
32
|
+
"@vscode/vsce": "^3.6.0",
|
|
33
|
+
"esbuild": "^0.25.0",
|
|
34
|
+
"highlight.js": "^11.11.1",
|
|
35
|
+
"katex": "^0.16.47",
|
|
36
|
+
"markdown-it": "^14.1.0",
|
|
37
|
+
"markdown-it-container": "^4.0.0",
|
|
38
|
+
"markdown-it-footnote": "^4.0.0",
|
|
39
|
+
"typescript": "^5.9.3",
|
|
40
|
+
"yaml": "^2.8.0"
|
|
41
|
+
}
|
|
42
|
+
}
|