diff --git a/src/media.rs b/src/media.rs index 950f7a5bf8..34867403dc 100644 --- a/src/media.rs +++ b/src/media.rs @@ -51,6 +51,7 @@ impl Media { ("text/markdown;charset=utf-8", Media::Markdown, &["md"]), ("text/plain", Media::Text, &[]), ("text/plain;charset=utf-8", Media::Text, &["txt"]), + ("text/x-python", Media::Code, &["py"]), ("video/mp4", Media::Video, &["mp4"]), ("video/webm", Media::Video, &["webm"]), ]; diff --git a/static/preview-code.js b/static/preview-code.js index 1acd5f8058..1e45f3c073 100644 --- a/static/preview-code.js +++ b/static/preview-code.js @@ -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 = `
${hljs.highlight(code, {language, ignoreIllegals: true}).value}
`;