rn-shiki 0.0.37-16 → 0.0.37-18

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rn-shiki",
3
3
  "type": "module",
4
- "version": "0.0.37-16",
4
+ "version": "0.0.37-18",
5
5
  "description": "Shiki syntax highlighter for React Native.",
6
6
  "author": "Ryan Skinner <hello@ryanskinner.com>",
7
7
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  import type { SyntaxHighlighterProps } from 'src/types/shiki'
2
2
  import type { ReactStyle } from '../../utils/style-transformer'
3
3
  import React, { useMemo } from 'react'
4
- import { Platform, ScrollView, StyleSheet, Text, type TextStyle, View } from 'react-native'
4
+ import { Platform, ScrollView, StyleSheet, Text, View } from 'react-native'
5
5
  import { useSyntaxHighlighter } from '../../hooks/useSyntaxHighlighter'
6
6
  import { getRNStylesFromShikiStyle } from '../../utils/style-transformer'
7
7
 
@@ -38,25 +38,28 @@ const SyntaxHighlighter: React.FC<SyntaxHighlighterProps> = ({ text, language, l
38
38
  })
39
39
 
40
40
  const renderToken = (token: any, index: number, lineIndex: number) => {
41
- const tokenStyles: TextStyle = StyleSheet.flatten([
42
- stylesheet.token,
41
+ // Ensure to collect all styles associated with the token's scopes
42
+ const tokenScopes = Array.isArray(token.scope) ? token.scope : [token.scope]
43
+ const tokenStylesArray = tokenScopes.map((scope: string) => stylesheet[scope] || {})
44
+ const combinedStyles = StyleSheet.flatten([
45
+ ...tokenStylesArray,
43
46
  {
44
47
  fontFamily: monospaceFont,
45
- ...(token.color && { color: token.color }),
46
- ...(token.fontStyle === 'italic' && stylesheet.italic),
47
- ...(token.fontWeight === 'bold' && stylesheet.bold),
48
48
  },
49
+ ...(token.color && { color: token.color }),
50
+ ...(token.fontStyle && { fontStyle: token.fontStyle }),
49
51
  ])
50
52
 
51
- console.log(`Rendering token: ${token.content}, styles:`, tokenStyles)
53
+ console.log(`Rendering token: ${token.content}, styles:`, combinedStyles)
52
54
 
53
55
  return (
54
- <Text key={`${lineIndex}-${index}`} style={tokenStyles}>
56
+ <Text key={`${lineIndex}-${index}`} style={combinedStyles}>
55
57
  {token.content.replace(/ /g, '\u00A0')}
56
58
  </Text>
57
59
  )
58
60
  }
59
61
 
62
+ // In the renderLine and renderToken flow
60
63
  const renderLine = (line: any[], lineIndex: number) => {
61
64
  console.log(`Rendering line ${lineIndex}:`, line)
62
65
  return (