krata/_sass/addon/syntax.scss

293 lines
5.2 KiB
SCSS
Raw Normal View History

2019-11-15 17:01:33 +01:00
/*
2019-09-30 14:38:41 +02:00
* The syntax highlight.
*/
@import 'colors/syntax-light';
@import 'colors/syntax-dark';
2020-01-03 13:18:19 +01:00
2022-01-26 21:41:19 +01:00
html {
@media (prefers-color-scheme: light) {
&:not([data-mode]),
&[data-mode='light'] {
2022-01-26 21:41:19 +01:00
@include light-syntax;
}
&[data-mode='dark'] {
2022-01-26 21:41:19 +01:00
@include dark-syntax;
}
}
2022-01-26 21:41:19 +01:00
@media (prefers-color-scheme: dark) {
&:not([data-mode]),
&[data-mode='dark'] {
2022-01-26 21:41:19 +01:00
@include dark-syntax;
}
&[data-mode='light'] {
2022-01-26 21:41:19 +01:00
@include light-syntax;
}
}
}
/* -- code snippets -- */
2021-09-09 15:07:07 +02:00
%code-snippet-bg {
2023-03-23 19:46:48 +01:00
background-color: var(--highlight-bg-color);
2019-09-30 14:38:41 +02:00
}
%code-snippet-padding {
2021-12-03 09:34:26 +01:00
padding-left: 1rem;
padding-right: 1.5rem;
}
2020-02-25 10:56:03 +01:00
.highlighter-rouge {
color: var(--highlighter-rouge-color);
margin-top: 0.5rem;
2020-02-25 10:56:03 +01:00
margin-bottom: 1.2em; /* Override BS Inline-code style */
2019-09-30 14:38:41 +02:00
}
2020-02-25 10:56:03 +01:00
.highlight {
@extend %rounded;
@extend %code-snippet-bg;
2020-08-19 15:18:14 +02:00
2020-02-25 10:56:03 +01:00
@at-root figure#{&} {
@extend %code-snippet-bg;
2020-02-25 10:56:03 +01:00
}
2020-08-19 15:18:14 +02:00
2020-02-25 10:56:03 +01:00
overflow: auto;
padding-bottom: 0.75rem;
2020-08-19 15:18:14 +02:00
pre {
margin-bottom: 0;
2020-08-23 10:09:35 +02:00
font-size: $code-font-size;
2020-08-19 15:18:14 +02:00
line-height: 1.4rem;
word-wrap: normal; /* Fixed Safari overflow-x */
}
2020-02-25 10:56:03 +01:00
table {
td {
&:first-child {
display: inline-block;
margin-left: 1rem;
margin-right: 0.75rem;
}
&:last-child {
padding-right: 2rem !important;
}
pre {
overflow: visible; /* Fixed iOS safari overflow-x */
word-break: normal; /* Fixed iOS safari linenos code break */
}
2020-02-25 10:56:03 +01:00
}
}
.lineno {
text-align: right;
color: var(--highlight-lineno-color);
-webkit-user-select: none;
-moz-user-select: none;
-o-user-select: none;
-ms-user-select: none;
user-select: none;
}
} /* .highlight */
2019-09-30 14:38:41 +02:00
code {
-webkit-hyphens: none;
-ms-hyphens: none;
2019-09-30 14:38:41 +02:00
hyphens: none;
color: var(--code-color);
2020-08-19 15:18:14 +02:00
2020-02-25 10:56:03 +01:00
&.highlighter-rouge {
2020-08-23 10:09:35 +02:00
font-size: $code-font-size;
2020-06-22 15:08:36 +02:00
padding: 3px 5px;
word-break: break-word;
2020-02-25 10:56:03 +01:00
border-radius: 4px;
2020-06-22 15:08:36 +02:00
background-color: var(--inline-code-bg);
2020-02-28 17:16:47 +01:00
}
2022-01-21 10:46:01 +01:00
2022-01-22 15:41:23 +01:00
&.filepath {
background-color: inherit;
color: var(--filepath-text-color);
font-weight: 600;
padding: 0;
2020-02-28 17:16:47 +01:00
}
2020-08-19 15:18:14 +02:00
2021-10-31 22:26:32 +01:00
a > &.highlighter-rouge {
padding-bottom: 0; /* show link's underlinke */
2020-06-22 15:08:36 +02:00
color: inherit;
2020-02-28 17:16:47 +01:00
}
2020-08-19 15:18:14 +02:00
2021-10-31 22:26:32 +01:00
a:hover > &.highlighter-rouge {
2020-02-28 17:16:47 +01:00
border-bottom: none;
2020-02-25 10:56:03 +01:00
}
2020-08-19 15:18:14 +02:00
2022-01-22 15:41:23 +01:00
blockquote & {
2020-06-22 15:08:36 +02:00
color: inherit;
}
2019-09-30 14:38:41 +02:00
}
td.rouge-code {
2021-12-03 09:34:26 +01:00
@extend %code-snippet-padding;
/*
Prevent some browser extends from
changing the URL string of code block.
*/
a {
color: inherit !important;
border-bottom: none !important;
pointer-events: none;
}
2019-09-30 14:38:41 +02:00
}
2023-03-23 19:46:48 +01:00
div[class^='language-'] {
@extend %rounded;
@extend %code-snippet-bg;
box-shadow: var(--language-border-color) 0 0 0 1px;
.content > & {
2023-09-06 19:58:03 +02:00
@include ml-mr(-1rem);
2023-03-23 19:46:48 +01:00
border-radius: 0;
}
.highlight {
border-top-left-radius: 0;
border-top-right-radius: 0;
}
2023-03-23 19:46:48 +01:00
}
2020-06-08 15:44:59 +02:00
/* Hide line numbers for default, console, and terminal code snippets */
div {
2022-10-19 20:05:29 +02:00
&.nolineno,
2023-03-23 19:46:48 +01:00
&.language-plaintext,
&.language-console,
&.language-terminal {
td:first-child {
padding: 0 !important;
margin-right: 0;
2021-10-25 21:04:15 +02:00
.lineno {
display: none;
}
}
}
}
2021-09-09 15:07:07 +02:00
.code-header {
2021-12-03 09:34:26 +01:00
@extend %no-cursor;
2021-09-09 16:09:07 +02:00
display: flex;
justify-content: space-between;
align-items: center;
2021-12-03 09:34:26 +01:00
height: $code-header-height;
margin-left: 0.75rem;
2023-09-24 16:11:02 +02:00
margin-right: 0.25rem;
/* the label block */
2021-09-22 12:25:46 +02:00
span {
line-height: $code-header-height;
/* label icon */
2021-09-29 10:34:22 +02:00
i {
2021-12-03 09:34:26 +01:00
font-size: 1rem;
width: $code-icon-width;
2021-12-03 09:34:26 +01:00
color: var(--code-header-icon-color);
&.small {
font-size: 70%;
}
2021-09-29 10:34:22 +02:00
}
@at-root [file] #{&} > i {
2021-09-22 12:25:46 +02:00
position: relative;
top: 1px; /* center the file icon */
2021-09-15 16:50:28 +02:00
}
2021-09-22 12:25:46 +02:00
/* label text */
2021-12-03 09:34:26 +01:00
&::after {
content: attr(data-label-text);
2021-12-03 09:34:26 +01:00
font-size: 0.85rem;
font-weight: 600;
color: var(--code-header-text-color);
}
}
2021-09-09 16:09:07 +02:00
/* clipboard */
2021-09-09 16:09:07 +02:00
button {
2021-12-03 09:34:26 +01:00
@extend %cursor-pointer;
@extend %rounded;
2021-12-03 09:34:26 +01:00
border: 1px solid transparent;
height: $code-header-height;
width: $code-header-height;
2021-09-15 08:36:37 +02:00
padding: 0;
2021-09-09 16:09:07 +02:00
background-color: inherit;
2021-12-03 09:34:26 +01:00
i {
color: var(--code-header-icon-color);
}
&[timeout] {
2021-09-22 16:21:33 +02:00
&:hover {
border-color: var(--clipboard-checked-color);
}
i {
color: var(--clipboard-checked-color);
}
2021-09-15 08:36:37 +02:00
}
2022-10-19 20:05:29 +02:00
&:focus {
outline: none;
}
&:not([timeout]):hover {
2021-09-22 16:21:33 +02:00
background-color: rgba(128, 128, 128, 0.37);
i {
2021-09-22 12:25:46 +02:00
color: white;
}
2021-09-09 16:09:07 +02:00
}
}
}
@media all and (min-width: 576px) {
2023-03-23 19:46:48 +01:00
div[class^='language-'] {
.content > & {
2023-03-23 19:46:48 +01:00
@include ml-mr(0);
2021-09-09 15:07:07 +02:00
2023-03-23 19:46:48 +01:00
border-radius: $base-radius;
}
2021-09-29 10:34:22 +02:00
2023-03-23 19:46:48 +01:00
.code-header {
@include ml-mr(0);
2023-09-24 16:11:02 +02:00
$dot-margin: 1rem;
2023-03-23 19:46:48 +01:00
&::before {
2023-03-23 19:46:48 +01:00
content: '';
display: inline-block;
margin-left: $dot-margin;
width: $code-dot-size;
height: $code-dot-size;
2023-03-23 19:46:48 +01:00
border-radius: 50%;
background-color: var(--code-header-muted-color);
box-shadow: ($code-dot-size + $code-dot-gap) 0 0
var(--code-header-muted-color),
($code-dot-size + $code-dot-gap) * 2 0 0
var(--code-header-muted-color);
}
span {
// center the text of label
margin-left: calc(($dot-margin + $code-dot-size) / 2 * -1);
2021-09-09 15:07:07 +02:00
}
}
}
}