Skip to content

Commit fb8df43

Browse files
committed
test
1 parent cefd57e commit fb8df43

File tree

3 files changed

+75
-22
lines changed

3 files changed

+75
-22
lines changed

src/components/HeadCommon.astro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ const { title } = Astro.props
5858
<!-- Scrollable a11y code helper - defer to not block render -->
5959
<script src="/make-scrollable-code-focusable.js" defer></script>
6060

61+
<!-- Prism.js for client-side syntax highlighting (to fix browser extension conflicts) -->
62+
<script is:inline>
63+
window.Prism = window.Prism || {}
64+
window.Prism.manual = true // Prevent auto-highlighting on load, we'll control it via our script
65+
</script>
66+
<script
67+
src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"
68+
integrity="sha512-9khQRAUBYEJDCDVP2yw3LRUQvjJ0Pjx0EShmaQjcHa6AXiOv6qHQu9lCAIR8O+/D8FtaCoJ2c0Tf9Xo7hYH01Q=="
69+
crossorigin="anonymous"
70+
referrerpolicy="no-referrer"
71+
defer></script>
72+
<script
73+
src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"
74+
integrity="sha512-SkmBfuA2hqjzEVpmnMt/LINrjop3GKWqsuLSSB3e7iBmYK7JuWw4ldmmxwD9mdm2IRTTi0OxSAfEGvgEi0i2Kw=="
75+
crossorigin="anonymous"
76+
referrerpolicy="no-referrer"
77+
defer></script>
78+
<script is:inline>
79+
// Configure Prism autoloader to use CDN
80+
window.Prism = window.Prism || {}
81+
window.Prism.plugins = window.Prism.plugins || {}
82+
window.Prism.plugins.autoloader = window.Prism.plugins.autoloader || {}
83+
window.Prism.plugins.autoloader.languages_path = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/"
84+
</script>
85+
6186
<!-- Preconnects to speed GTM/GA when they load -->
6287
<link rel="preconnect" href="https://www.googletagmanager.com" crossorigin />
6388
<link rel="preconnect" href="https://www.google-analytics.com" crossorigin />

src/scripts/fix-prism-extension-conflict.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ function isPrismCompromised(): boolean {
3030
// Look for code elements with language-* class but no token spans inside
3131
const codeBlocks = document.querySelectorAll('pre code[class*="language-"]')
3232

33+
console.log("[Prism Fix] Checking", codeBlocks.length, "code blocks")
34+
3335
for (const block of Array.from(codeBlocks)) {
3436
const hasTokens = block.querySelector('[class*="token"]')
3537
if (!hasTokens && block.textContent && block.textContent.trim().length > 0) {
3638
// Found a code block that should be highlighted but isn't
39+
console.log("[Prism Fix] Found compromised block:", block)
3740
return true
3841
}
3942
}
4043

44+
console.log("[Prism Fix] All code blocks appear to be properly highlighted")
4145
return false
4246
}
4347

@@ -79,16 +83,35 @@ function checkAndFix(delay = 100) {
7983
* Initialize the fix
8084
*/
8185
function init() {
82-
// Check immediately after DOM is ready
83-
if (document.readyState === "loading") {
84-
document.addEventListener("DOMContentLoaded", () => checkAndFix(50))
85-
} else {
86-
checkAndFix(50)
86+
console.log("[Prism Fix] Initializing browser extension fix")
87+
console.log("[Prism Fix] Prism available?", typeof window.Prism !== "undefined")
88+
89+
// Wait for Prism to load before attempting fixes
90+
function waitForPrism() {
91+
if (typeof window.Prism !== "undefined") {
92+
console.log("[Prism Fix] Prism loaded successfully")
93+
startChecking()
94+
} else {
95+
console.log("[Prism Fix] Waiting for Prism to load...")
96+
setTimeout(waitForPrism, 100)
97+
}
98+
}
99+
100+
function startChecking() {
101+
// Check immediately after DOM is ready
102+
if (document.readyState === "loading") {
103+
document.addEventListener("DOMContentLoaded", () => checkAndFix(50))
104+
} else {
105+
checkAndFix(50)
106+
}
107+
108+
// Check again after a short delay (in case extension runs after us)
109+
checkAndFix(200)
110+
checkAndFix(500)
111+
checkAndFix(1000)
87112
}
88113

89-
// Check again after a short delay (in case extension runs after us)
90-
checkAndFix(200)
91-
checkAndFix(500)
114+
waitForPrism()
92115

93116
// Set up a MutationObserver to detect if extension modifies code blocks
94117
const observer = new MutationObserver((mutations) => {

src/styles/index.css

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,25 @@ strong {
9292
/* Override browser extensions (1Password, etc.) that inject dark themes into INLINE code elements ONLY */
9393
/* Specifically target ONLY inline code, never code inside pre tags or with token classes */
9494
/* Target: inline code in paragraphs, tables, and CopyText components */
95-
body p > code:not([class*="token"]),
96-
body li > code:not([class*="token"]),
97-
body td > code:not([class*="token"]),
98-
body th > code:not([class*="token"]),
99-
body .copyContainer > code:not([class*="token"]),
100-
body h1 > code:not([class*="token"]),
101-
body h2 > code:not([class*="token"]),
102-
body h3 > code:not([class*="token"]),
103-
body h4 > code:not([class*="token"]),
104-
body h5 > code:not([class*="token"]),
105-
body h6 > code:not([class*="token"]),
106-
body blockquote > code:not([class*="token"]),
107-
body a > code:not([class*="token"]),
108-
body span > code:not([class*="token"]) {
95+
/* Use descendant selector (space) to catch nested code (e.g., inside <strong>) */
96+
body p code:not([class*="token"]),
97+
body li code:not([class*="token"]),
98+
body td code:not([class*="token"]),
99+
body th code:not([class*="token"]),
100+
body .copyContainer code:not([class*="token"]),
101+
body h1 code:not([class*="token"]),
102+
body h2 code:not([class*="token"]),
103+
body h3 code:not([class*="token"]),
104+
body h4 code:not([class*="token"]),
105+
body h5 code:not([class*="token"]),
106+
body h6 code:not([class*="token"]),
107+
body blockquote code:not([class*="token"]),
108+
body a code:not([class*="token"]),
109+
body strong code:not([class*="token"]),
110+
body em code:not([class*="token"]),
111+
body b code:not([class*="token"]),
112+
body i code:not([class*="token"]),
113+
body span code:not([class*="token"]) {
109114
background: var(--theme-code-inline-bg) !important;
110115
background-color: var(--theme-code-inline-bg) !important;
111116
color: var(--theme-code-inline-text) !important;

0 commit comments

Comments
 (0)