|
56 | 56 | rehypePlugin: [ |
57 | 57 | rehypeShikiFromHighlighter, |
58 | 58 | highlighter, |
59 | | - { themes: { light: "github-light-default", dark: "github-dark-default" } } |
| 59 | + { |
| 60 | + themes: { light: "github-light-default", dark: "github-dark-default" }, |
| 61 | + transformers: [ |
| 62 | + { |
| 63 | + pre(node) { |
| 64 | + node.properties["data-language"] = this.options.lang; |
| 65 | + } |
| 66 | + } |
| 67 | + ] |
| 68 | + } satisfies Parameters<typeof rehypeShikiFromHighlighter>[1] |
60 | 69 | ] |
61 | 70 | }; |
62 | 71 |
|
|
573 | 582 | :global(html.dark .shiki span) { |
574 | 583 | color: var(--shiki-dark) !important; |
575 | 584 | background-color: var(--shiki-dark-bg) !important; |
576 | | - /* Optional, if you also want font styles */ |
577 | 585 | font-style: var(--shiki-dark-font-style) !important; |
578 | 586 | font-weight: var(--shiki-dark-font-weight) !important; |
579 | 587 | text-decoration: var(--shiki-dark-text-decoration) !important; |
580 | 588 | } |
| 589 | +
|
| 590 | + :global { |
| 591 | + .shiki { |
| 592 | + /* Show line numbers */ |
| 593 | + /* Credit to https://github.com/shikijs/shiki/issues/3#issuecomment-830564854 */ |
| 594 | + code { |
| 595 | + counter-reset: step; |
| 596 | + counter-increment: step 0; |
| 597 | +
|
| 598 | + .line::before { |
| 599 | + content: counter(step); |
| 600 | + counter-increment: step; |
| 601 | + width: 1rem; |
| 602 | + margin-right: 1.5rem; |
| 603 | + display: inline-block; |
| 604 | + text-align: right; |
| 605 | + color: color-mix(in oklab, var(--color-muted-foreground) 70%, transparent); |
| 606 | + } |
| 607 | + } |
| 608 | +
|
| 609 | + /* Add language tag to code blocks */ |
| 610 | + &:is(pre[data-language]) { |
| 611 | + position: relative; |
| 612 | + border-radius: var(--radius-xl); |
| 613 | + border: 1px var(--tw-border-style) var(--color-border); |
| 614 | +
|
| 615 | + &::after { |
| 616 | + content: attr(data-language); |
| 617 | + position: absolute; |
| 618 | + inset: 0.55rem 0.55rem auto auto; |
| 619 | + padding: 0.25rem 0.5rem; |
| 620 | + background-color: var(--color-background); |
| 621 | + font-size: var(--text-xs); |
| 622 | + border-radius: var(--radius-lg); |
| 623 | + border: 1px var(--tw-border-style) var(--color-border); |
| 624 | + } |
| 625 | + } |
| 626 | + } |
| 627 | + } |
581 | 628 | </style> |
0 commit comments