Merge pull request #18545 from dvdksn/code-blocks-lineno

style: numbered lines for code blocks
This commit is contained in:
David Karlsson 2023-10-31 11:45:17 +01:00 committed by GitHub
commit 9c6f0d5bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 45 deletions

View File

@ -1,30 +1,28 @@
.prose { .highlight, :not(pre) > code {
pre { font-size: .875em;
@apply rounded-sm border border-gray-light-200 p-3 dark:border-gray-dark-400; border: 1px solid;
} border-radius: theme("spacing.1");
:not(pre) > code { border-color: theme("colors.gray.light.300");
display: inline-block; .dark & {
margin: 0 !important; background: theme("colors.gray.dark.200");
white-space: nowrap; border-color: theme("colors.gray.dark.300");
font-weight: 400;
padding: 0 4px;
border: 1px solid;
border-radius: theme("spacing.1");
background: theme("colors.gray.light.200");
border-color: theme("colors.gray.light.300");
.dark & {
background: theme("colors.gray.dark.200");
border-color: theme("colors.gray.dark.300");
}
}
code::before {
content: "";
}
code::after {
content: "";
} }
} }
.highlight {
@apply p-3 my-4 overflow-x-auto;
background: theme("colors.white");
}
:not(pre) > code {
background: theme("colors.gray.light.200");
display: inline-block;
margin: 0;
white-space: nowrap;
font-weight: 400;
padding: 0 4px;
}
.chroma { .chroma {
/* LineTableTD */ /* LineTableTD */
.lntd { .lntd {
@ -380,6 +378,7 @@
} }
/* GenericPrompt */ /* GenericPrompt */
.gp { .gp {
user-select: none;
color: #8f5902; color: #8f5902;
} }
/* GenericStrong */ /* GenericStrong */

View File

@ -1,5 +1,5 @@
.prose table { .prose table {
@apply block overflow-x-auto; @apply block overflow-x-auto text-base;
thead tr { thead tr {
@apply bg-gray-light-300 dark:bg-gray-dark-300 @apply bg-gray-light-300 dark:bg-gray-dark-300
} }
@ -7,6 +7,6 @@
@apply bg-gray-light-200 dark:bg-gray-dark-200 @apply bg-gray-light-200 dark:bg-gray-dark-200
} }
th, td { th, td {
@apply p-2 !important; @apply p-2;
} }
} }

View File

@ -1,6 +1,9 @@
.prose { .prose {
li { li {
@apply mt-1 mb-1; @apply mt-1 mb-1;
& > :first-child, & > :last-child {
@apply m-0;
}
} }
a { a {
font-weight: 400; font-weight: 400;

10
assets/js/src/vars.js Normal file
View File

@ -0,0 +1,10 @@
const codeblocks = document.querySelectorAll(".highlight")
for (const codeblock of codeblocks) {
codeblock.innerHTML = codeblock.innerHTML
.replaceAll(
/<([A-Z_]+)>/g,
`<var class="text-violet-light dark:text-violet-dark"
>$1</var>`
)
}

View File

@ -1,22 +1,13 @@
{{ $innerHTML := highlight .Inner .Type <div class="group relative">
| replaceRE
`&lt;([A-Z_]+)?&gt;`
`<var
class="text-violet-light dark:text-violet-dark font-bold"
>$1</var>`
}}
<div x-data class="group relative">
<button <button
x-data="{ code: '{{encoding.Base64Encode .Inner}}' }"
class="material-symbols-rounded hidden group-hover:block absolute top-3 right-3 text-gray-light-300 dark:text-gray-dark-600" class="material-symbols-rounded hidden group-hover:block absolute top-3 right-3 text-gray-light-300 dark:text-gray-dark-600"
title="Copy" title="Copy"
@click="window.navigator.clipboard.writeText($refs.code.textContent.replaceAll(/^\$\s*/gm, '')); @click="window.navigator.clipboard.writeText(atob(code).replaceAll(/^\$\s*/gm, ''));
$el.textContent='check_circle'; $el.textContent='check_circle';
setTimeout(() => $el.textContent='content_copy', 2000);" setTimeout(() => $el.textContent='content_copy', 2000);"
> >
content_copy content_copy
</button> </button>
<div x-ref="code"> {{- highlight .Inner .Type .Options -}}
{{- safeHTML $innerHTML -}}
</div>
</div> </div>

View File

@ -7,6 +7,12 @@ module.exports = {
typography: (theme) => ({ typography: (theme) => ({
DEFAULT: { DEFAULT: {
css: { css: {
pre: false,
code: false,
'pre code': false,
'code::before': false,
'code::after': false,
table: false,
// light colors for prose // light colors for prose
"--tw-prose-body": theme("colors.black"), "--tw-prose-body": theme("colors.black"),
"--tw-prose-headings": theme("colors.black"), "--tw-prose-headings": theme("colors.black"),
@ -19,9 +25,6 @@ module.exports = {
"--tw-prose-quotes": theme("colors.black"), "--tw-prose-quotes": theme("colors.black"),
"--tw-prose-quote-borders": theme("colors.blue.light.500"), "--tw-prose-quote-borders": theme("colors.blue.light.500"),
"--tw-prose-captions": theme("colors.gray.light.600"), "--tw-prose-captions": theme("colors.gray.light.600"),
"--tw-prose-code": theme("colors.black"),
"--tw-prose-pre-code": theme("colors.gray.light.800"),
"--tw-prose-pre-bg": theme("colors.white"),
"--tw-prose-th-borders": theme("colors.gray.light.200"), "--tw-prose-th-borders": theme("colors.gray.light.200"),
"--tw-prose-td-borders": theme("colors.gray.light.200"), "--tw-prose-td-borders": theme("colors.gray.light.200"),
@ -37,9 +40,6 @@ module.exports = {
"--tw-prose-invert-quotes": theme("colors.white"), "--tw-prose-invert-quotes": theme("colors.white"),
"--tw-prose-invert-quote-borders": theme("colors.blue.dark.500"), "--tw-prose-invert-quote-borders": theme("colors.blue.dark.500"),
"--tw-prose-invert-captions": theme("colors.gray.dark.600"), "--tw-prose-invert-captions": theme("colors.gray.dark.600"),
"--tw-prose-invert-code": theme("colors.white"),
"--tw-prose-invert-pre-code": theme("colors.background.light"),
"--tw-prose-invert-pre-bg": theme("colors.gray.dark.200"),
"--tw-prose-invert-th-borders": theme("colors.gray.dark.200"), "--tw-prose-invert-th-borders": theme("colors.gray.dark.200"),
"--tw-prose-invert-td-borders": theme("colors.gray.dark.200"), "--tw-prose-invert-td-borders": theme("colors.gray.dark.200"),
}, },