Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 59c79f6

Browse files
committed
fix line-height of code and clean up tabs
1 parent a40cd18 commit 59c79f6

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

docs/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ Oh, and it supports basically any language, like JavaScript, TypeScript, Python,
2222
<LanguageSwitch />
2323
</div>
2424

25-
<div className="max-w-xl w-full">
25+
<div className="w-full">
2626

27-
<CodeSwitcher enableTransitions className="xl:max-h-[300px] w-full">
27+
<CodeSwitcher className="xl:max-h-[300px]">
2828

2929
```javascript !! title:services/api.js
3030
import { api } from '@nitric/sdk'

src/components/code/Code.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { highlight, RawCode } from 'codehike/code'
1+
import { RawCode } from 'codehike/code'
22
import Pre from './Pre'
33
import CodeContainer from './CodeContainer'
4-
import CODE_THEME from './theme'
54
import { meta } from './meta'
5+
import { highlight } from './highlight'
66

77
export async function Code({
88
codeblock,
99
}: {
1010
codeblock: RawCode
1111
isPanel?: boolean
1212
}) {
13-
const highlighted = await highlight(codeblock, CODE_THEME)
13+
const highlighted = await highlight(codeblock)
1414

1515
const { title } = meta(codeblock)
1616

src/components/code/CodeSwitcher.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { Suspense } from 'react'
2-
import { highlight, RawCode } from 'codehike/code'
2+
import { RawCode } from 'codehike/code'
33
import CodeContainer from './CodeContainer'
44
import { CodeSwitcherSelect } from './CodeSwitcherSelect'
5-
import CODE_THEME from './theme'
65
import Pre, { HandlerProps } from './Pre'
6+
import { highlight } from './highlight'
77

88
export async function CodeSwitcher({
99
code,
@@ -14,7 +14,7 @@ export async function CodeSwitcher({
1414
className?: string
1515
} & HandlerProps) {
1616
const highlighted = await Promise.all(
17-
code.map((codeblock) => highlight(codeblock, CODE_THEME)),
17+
code.map((codeblock) => highlight(codeblock)),
1818
)
1919

2020
return (

src/components/code/Pre.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { HighlightedCode, Pre as CodeHikePre } from 'codehike/code'
22
import React from 'react'
33
import { callout } from './annotations/callout'
44
import { CopyButton } from './CopyButton'
5-
import { className } from './annotations/classname'
65
import { fold } from './annotations/fold'
76
import {
87
collapse,
@@ -76,7 +75,7 @@ const Pre: React.FC<Props> = ({
7675
code={highlighted}
7776
handlers={handlers}
7877
className={cn(
79-
'overflow-auto overscroll-x-contain p-4',
78+
'overflow-auto overscroll-x-contain p-4 text-sm',
8079
showPanel && !title && 'pt-7', // add padding to ensure the code doesn't touch the top of the panel
8180
className,
8281
)}

src/components/code/annotations/collapse.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ export const collapse: AnnotationHandler = {
2727
},
2828
Block: ({ annotation, children }) => {
2929
return (
30-
<Collapsible
31-
className="-ml-[17px]"
32-
defaultOpen={annotation.query !== 'collapsed'}
33-
>
30+
<Collapsible defaultOpen={annotation.query !== 'collapsed'}>
3431
{children}
3532
</Collapsible>
3633
)

src/components/code/highlight.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { highlight as codehikeHighlight, RawCode } from 'codehike/code'
2+
import CODE_THEME from './theme'
3+
4+
const cleanCode = (code: RawCode) => {
5+
// Replace tabs with two spaces
6+
code.value = code.value.replace(/\t/g, ' ')
7+
8+
return code
9+
}
10+
11+
export const highlight = (data: RawCode) =>
12+
codehikeHighlight(cleanCode(data), CODE_THEME)

0 commit comments

Comments
 (0)