-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only load unnecesary language highlight module
- Loading branch information
Showing
5 changed files
with
81 additions
and
64 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,14 @@ | ||
import hljs from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/highlight.min.js'; | ||
import css from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/languages/css.min.js'; | ||
import javascript from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/languages/javascript.min.js'; | ||
import json from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/languages/json.min.js'; | ||
import python from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/languages/python.min.js'; | ||
import yaml from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/languages/yaml.min.js'; | ||
|
||
hljs.registerLanguage('css', css); | ||
hljs.registerLanguage('javascript', javascript); | ||
hljs.registerLanguage('json', json); | ||
hljs.registerLanguage('python', python); | ||
hljs.registerLanguage('yaml', yaml); | ||
|
||
const inscription = document.documentElement.dataset.inscription; | ||
const language = document.documentElement.dataset.language; | ||
|
||
const definition = await import(`https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/languages/${language}.min.js`); | ||
|
||
hljs.registerLanguage(language, definition.default); | ||
|
||
const response = await fetch(`/content/${inscription}`); | ||
const contentType = response.headers.get("content-type"); | ||
let language = contentType.split("/")[1]; | ||
if (language === "x-python") { | ||
language = "python"; | ||
} | ||
const code = await response.text(); | ||
document.body.innerHTML = `<pre><code>${hljs.highlight(code, {language, ignoreIllegals: true}).value}</code></pre>`; | ||
const text = await response.text(); | ||
const code = document.querySelector('code'); | ||
|
||
code.innerHTML = hljs.highlight(text, {language, ignoreIllegals: true}).value; |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
<!doctype html> | ||
<html lang=en data-inscription={{self.inscription_id}}> | ||
<html lang=en data-inscription={{self.inscription_id}} data-language={{self.language}}> | ||
<head> | ||
<meta charset=utf-8> | ||
<link rel=stylesheet href=/static/preview-code.css> | ||
<script src=/static/preview-code.js defer type=module></script> | ||
</head> | ||
<body> | ||
<pre><code></code></pre> | ||
</body> | ||
</html> |