Skip to content

Commit

Permalink
v
Browse files Browse the repository at this point in the history
  • Loading branch information
julianbenegas committed Aug 18, 2024
1 parent 3be3f6d commit 544a13e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/basehub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# basehub

## 7.2.5

### Patch Changes

- Support lineNumbers out of the box

## 7.2.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/basehub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "basehub",
"description": "The first AI-native content hub.",
"author": "JB <[email protected]>",
"version": "7.2.4",
"version": "7.2.5",
"license": "MIT",
"repository": "basehub-ai/basehub",
"bugs": "https://github.com/basehub-ai/basehub/issues",
Expand Down
24 changes: 24 additions & 0 deletions packages/basehub/src/react/code-block/highlighter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type HighlighterProps = {
extraTransformers?: Array<ShikiTransformer>;
startHidden: boolean;
groupId: string;
lineNumbers?: boolean | { className?: string };
};

export const Highlighter = async ({
Expand All @@ -40,6 +41,7 @@ export const Highlighter = async ({
extraTransformers,
startHidden,
groupId,
lineNumbers,
}: HighlighterProps) => {
const hast = await codeToHast(children, {
lang,
Expand All @@ -49,6 +51,28 @@ export const Highlighter = async ({
transformerNotationErrorLevel(),
transformerNotationHighlight(),
transformerNotationWordHighlight(),
...(lineNumbers
? [
{
line(node, line) {
node.children = [
{
type: "element",
tagName: "span",
properties: {
class:
lineNumbers === true
? "line-number"
: lineNumbers.className,
},
children: [{ type: "text", value: line.toString() }],
},
...node.children,
];
},
} satisfies ShikiTransformer,
]
: []),
...(extraTransformers ?? []),
],
});
Expand Down
5 changes: 5 additions & 0 deletions packages/basehub/src/react/code-block/primitive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type CodeBlockProps = {
components?: HighlighterProps["components"];
extraTransformers?: HighlighterProps["extraTransformers"];
disableLocalStorageSelection?: boolean;
lineNumbers?: HighlighterProps["lineNumbers"];
};

export const CodeBlock = ({
Expand All @@ -24,6 +25,8 @@ export const CodeBlock = ({
childrenBottom,
components,
disableLocalStorageSelection,
extraTransformers,
lineNumbers,
}: CodeBlockProps) => {
const groupId = "__bshb_code-block-id" + Math.random().toString(16).slice(2);

Expand All @@ -47,6 +50,8 @@ export const CodeBlock = ({
components={components}
startHidden={i > 0}
groupId={groupId}
extraTransformers={extraTransformers}
lineNumbers={lineNumbers}
>
{snippet.code}
</Highlighter>
Expand Down
7 changes: 7 additions & 0 deletions playground/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# playground

## 0.0.129

### Patch Changes

- Updated dependencies
- [email protected]

## 0.0.128

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "playground",
"private": true,
"version": "0.0.128",
"version": "0.0.129",
"scripts": {
"dev": "basehub dev & next dev",
"build": "basehub && next build",
Expand Down

0 comments on commit 544a13e

Please sign in to comment.