forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add syntax highlighting for Python inscriptions (ordinals#2538)
- Loading branch information
1 parent
7e1ed85
commit 231bdda
Showing
2 changed files
with
11 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import hljs from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/highlight.min.js'; | ||
import javascript from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/languages/javascript.min.js'; | ||
import yaml from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/es/languages/yaml.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('javascript', javascript); | ||
hljs.registerLanguage('yaml', yaml); | ||
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 response = await fetch(`/content/${inscription}`); | ||
const contentType = response.headers.get("content-type"); | ||
const language = contentType.split("/")[1]; | ||
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>`; |