|
1 | | -<!DOCTYPE html> |
| 1 | +<!doctype html> |
2 | 2 | <html lang="en"> |
3 | 3 | <head> |
4 | 4 | <meta charset="UTF-8" /> |
|
65 | 65 | margin-bottom: 0; |
66 | 66 | } |
67 | 67 |
|
68 | | - /* Style for [!Important] callouts */ |
69 | | - .markdown-body blockquote:has(strong:first-child) { |
| 68 | + .markdown-alert { |
| 69 | + padding: 0.5rem 1rem; |
| 70 | + margin: 0 0 1rem 0; |
| 71 | + border-left: 0.25rem solid #30363d; |
| 72 | + background-color: #161b22; |
| 73 | + } |
| 74 | + |
| 75 | + .markdown-alert-title { |
| 76 | + font-weight: 600; |
| 77 | + margin-bottom: 0.25rem; |
| 78 | + } |
| 79 | + |
| 80 | + .markdown-alert-note { |
| 81 | + border-left-color: #58a6ff; |
| 82 | + } |
| 83 | + |
| 84 | + .markdown-alert-tip { |
| 85 | + border-left-color: #3fb950; |
| 86 | + } |
| 87 | + |
| 88 | + .markdown-alert-important { |
70 | 89 | border-left-color: #a371f7; |
71 | 90 | } |
72 | 91 |
|
| 92 | + .markdown-alert-warning { |
| 93 | + border-left-color: #d29922; |
| 94 | + } |
| 95 | + |
| 96 | + .markdown-alert-caution { |
| 97 | + border-left-color: #f85149; |
| 98 | + } |
| 99 | + |
73 | 100 | /* Card fills the width */ |
74 | 101 | .doc-card { |
75 | 102 | min-height: calc(100vh - 120px); |
|
380 | 407 | .replace(/src="\.\/images\//g, `src="${GITHUB_IMAGES_BASE}`); |
381 | 408 | } |
382 | 409 |
|
| 410 | + // Convert GitHub-style alerts to the same HTML structure GitHub renders |
| 411 | + function transformMarkdownAlerts(html) { |
| 412 | + const parser = new DOMParser(); |
| 413 | + const doc = parser.parseFromString(html, "text/html"); |
| 414 | + const alertTypes = { |
| 415 | + NOTE: "note", |
| 416 | + TIP: "tip", |
| 417 | + IMPORTANT: "important", |
| 418 | + WARNING: "warning", |
| 419 | + CAUTION: "caution", |
| 420 | + }; |
| 421 | + |
| 422 | + doc.querySelectorAll("blockquote").forEach((blockquote) => { |
| 423 | + const firstParagraph = blockquote.querySelector("p"); |
| 424 | + if (!firstParagraph) return; |
| 425 | + |
| 426 | + const text = firstParagraph.textContent || ""; |
| 427 | + const match = text.match( |
| 428 | + /^\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/i, |
| 429 | + ); |
| 430 | + if (!match) return; |
| 431 | + |
| 432 | + const type = match[1].toUpperCase(); |
| 433 | + const slug = alertTypes[type]; |
| 434 | + if (!slug) return; |
| 435 | + |
| 436 | + firstParagraph.textContent = text.replace(match[0], ""); |
| 437 | + |
| 438 | + const alert = doc.createElement("div"); |
| 439 | + alert.className = `markdown-alert markdown-alert-${slug}`; |
| 440 | + |
| 441 | + const title = doc.createElement("p"); |
| 442 | + title.className = "markdown-alert-title"; |
| 443 | + title.textContent = type.charAt(0) + type.slice(1).toLowerCase(); |
| 444 | + alert.appendChild(title); |
| 445 | + |
| 446 | + while (blockquote.firstChild) { |
| 447 | + alert.appendChild(blockquote.firstChild); |
| 448 | + } |
| 449 | + |
| 450 | + blockquote.replaceWith(alert); |
| 451 | + }); |
| 452 | + |
| 453 | + return doc.body.innerHTML; |
| 454 | + } |
| 455 | + |
383 | 456 | // Load and render markdown |
384 | 457 | async function loadMarkdown(docName) { |
385 | 458 | const spinner = document.getElementById("loadingSpinner"); |
|
408 | 481 | // Fix image URLs |
409 | 482 | html = fixImageUrls(html); |
410 | 483 |
|
| 484 | + // Convert GitHub-style alerts |
| 485 | + html = transformMarkdownAlerts(html); |
| 486 | + |
411 | 487 | // Sanitize HTML |
412 | 488 | html = DOMPurify.sanitize(html, { |
413 | 489 | ADD_TAGS: ["img"], |
|
439 | 515 | if (href && href.startsWith("docs.html?doc=")) { |
440 | 516 | e.preventDefault(); |
441 | 517 | const docName = new URLSearchParams(href.split("?")[1]).get( |
442 | | - "doc" |
| 518 | + "doc", |
443 | 519 | ); |
444 | 520 | if (docName) { |
445 | 521 | window.history.pushState({}, "", href); |
|
0 commit comments