-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6236188
commit 6177bba
Showing
8 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import 'prismjs/themes/prism-tomorrow.css'; | ||
|
||
code { | ||
background-color: #f1f5f8; | ||
border-radius: 0.5rem; | ||
color: #266193; | ||
font-size: 0.875em; | ||
font-weight: 400; | ||
padding: 0.25rem 0.5rem; | ||
} | ||
|
||
:not(pre) > code[class*='language-'], | ||
pre[class*='language-'] { | ||
border-radius: 0.5rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
let Prism; | ||
|
||
async function loadPrism() { | ||
if (Prism) { | ||
return; | ||
} | ||
|
||
Prism = await import('prismjs'); | ||
await import('prismjs/components/prism-javascript'); | ||
await import('prismjs/components/prism-json'); | ||
await import('prismjs/components/prism-markup-templating'); | ||
await import('prismjs/components/prism-php'); | ||
await import('prismjs/components/prism-scss'); | ||
await import('prismjs/components/prism-turtle'); | ||
await import('prismjs/components/prism-typescript'); | ||
} | ||
|
||
function getLanguage(element) { | ||
for (const className of element.classList) { | ||
if (!className.startsWith('language-')) { | ||
continue; | ||
} | ||
|
||
return className.substr(9); | ||
} | ||
} | ||
|
||
function highlightCodeElement(element, language) { | ||
if ( | ||
element.parentElement && | ||
element.parentElement.tagName && | ||
element.parentElement.tagName.toLowerCase() === 'pre' | ||
) { | ||
element.parentElement.classList.add(`language-${language}`); | ||
} | ||
|
||
element.innerHTML = Prism.highlight( | ||
element.innerText, | ||
Prism.languages[language], | ||
language, | ||
); | ||
} | ||
|
||
async function highlightCode() { | ||
const codeElements = document.querySelectorAll('code'); | ||
|
||
if (codeElements.length === 0) { | ||
return; | ||
} | ||
|
||
await loadPrism(); | ||
|
||
for (const codeElement of codeElements) { | ||
const language = getLanguage(codeElement); | ||
|
||
if (!language) { | ||
continue; | ||
} | ||
|
||
highlightCodeElement(codeElement, language); | ||
} | ||
} | ||
|
||
if (document.readyState === 'complete') { | ||
highlightCode(); | ||
} else { | ||
document.addEventListener('DOMContentLoaded', highlightCode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters