/**
* Lightweight markdown → HTML for offline 小红书小工具.
* Images: park as @@IMGn@@ then emit
after escape — never escape HTML tags as text.
* No eval / network / Worker.
*/
(function (global) {
function themeColors(theme) {
if (theme === "light") {
return {
text: "#1e1630",
muted: "#6d6286",
accent: "#db2777",
accentSoft: "rgba(219,39,119,.1)",
code: "#7c3aed",
strong: "#120f1d",
};
}
if (theme === "sepia") {
return {
text: "#3d2f1f",
muted: "#8a7358",
accent: "#c2410c",
accentSoft: "rgba(194,65,12,.12)",
code: "#c2410c",
strong: "#2a1f14",
};
}
return {
text: "#f3eefc",
muted: "#b4a9c8",
accent: "#ff7ab6",
accentSoft: "rgba(255,122,182,.14)",
code: "#c4b5fd",
strong: "#ffffff",
};
}
function escapeHtml(s) {
return String(s)
.replace(/&/g, "&")
.replace(//g, ">");
}
function inline(s, c) {
return escapeHtml(s)
.replace(/\*\*(.+?)\*\*/g, '$1')
.replace(/\*(.+?)\*/g, '$1')
.replace(/`([^`]+)`/g, '$1')
.replace(
/\[(.+?)\]\((https?:\/\/.+?)\)/g,
'$1',
);
}
function imgHtml(src, alt, width) {
var style = width
? 'style="max-width:100%;width:' +
width +
'px;height:auto;display:block;margin:12px auto;border-radius:8px;"'
: 'style="max-width:100%;height:auto;display:block;margin:12px auto;border-radius:8px;"';
return (
'
.replace(/)
"
);
}
function markdownToHtml(src, opts) {
opts = opts || {};
var dropCap = opts.dropCap !== false;
var c = themeColors(opts.theme || "dark");
var text = String(src || "").replace(/\r\n/g, "\n");
text = text.replace(//g, "");
text = text.replace(/