Files
go_blog/static/css/markdown.css
dsh 83866f6de2 feat: enhance frontend Markdown rendering
- Add shared BlogMD renderer (static/js/markdown.js): marked + DOMPurify
  + highlight.js pipeline with GFM support, heading id slugger with
  CJK-aware anchors, syntax highlighting, per-block copy button and
  language badge, lazy images with lightbox, external links opened
  safely in new tabs, tables wrapped for small screens.
- Add .md-body typography styles (static/css/markdown.css) so articles,
  comments and editor previews render with proper headings, tables,
  lists, blockquotes and code blocks (previously the prose classes had
  no effect because the Tailwind typography plugin is not loaded).
- Fix marked options that were set after parsing and removed from
  marked v4+ (mangle/headerIds no-ops).
- Pin CDN versions (marked 15.0.12, dompurify 3.4.13, highlight.js
  11.12.0) instead of floating 'latest' URLs.
- Wire EasyMDE preview/side-by-side to BlogMD in admin and user
  article editors; use BlogMD for comment bodies on the article page,
  admin comment list and comment preview.
- Serve /static in main.go and deploy it in install_linux.sh.
2026-08-18 06:05:53 -04:00

378 lines
8.2 KiB
CSS

/*
* markdown.css — typography and components for rendered Markdown
* (article body, comments, editor previews).
*
* All rules are scoped under .md-body so they never leak into the rest
* of the page. Sizes are written in em so the content scales with the
* container's font size (articles are base size, comments are text-sm).
*/
.md-body {
font-size: 1em;
line-height: 1.75;
color: #1f2937; /* gray-800 */
word-wrap: break-word;
overflow-wrap: break-word;
}
/* ---------- paragraphs ---------- */
.md-body p {
margin: 0 0 1em;
}
.md-body > :first-child {
margin-top: 0;
}
.md-body > :last-child {
margin-bottom: 0;
}
/* ---------- headings ---------- */
.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4,
.md-body h5,
.md-body h6 {
font-weight: 700;
color: #111827; /* gray-900 */
line-height: 1.3;
margin: 1.6em 0 0.6em;
scroll-margin-top: 1rem;
}
.md-body h1 {
font-size: 1.875em;
padding-bottom: 0.3em;
border-bottom: 1px solid #e5e7eb;
}
.md-body h2 {
font-size: 1.5em;
padding-bottom: 0.3em;
border-bottom: 1px solid #e5e7eb;
}
.md-body h3 { font-size: 1.25em; }
.md-body h4 { font-size: 1.1em; }
.md-body h5 { font-size: 1em; }
.md-body h6 {
font-size: 0.9em;
color: #4b5563; /* gray-600 */
text-transform: uppercase;
letter-spacing: 0.02em;
}
/* heading permalink (#) shown on hover */
.md-body .md-anchor {
display: inline-block;
margin-left: 0.4em;
font-size: 0.8em;
font-weight: 600;
color: #9ca3af; /* gray-400 */
text-decoration: none;
visibility: hidden;
opacity: 0;
transition: opacity 0.15s ease;
}
.md-body h1:hover .md-anchor,
.md-body h2:hover .md-anchor,
.md-body h3:hover .md-anchor,
.md-body h4:hover .md-anchor,
.md-body h5:hover .md-anchor,
.md-body h6:hover .md-anchor {
visibility: visible;
opacity: 1;
}
.md-body .md-anchor:hover {
color: #2563eb; /* blue-600 */
}
/* ---------- links ---------- */
.md-body a {
color: #2563eb; /* blue-600 */
text-decoration: none;
border-bottom: 1px solid rgba(37, 99, 235, 0.3);
transition: border-color 0.15s ease;
}
.md-body a:hover {
color: #1d4ed8; /* blue-700 */
border-bottom-color: currentColor;
}
/* ---------- emphasis ---------- */
.md-body strong { font-weight: 700; color: #111827; }
.md-body em { font-style: italic; }
.md-body del { color: #6b7280; }
.md-body mark {
background: #fef08a; /* yellow-200 */
color: #1f2937;
padding: 0 0.2em;
border-radius: 0.25em;
}
.md-body kbd {
display: inline-block;
padding: 0.15em 0.45em;
font-size: 0.85em;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
color: #374151;
background: #f9fafb;
border: 1px solid #d1d5db;
border-bottom-width: 2px;
border-radius: 0.35em;
}
/* ---------- inline code ---------- */
.md-body code {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
font-size: 0.875em;
background: #f3f4f6; /* gray-100 */
color: #111827;
padding: 0.2em 0.4em;
border-radius: 0.375em;
}
.md-body pre code {
background: transparent;
color: inherit;
padding: 0;
font-size: 0.9em;
border-radius: 0;
display: block;
overflow-x: auto;
}
/* ---------- code blocks ---------- */
.md-body pre {
position: relative;
margin: 1em 0;
padding: 1rem 1.1rem;
background: #f6f8fa; /* github light */
border: 1px solid #e5e7eb;
border-radius: 0.5rem;
overflow-x: auto;
line-height: 1.6;
tab-size: 4;
}
/* language badge (top-left) */
.md-body .md-lang {
position: absolute;
top: 0.5rem;
left: 0.9rem;
font-size: 0.65rem;
font-weight: 600;
letter-spacing: 0.06em;
text-transform: uppercase;
color: #9ca3af;
user-select: none;
pointer-events: none;
}
/* copy button (top-right, appears on hover) */
.md-body .md-copy-btn {
position: absolute;
top: 0.5rem;
right: 0.5rem;
display: inline-flex;
align-items: center;
gap: 0.3rem;
padding: 0.25rem 0.55rem;
font-size: 0.72rem;
font-weight: 500;
color: #6b7280;
background: #ffffff;
border: 1px solid #d1d5db;
border-radius: 0.375rem;
cursor: pointer;
opacity: 0;
transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
z-index: 1;
}
.md-body pre:hover .md-copy-btn {
opacity: 1;
}
.md-body .md-copy-btn:hover {
color: #1f2937;
border-color: #9ca3af;
}
.md-body .md-copy-btn.md-copied {
color: #059669; /* green-600 */
border-color: #059669;
}
.md-body .md-copy-btn svg {
width: 0.85em;
height: 0.85em;
}
@media (hover: none) {
.md-body .md-copy-btn { opacity: 1; }
}
/* ---------- lists ---------- */
.md-body ul,
.md-body ol {
margin: 0 0 1em;
padding-left: 1.6em;
}
.md-body ul { list-style: disc; }
.md-body ol { list-style: decimal; }
.md-body li {
margin: 0.3em 0;
}
.md-body li > ul,
.md-body li > ol {
margin: 0.3em 0;
}
.md-body li > p {
margin: 0.3em 0;
}
/* GFM task lists */
.md-body li:has(> input[type="checkbox"]) {
list-style: none;
margin-left: -1.6em;
}
.md-body input[type="checkbox"] {
margin-right: 0.5em;
accent-color: #2563eb;
transform: translateY(0.1em);
}
/* ---------- blockquote ---------- */
.md-body blockquote {
margin: 1em 0;
padding: 0.6em 1em;
color: #4b5563; /* gray-600 */
background: #f9fafb; /* gray-50 */
border-left: 4px solid #d1d5db;
border-radius: 0 0.5rem 0.5rem 0;
}
.md-body blockquote > :last-child {
margin-bottom: 0;
}
.md-body blockquote > :first-child {
margin-top: 0;
}
/* ---------- tables ---------- */
.md-body .md-table-wrap {
margin: 1em 0;
overflow-x: auto;
border: 1px solid #e5e7eb;
border-radius: 0.5rem;
}
.md-body table {
width: 100%;
border-collapse: collapse;
font-size: 0.95em;
}
.md-body th,
.md-body td {
padding: 0.5em 0.9em;
border: 1px solid #e5e7eb;
text-align: left;
vertical-align: top;
}
.md-body th {
font-weight: 600;
background: #f9fafb;
color: #111827;
white-space: nowrap;
}
.md-body tbody tr:nth-child(even) {
background: #f9fafb;
}
.md-body tbody tr:hover {
background: #f3f4f6;
}
/* ---------- images ---------- */
.md-body img {
max-width: 100%;
height: auto;
margin: 0.5em 0;
border-radius: 0.5rem;
cursor: zoom-in;
}
/* ---------- horizontal rule ---------- */
.md-body hr {
margin: 2em 0;
border: 0;
border-top: 1px solid #e5e7eb;
}
/* ---------- details (rendered by some md flavors) ---------- */
.md-body details {
margin: 1em 0;
padding: 0.6em 1em;
background: #f9fafb;
border: 1px solid #e5e7eb;
border-radius: 0.5rem;
}
.md-body summary {
cursor: pointer;
font-weight: 600;
color: #111827;
}
/* ---------- lightbox ---------- */
#mdLightbox {
position: fixed;
inset: 0;
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
background: rgba(17, 24, 39, 0.9);
padding: 2rem;
opacity: 0;
visibility: hidden;
transition: opacity 0.2s ease, visibility 0.2s ease;
}
#mdLightbox.open {
opacity: 1;
visibility: visible;
}
#mdLightbox img {
max-width: 92vw;
max-height: 88vh;
border-radius: 0.5rem;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
#mdLightbox .md-lightbox-close {
position: absolute;
top: 1rem;
right: 1.25rem;
width: 2.5rem;
height: 2.5rem;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
line-height: 1;
color: #e5e7eb;
background: rgba(255, 255, 255, 0.1);
border: none;
border-radius: 9999px;
cursor: pointer;
transition: background 0.15s ease;
}
#mdLightbox .md-lightbox-close:hover {
background: rgba(255, 255, 255, 0.25);
}
#mdLightbox .md-lightbox-caption {
position: absolute;
left: 0;
right: 0;
bottom: 1rem;
text-align: center;
color: #d1d5db;
font-size: 0.85rem;
padding: 0 2rem;
}
/* ---------- responsive ---------- */
@media (max-width: 640px) {
.md-body h1 { font-size: 1.6em; }
.md-body h2 { font-size: 1.35em; }
.md-body pre { padding: 0.85rem 0.9rem; }
}