rn-shiki 0.0.37-4 → 0.0.37-6
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -6
- package/src/components/syntax/SyntaxHighlighter.tsx +6 -20
- package/src/hooks/useSyntaxHighlighter.ts +1 -1
- package/src/index.ts +1 -4
- package/src/syntax/highlighter/index.ts +1 -1
- package/src/components/syntax/SyntaxLine.tsx +0 -81
- package/src/components/syntax/index.ts +0 -2
- package/src/syntax/index.ts +0 -1
- package/src/types/index.ts +0 -6
- package/src/utils/index.ts +0 -1
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "rn-shiki",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.37-
|
4
|
+
"version": "0.0.37-6",
|
5
5
|
"description": "Shiki syntax highlighter for React Native.",
|
6
6
|
"author": "Ryan Skinner <hello@ryanskinner.com>",
|
7
7
|
"license": "MIT",
|
@@ -34,21 +34,16 @@
|
|
34
34
|
"shiki": "^1.1.7"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"esbuild": "^0.24.0",
|
38
37
|
"shiki": "^1.1.7"
|
39
38
|
},
|
40
39
|
"devDependencies": {
|
41
40
|
"@antfu/eslint-config": "^3.8.0",
|
42
|
-
"@babel/core": "^7.24.0",
|
43
|
-
"@babel/preset-env": "^7.26.0",
|
44
41
|
"@eslint-react/eslint-plugin": "^1.15.0",
|
45
42
|
"@types/react": "^18.2.0",
|
46
43
|
"@types/react-native": "^0.73.0",
|
47
|
-
"babel-plugin-module-resolver": "^5.0.2",
|
48
44
|
"eslint": "^9.13.0",
|
49
45
|
"eslint-plugin-react-hooks": "^5.0.0",
|
50
46
|
"eslint-plugin-react-refresh": "^0.4.13",
|
51
|
-
"metro-react-native-babel-preset": "^0.77.0",
|
52
47
|
"react": "^18.2.0",
|
53
48
|
"react-native": "^0.73.0",
|
54
49
|
"react-native-builder-bob": "^0.30.2",
|
@@ -1,5 +1,7 @@
|
|
1
|
+
import type { ThemeRegistrationAny } from 'shiki'
|
2
|
+
import type { SyntaxHighlighterProps } from 'src/types/shiki'
|
1
3
|
import React from 'react'
|
2
|
-
import { Platform, ScrollView,
|
4
|
+
import { Platform, ScrollView, StyleSheet, Text, type TextStyle, View } from 'react-native'
|
3
5
|
import { useSyntaxHighlighter } from '../../hooks/useSyntaxHighlighter'
|
4
6
|
import { convertShikiTheme } from '../../utils/style-transformer'
|
5
7
|
|
@@ -9,15 +11,6 @@ const monospaceFont = Platform.select({
|
|
9
11
|
default: 'monospace',
|
10
12
|
})
|
11
13
|
|
12
|
-
interface SyntaxHighlighterProps {
|
13
|
-
text: string
|
14
|
-
language: any
|
15
|
-
languageId: string
|
16
|
-
theme: any
|
17
|
-
textStyle?: TextStyle
|
18
|
-
scrollViewProps?: ScrollViewProps
|
19
|
-
}
|
20
|
-
|
21
14
|
const styles = StyleSheet.create({
|
22
15
|
scrollView: {
|
23
16
|
flex: 1,
|
@@ -32,8 +25,8 @@ const styles = StyleSheet.create({
|
|
32
25
|
},
|
33
26
|
})
|
34
27
|
|
35
|
-
const SyntaxHighlighter: React.FC<SyntaxHighlighterProps> = ({ text, language, languageId, theme
|
36
|
-
const themeStyles = React.useMemo(() => convertShikiTheme(theme), [theme])
|
28
|
+
const SyntaxHighlighter: React.FC<SyntaxHighlighterProps> = ({ text, language, languageId, theme }) => {
|
29
|
+
const themeStyles = React.useMemo(() => convertShikiTheme(theme as ThemeRegistrationAny), [theme])
|
37
30
|
const { tokens } = useSyntaxHighlighter({
|
38
31
|
text,
|
39
32
|
language,
|
@@ -48,7 +41,6 @@ const SyntaxHighlighter: React.FC<SyntaxHighlighterProps> = ({ text, language, l
|
|
48
41
|
...(token.color && { color: token.color }),
|
49
42
|
...(token.fontStyle === 'italic' && themeStyles.italic),
|
50
43
|
...(token.fontWeight === 'bold' && themeStyles.bold),
|
51
|
-
...textStyle,
|
52
44
|
}
|
53
45
|
|
54
46
|
return (
|
@@ -65,13 +57,7 @@ const SyntaxHighlighter: React.FC<SyntaxHighlighterProps> = ({ text, language, l
|
|
65
57
|
)
|
66
58
|
|
67
59
|
return (
|
68
|
-
<ScrollView
|
69
|
-
horizontal
|
70
|
-
showsHorizontalScrollIndicator={Platform.OS !== 'web'}
|
71
|
-
style={styles.scrollView}
|
72
|
-
contentContainerStyle={[styles.contentContainer, themeStyles.container, scrollViewProps?.contentContainerStyle]}
|
73
|
-
{...scrollViewProps}
|
74
|
-
>
|
60
|
+
<ScrollView horizontal showsHorizontalScrollIndicator={Platform.OS !== 'web'} style={styles.scrollView}>
|
75
61
|
<View onStartShouldSetResponder={() => true}>{tokens.map((line, index) => renderLine(line, index))}</View>
|
76
62
|
</ScrollView>
|
77
63
|
)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { ThemedToken } from 'shiki'
|
2
2
|
import type { SyntaxHighlighterProps, TokensResult } from '../types/shiki'
|
3
3
|
import { useEffect, useState } from 'react'
|
4
|
-
import { createHighlighter } from '../syntax'
|
4
|
+
import { createHighlighter } from '../syntax/highlighter'
|
5
5
|
|
6
6
|
export function useSyntaxHighlighter({ text, language, languageId, theme }: SyntaxHighlighterProps) {
|
7
7
|
const [tokens, setTokens] = useState<ThemedToken[][]>([])
|
package/src/index.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { LanguageInput, ThemedToken, ThemeInput } from 'shiki'
|
2
|
-
import type { TokenType } from '../../types'
|
2
|
+
import type { TokenType } from '../../types/shiki'
|
3
3
|
import { createHighlighterCore } from 'shiki/dist/core.mjs'
|
4
4
|
import { createJavaScriptRegexEngine } from 'shiki/dist/engine-javascript.mjs'
|
5
5
|
|
@@ -1,81 +0,0 @@
|
|
1
|
-
import type { TokenType } from '../../types'
|
2
|
-
import type { RNTokenStyle } from '../../utils/style-transformer'
|
3
|
-
import React from 'react'
|
4
|
-
import { Platform, StyleSheet, Text, View } from 'react-native'
|
5
|
-
|
6
|
-
const monospaceFont = Platform.select({
|
7
|
-
ios: 'Menlo',
|
8
|
-
android: 'monospace',
|
9
|
-
default: 'monospace',
|
10
|
-
})
|
11
|
-
|
12
|
-
const styles = StyleSheet.create({
|
13
|
-
lineContainer: {
|
14
|
-
flexDirection: 'row',
|
15
|
-
flexWrap: 'wrap',
|
16
|
-
},
|
17
|
-
token: {
|
18
|
-
includeFontPadding: false,
|
19
|
-
},
|
20
|
-
})
|
21
|
-
|
22
|
-
interface SyntaxLineProps {
|
23
|
-
line: TokenType[]
|
24
|
-
fontSize?: number
|
25
|
-
isLastLine?: boolean
|
26
|
-
themeStyles: {
|
27
|
-
backgroundColor: string
|
28
|
-
defaultColor: string
|
29
|
-
styles: Record<string, RNTokenStyle>
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
function SyntaxLine({ line, fontSize = 14, isLastLine = false, themeStyles }: SyntaxLineProps) {
|
34
|
-
const lineHeight = Math.floor(fontSize * 1.5)
|
35
|
-
|
36
|
-
return (
|
37
|
-
<View
|
38
|
-
style={[
|
39
|
-
styles.lineContainer,
|
40
|
-
{
|
41
|
-
minHeight: lineHeight,
|
42
|
-
paddingBottom: !isLastLine ? 4 : 0,
|
43
|
-
},
|
44
|
-
]}
|
45
|
-
>
|
46
|
-
{line.map((token, tokenIndex) => {
|
47
|
-
const content = token.content.replace(/ /g, '\u00A0')
|
48
|
-
// Use converted theme styles
|
49
|
-
const tokenStyle = token.color ? { color: token.color } : { color: themeStyles.defaultColor }
|
50
|
-
|
51
|
-
return (
|
52
|
-
<Text
|
53
|
-
key={`${tokenIndex}-${content.slice(0, 8)}`}
|
54
|
-
style={[
|
55
|
-
styles.token,
|
56
|
-
{
|
57
|
-
...tokenStyle,
|
58
|
-
fontFamily: monospaceFont,
|
59
|
-
fontSize,
|
60
|
-
fontStyle: token.fontStyle as 'normal' | 'italic',
|
61
|
-
fontWeight: token.fontWeight as 'normal' | 'bold',
|
62
|
-
lineHeight,
|
63
|
-
height: lineHeight,
|
64
|
-
textAlignVertical: 'center',
|
65
|
-
...(Platform.OS === 'ios'
|
66
|
-
? {
|
67
|
-
paddingTop: 2,
|
68
|
-
}
|
69
|
-
: {}),
|
70
|
-
},
|
71
|
-
]}
|
72
|
-
>
|
73
|
-
{content}
|
74
|
-
</Text>
|
75
|
-
)
|
76
|
-
})}
|
77
|
-
</View>
|
78
|
-
)
|
79
|
-
}
|
80
|
-
|
81
|
-
export default SyntaxLine
|
package/src/syntax/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export { createHighlighter, processTokens } from './highlighter'
|
package/src/types/index.ts
DELETED
package/src/utils/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './string'
|