diff --git a/src/assets/css/a11y-syntax-highlighting.css b/src/assets/css/a11y-syntax-highlighting.css index 7f558cb0..98d5862d 100644 --- a/src/assets/css/a11y-syntax-highlighting.css +++ b/src/assets/css/a11y-syntax-highlighting.css @@ -1,262 +1,234 @@ -/** - * Code Credit: PrismJS a11y-dark / a11y-light theme for JavaScript, CSS, and HTML +/* + * a11y theme for JavaScript, CSS, and HTML * Based on the okaidia theme: https://github.com/PrismJS/prism/blob/gh-pages/themes/prism-okaidia.css * @author ericwbailey - * - * Modified by @author Chris Henrick on 8/4/2024 to use CSS custom properties instead of separate style sheets for light and dark themes - * See this Observable Notebook for how modifications were made: https://observablehq.com/@clhenrick/a11y-syntax-highlighting-modifications */ -:root, -:root[data-theme="light"] { - --color-syntax-1: #545454; - --color-syntax-2: #fefefe; - --color-syntax-3: #696969; - --color-syntax-4: #545454; - --color-syntax-5: #007299; - --color-syntax-6: #008000; - --color-syntax-7: #aa5d00; - --color-syntax-8: #008000; - --color-syntax-9: #aa5d00; - --color-syntax-10: #d91e18; - --color-syntax-11: #d91e18; - --color-syntax-12: rgba(183, 134, 11, 0.075); - --color-syntax-13: #b8860b; - --color-syntax-14: #b8860b; - --color-syntax-15: #aa5d00; - --color-syntax-16: #696969; -} - -:root[data-theme="dark"] { - --color-syntax-1: #f8f8f2; - --color-syntax-2: #2b2b2b; - --color-syntax-3: #d4d0ab; - --color-syntax-4: #fefefe; - --color-syntax-5: #ffa07a; - --color-syntax-6: #00e0e0; - --color-syntax-7: #abe338; - --color-syntax-8: #00e0e0; - --color-syntax-9: #ffd700; - --color-syntax-10: #00e0e0; - --color-syntax-11: #ffd700; - --color-syntax-12: rgba(255, 217, 0, 0.1); - --color-syntax-13: rgba(255, 217, 0, 0.55); - --color-syntax-14: rgba(255, 217, 0, 0.55); - --color-syntax-15: #f8f8f2; - --color-syntax-16: #d4d0ab; -} - -@media (prefers-color-scheme: dark) { - :root:not([data-theme]) { - --color-syntax-1: #f8f8f2; - --color-syntax-2: #2b2b2b; - --color-syntax-3: #d4d0ab; - --color-syntax-4: #fefefe; - --color-syntax-5: #ffa07a; - --color-syntax-6: #00e0e0; - --color-syntax-7: #abe338; - --color-syntax-8: #00e0e0; - --color-syntax-9: #ffd700; - --color-syntax-10: #00e0e0; - --color-syntax-11: #ffd700; - --color-syntax-12: rgba(255, 217, 0, 0.1); - --color-syntax-13: rgba(255, 217, 0, 0.55); - --color-syntax-14: rgba(255, 217, 0, 0.55); - --color-syntax-15: #f8f8f2; - --color-syntax-16: #d4d0ab; - } -} - /* -Theme -*/ -code[class*="language-"], -pre[class*="language-"] { - color: var(--color-syntax-1); - background: none; - font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; - font-size: 1rem; - text-align: left; - white-space: pre; - word-spacing: normal; - word-break: normal; - word-wrap: normal; - line-height: 1.5; - - -moz-tab-size: 4; - -o-tab-size: 4; - tab-size: 4; - - -webkit-hyphens: none; - -moz-hyphens: none; - -ms-hyphens: none; - hyphens: none; -} - -/* Code blocks */ -pre[class*="language-"] { - padding: 1em; - margin: 0.5em 0; - overflow: auto; - border-radius: 0.3em; -} - -pre[class*="language-"][tabindex]:focus-visible { - outline: var(--focus-style-outline); - outline-offset: var(--focus-style-width); -} - -@supports not selector(:focus-visible) { - pre[class*="language-"][tabindex]:focus { - outline: var(--focus-style-outline); - outline-offset: var(--focus-style-width); + * MARK: Setup + */ + @layer vendor-prism { + @media (forced-colors: none), (forced-colors: active) and (prefers-color-scheme: light), (prefers-color-scheme: dark) { + :root { + --prism-a11y-border-radius: 0.3em; + --prism-a11y-font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; + --prism-a11y-line-height: 1.5; + --prism-a11y-code-block-margin: 0.5em 0; + --prism-a11y-code-block-padding: 1em; + --prism-a11y-code-inline-padding: 0.1em; + --prism-a11y-width-border: 1px; + --prism-a11y-width-tab: 2; + } } -} - -:not(pre) > code[class*="language-"], -pre[class*="language-"] { - background: var(--color-syntax-2); -} - -/* Inline code */ -:not(pre) > code[class*="language-"] { - padding: 0.1em; - border-radius: 0.3em; - white-space: normal; -} - -.token.comment, -.token.prolog, -.token.doctype, -.token.cdata { - color: var(--color-syntax-3); -} - -.token.punctuation { - color: var(--color-syntax-4); -} - -.token.property, -.token.tag, -.token.constant, -.token.symbol, -.token.deleted { - color: var(--color-syntax-5); -} -.token.boolean, -.token.number { - color: var(--color-syntax-6); -} - -.token.selector, -.token.attr-name, -.token.string, -.token.char, -.token.builtin, -.token.inserted { - color: var(--color-syntax-7); -} - -.token.operator, -.token.entity, -.token.url, -.language-css .token.string, -.style .token.string, -.token.variable { - color: var(--color-syntax-8); -} - -.token.atrule, -.token.attr-value, -.token.function { - color: var(--color-syntax-9); -} - -.token.keyword { - color: var(--color-syntax-10); -} - -.token.regex, -.token.important { - color: var(--color-syntax-11); -} - -.token.important, -.token.bold { - font-weight: bold; -} -.token.italic { - font-style: italic; -} - -.token.entity { - cursor: help; -} - -/* - Plugin support -*/ - -/* Line highlight */ -.line-highlight { - background: var(--color-syntax-12); - border-top: 1px solid var(--color-syntax-13); - border-bottom: 1px solid var(--color-syntax-14); -} - -/* Line numbers */ -.line-numbers .line-numbers-rows { - border-right: 1px solid var(--color-syntax-15); -} - -.line-numbers-rows > span:before { - color: var(--color-syntax-16); -} - -/* -High contrast mode support -*/ -@media screen and (-ms-high-contrast: active) { - code[class*="language-"], - pre[class*="language-"] { - color: windowText; - background: window; + @media (forced-colors: none) and (prefers-color-scheme: light) { + :root { + --prism-a11y-color-background: hsla(0, 0%, 100%, 1); + --prism-a11y-color-text-no-token: hsla(0, 0%, 33%, 1); + --prism-a11y-color-text-comment: hsla(16, 100%, 25%, 1); + --prism-a11y-color-text-blue: hsla(195, 100%, 30%, 1); + --prism-a11y-color-text-green: hsla(120, 100%, 25%, 1); + --prism-a11y-color-text-gray: hsla(0, 0%, 41%, 1); + --prism-a11y-color-text-purple: hsla(282, 100%, 41%, 1); + --prism-a11y-color-text-red: hsla(2, 80%, 47%, 1); + --prism-a11y-color-text-yellow: hsla(43, 74%, 30%, 1); + --prism-a11y-plugin-color-border: hsla(43, 74%, 30%, 0.55); + --prism-a11y-plugin-color-background: hsla(43, 74%, 30%, 0.1); + } } - :not(pre) > code[class*="language-"], - pre[class*="language-"] { - background: window; + @media (forced-colors: none) and (prefers-color-scheme: dark) { + :root { + --prism-a11y-color-background: hsla(0, 0%, 17%, 1); + --prism-a11y-color-text-no-token: hsla(60, 30%, 96%, 1); + --prism-a11y-color-text-comment: hsla(54, 32%, 75%, 1); + --prism-a11y-color-text-blue: hsla(180, 100%, 44%, 1); + --prism-a11y-color-text-green: hsla(80, 75%, 55%, 1); + --prism-a11y-color-text-gray: hsla(60, 30%, 96%, 1); + --prism-a11y-color-text-purple: hsla(291, 30%, 83%, 1); + --prism-a11y-color-text-red: hsla(17, 100%, 74%, 1); + --prism-a11y-color-text-yellow: hsla(51, 100%, 50%, 1); + --prism-a11y-plugin-color-border: hsla(51, 100%, 50%, 0.55); + --prism-a11y-plugin-color-background: hsla(51, 100%, 50%, 0.1); + } } - .token.important { - background: highlight; - color: window; - font-weight: normal; - } - .token.atrule, - .token.attr-value, - .token.function, - .token.keyword, - .token.operator, - .token.selector { - font-weight: bold; + @media (forced-colors: none), (forced-colors: active) and (prefers-color-scheme: light), (prefers-color-scheme: dark) { + /* + * MARK: Theme + */ + :where( + code[class*="language-"], + pre[class*="language-"] + ) { + color: var(--prism-a11y-color-text-no-token); + background: var(--prism-a11y-color-background); + font-family: var(--prism-a11y-font-family); + text-align: start; + white-space: pre; + word-spacing: normal; + word-break: normal; + word-wrap: normal; + line-height: var(--prism-a11y-line-height); + + -moz-tab-size: var(--prism-a11y-width-tab); + -o-tab-size: var(--prism-a11y-width-tab); + tab-size: var(--prism-a11y-width-tab); + + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; + } + + /* Code blocks */ + pre[class*="language-"] { + padding: var(--prism-a11y-code-block-padding); + margin: var(--prism-a11y-code-block-margin); + overflow: auto; + border-radius: var(--prism-a11y-border-radius); + } + + :where( + :not(pre) > code[class*="language-"], + pre[class*="language-"] + ) { + background: var(--prism-a11y-color-background); + } + + /* Inline code */ + :not(pre) > code[class*="language-"] { + padding: var(--prism-a11y-code-inline-padding); + border-radius: var(--prism-a11y-border-radius); + white-space: normal; + } + + :where( + .token.comment, + .token.prolog, + .token.doctype, + .token.cdata + ) { + color: var(--prism-a11y-color-text-comment); + } + + .token.punctuation { + color: var(--prism-a11y-color-text-gray); + } + + :where( + .token.property, + .token.tag, + .token.constant, + .token.symbol, + .token.deleted + ) { + color: var(--prism-a11y-color-text-red); + } + + :where( + .token.operator, + .token.entity, + .token.url, + .language-css .token.string, + .style .token.string, + .token.variable, + .token.keyword + ) { + color: var(--prism-a11y-color-text-blue); + } + + :where( + .token.selector, + .token.attr-name, + .token.string, + .token.char, + .token.builtin, + .token.inserted + ) { + color: var(--prism-a11y-color-text-green); + } + + :where( + .token.atrule, + .token.attr-value, + .token.function, + .token.regex, + .token.important + ) { + color: var(--prism-a11y-color-text-yellow); + } + + :where( + .token.boolean, + .token.number, + .token.keyword + ) { + color: var(--prism-a11y-color-text-purple); + } + + :where( + .token.important, + .token.bold + ) { + font-weight: bold; + } + + .token.italic { + font-style: italic; + } + + .token.entity { + cursor: help; + } + + + /* + * MARK: Plugin support + */ + /* Line highlight */ + .line-highlight { + background: var(--prism-a11y-plugin-color-background); + border-top: var(--prism-a11y-width-border) solid var(--prism-a11y-plugin-color-border); + border-bottom: var(--prism-a11y-width-border) solid var(--prism-a11y-plugin-color-border); + } + + /* Line numbers */ + .line-numbers .line-numbers-rows { + border-right: var(--prism-a11y-width-border) solid var(--prism-a11y-color-text-no-token); + } + + .line-numbers-rows > span:before { + color: var(--prism-a11y-color-text-comment); + } } - .token.attr-value, - .token.comment, - .token.doctype, - .token.function, - .token.keyword, - .token.operator, - .token.property, - .token.string { - color: highlight; - } - .token.attr-value, - .token.url { - font-weight: normal; + /* + * MARK: Forced color mode support + */ + @media (forced-colors: active) { + :root { + --prism-a11y-color-background: Canvas; + --prism-a11y-color-text-no-token: CanvasText; + --prism-a11y-color-text-comment: GrayText; + --prism-a11y-color-text-blue: LinkText; + --prism-a11y-color-text-gray: LinkText; + --prism-a11y-color-text-green: CanvasText; + --prism-a11y-color-text-purple: CanvasText; + --prism-a11y-color-text-red: CanvasText; + --prism-a11y-color-text-yellow: GrayText; + --prism-a11y-plugin-color-border: LinkText; + --prism-a11y-plugin-color-background: Canvas; + } + + :where( + .token.boolean, + .token.number, + .token.keyword + ) { + font-weight: bold; + } } } \ No newline at end of file diff --git a/src/assets/css/general.css b/src/assets/css/general.css index 3e780c29..d49e92b8 100644 --- a/src/assets/css/general.css +++ b/src/assets/css/general.css @@ -31,9 +31,10 @@ code { word-break: break-word; } -:not(pre) > code { padding: 0.125em 0.25em; } -:not(pre) > code, -pre { background-color: var(--clr-code-bg); } +:not(pre) > code { + padding: 0.125em 0.25em; + background-color: var(--clr-code-bg); +} pre { border: 0.1em solid var(--clr-code-border);