Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const md = new MarkdownIt({
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return '<pre class="hljs"><code>' +
const langLabel = `<span class="code-lang">${md.utils.escapeHtml(lang)}</span>`;
Comment thread
Syrup marked this conversation as resolved.
Outdated
return `<pre class="hljs" data-lang="${md.utils.escapeHtml(lang)}">` +
langLabel +
`<code>` +
hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
'</code></pre>';
} catch (__) {}
Expand Down
33 changes: 33 additions & 0 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ pre.hljs {
position: relative;
}

pre.hljs code {
display: block;
position: relative;
}

.code-wrapper .code-lang {
Comment thread
Syrup marked this conversation as resolved.
Outdated
position: sticky;
Comment thread
Syrup marked this conversation as resolved.
top: 0;
left: 0;
float: left;
background-color: transparent;
color: #888;
padding: 2px 6px;
font-size: 9px;
font-family: 'Courier New', monospace;
font-weight: 600;
line-height: 1;
text-transform: none;
border-top-left-radius: 2px;
border-bottom-right-radius: 3px;
user-select: none;
pointer-events: none;
margin: 0;
margin-bottom: -14px;
display: inline-block;
z-index: 1;
}

.code-wrapper {
position: relative;
display: inline-block;
Expand Down Expand Up @@ -264,6 +292,11 @@ blockquote.alert p:last-child {
margin-bottom: 0;
}

:root.dark .code-lang {
background-color: transparent !important;
color: #666 !important;
}

@media screen and (max-width: 600px) {
pre.hljs,
.code-wrapper {
Expand Down
7 changes: 6 additions & 1 deletion vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"buildCommand": "npm run build",
"outputDirectory": "dist",
"devCommand": "npm run dev",
"installCommand": "npm install"
"installCommand": "npm install",
"cleanUrls": true,
"trailingSlash": false,
"rewrites": [
{ "source": "/((?!.*\\.).*)", "destination": "/$1.html" }
]
}