-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: syntax highlighter package (#418)
- Loading branch information
Showing
19 changed files
with
213 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `@assistant-ui/react-syntax-highlighter` | ||
|
||
`react-syntax-highlighter` integration for `@assistant-ui/react`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"name": "@assistant-ui/react-syntax-highlighter", | ||
"version": "0.0.1", | ||
"license": "MIT", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
} | ||
}, | ||
"source": "./src/index.ts", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"README.md" | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "tsup src/index.ts --format cjs,esm --dts --sourcemap --clean" | ||
}, | ||
"peerDependencies": { | ||
"@assistant-ui/react": "^0.3.2", | ||
"@assistant-ui/react-markdown": "^0.0.4", | ||
"@types/react": "*", | ||
"@types/react-syntax-highlighter": "*", | ||
"react": "^18", | ||
"react-syntax-highlighter": "^15.5.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@types/react": { | ||
"optional": true | ||
}, | ||
"@types/react-syntax-highlighter": { | ||
"optional": true | ||
} | ||
}, | ||
"devDependencies": { | ||
"@assistant-ui/tsconfig": "workspace:*", | ||
"eslint-config-next": "14.2.4", | ||
"tsup": "^8.1.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"provenance": true | ||
}, | ||
"homepage": "https://assistant-ui.com/", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Yonom/assistant-ui.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Yonom/assistant-ui/issues" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { | ||
makeSyntaxHighlighter, | ||
makeLightSyntaxHighlighter, | ||
makeLightAsyncSyntaxHighlighter, | ||
makePrismSyntaxHighlighter, | ||
makePrismLightSyntaxHighlighter, | ||
makePrismAsyncSyntaxHighlighter, | ||
makePrismAsyncLightSyntaxHighlighter, | ||
} from "./react-syntax-highlighter"; |
57 changes: 57 additions & 0 deletions
57
packages/react-syntax-highlighter/src/react-syntax-highlighter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"use client"; | ||
|
||
import { ComponentType, type FC } from "react"; | ||
import SyntaxHighlighter, { | ||
Prism, | ||
PrismAsync, | ||
PrismAsyncLight, | ||
PrismLight, | ||
Light, | ||
LightAsync, | ||
SyntaxHighlighterProps as SHP, | ||
} from "react-syntax-highlighter"; | ||
import type { SyntaxHighlighterProps } from "@assistant-ui/react-markdown"; | ||
|
||
const makeMakeSyntaxHighlighter = | ||
(SyntaxHighlighter: ComponentType<SHP>) => | ||
(config: Omit<SHP, "language" | "children">) => { | ||
const PrismSyntaxHighlighter: FC<SyntaxHighlighterProps> = ({ | ||
components: { Pre, Code }, | ||
language, | ||
code, | ||
}) => { | ||
return ( | ||
<SyntaxHighlighter | ||
PreTag={Pre} | ||
CodeTag={Code} | ||
{...config} | ||
language={language} | ||
> | ||
{code} | ||
</SyntaxHighlighter> | ||
); | ||
}; | ||
|
||
PrismSyntaxHighlighter.displayName = "PrismSyntaxHighlighter"; | ||
|
||
return PrismSyntaxHighlighter; | ||
}; | ||
|
||
export const makeSyntaxHighlighter = | ||
makeMakeSyntaxHighlighter(SyntaxHighlighter); | ||
|
||
export const makePrismSyntaxHighlighter = makeMakeSyntaxHighlighter(Prism); | ||
|
||
export const makePrismAsyncSyntaxHighlighter = | ||
makeMakeSyntaxHighlighter(PrismAsync); | ||
|
||
export const makePrismAsyncLightSyntaxHighlighter = | ||
makeMakeSyntaxHighlighter(PrismAsyncLight); | ||
|
||
export const makePrismLightSyntaxHighlighter = | ||
makeMakeSyntaxHighlighter(PrismLight); | ||
|
||
export const makeLightSyntaxHighlighter = makeMakeSyntaxHighlighter(Light); | ||
|
||
export const makeLightAsyncSyntaxHighlighter = | ||
makeMakeSyntaxHighlighter(LightAsync); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "@assistant-ui/tsconfig/base.json", | ||
"compilerOptions": { | ||
"paths": { | ||
"@assistant-ui/*": ["../../packages/*/src"], | ||
"@assistant-ui/react/*": ["../../packages/react/src/*"] | ||
} | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], | ||
"exclude": ["node_modules"] | ||
} |
6 changes: 3 additions & 3 deletions
6
...ct-ui/src/components/code/code-header.tsx → ...s/react-ui/src/components/code-header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
packages/react-ui/src/components/code/react-syntax-highlighter.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.