Skip to content

Commit

Permalink
PR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
elocremarc committed Sep 28, 2023
1 parent 6269148 commit 4a1d3ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 2 additions & 3 deletions static/preview-code.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@import url('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/atom-one-dark.min.css');
@import url('https://cdn.jsdelivr.net/npm/highlight.js@11.8.0/styles/atom-one-dark.min.css');
html {
color: #98a3ad;
background-color: #131516;
max-width: 900px;
font-family: system-ui, sans-serif;
}

}
16 changes: 12 additions & 4 deletions static/preview-code.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import hljs from 'https://cdn.jsdelivr.net/npm/highlightjs@9.16.2/+esm'
import hljs from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/es/highlight.min.js';
import javascript from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/es/languages/javascript.min.js';
import yaml from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/es/languages/yaml.min.js';
import css from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/es/languages/css.min.js';
import json from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/es/languages/json.min.js';
hljs.registerLanguage('javascript', javascript);
hljs.registerLanguage('yaml', yaml);
hljs.registerLanguage('css', css);
hljs.registerLanguage('json', json);

const inscription = document.documentElement.dataset.inscription;
const response = await fetch(`/content/${inscription}`);
const contentType = response.headers.get("content-type");
const language = contentType.split("/")[1];
const code = await response.text();
const codeBlock = document.createElement('code');
codeBlock.innerHTML = hljs.highlightAuto(code).value;
document.body.appendChild(codeBlock);
document.body.innerHTML = `<pre><code>${hljs.highlight(code, {language, ignoreIllegals: true}).value}</code></pre>`;
5 changes: 3 additions & 2 deletions templates/preview-code.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<!doctype html>
<html lang=en data-inscription={{self.inscription_id}}> <head>
<html lang=en data-inscription={{self.inscription_id}}>
<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>
</body>
</html>
</html>

0 comments on commit 4a1d3ce

Please sign in to comment.