Skip to content

Commit e53808d

Browse files
Copilotdwjohnston
authored andcommitted
Fix syntax highlighting issue by not specifying the language.
Fix syntax highlighting for React/TypeScript files by adding language detection Co-authored-by: dwjohnston <[email protected]> Add React TSX syntax highlighting demo story and verify fix works Co-authored-by: dwjohnston <[email protected]> Sample tsx Just don't set the language Get rid of 'getLanguageFromPath' stuff
1 parent bc75e8f commit e53808d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

sample_files/sample1.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Foo(props: { name: string }) {
2+
return <div>{props.name}</div>
3+
4+
}
5+
6+
export function Demo() {
7+
return <div>
8+
<Foo name="bar" />
9+
Hello world!
10+
</div>
11+
}

src/library/GithubPermalink/GithubPermalink.stories.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ export const Primary: Story = {
2323
),
2424
};
2525

26+
export const DifferentLanguages: Story = {
27+
render: () => (<div>
28+
<p>Go</p>
29+
<GithubPermalink permalink="https://github.com/dwjohnston/react-github-permalink/blob/5b15aa07e60af4e317086f391b28cadf9aae8e1b/sample_files/sample1.go#L1-L5" />
30+
31+
<p>JavaScript</p>
32+
<GithubPermalink permalink="https://github.com/dwjohnston/react-github-permalink/blob/bc75e8fe2d1c0395c9443afe1837f453c05a7698/sample_files/sample1.js#L3-L17" />
33+
34+
<p>SQL</p>
35+
<GithubPermalink permalink="https://github.com/dwjohnston/react-github-permalink/blob/bc75e8fe2d1c0395c9443afe1837f453c05a7698/sample_files/sample1.sql#L11-L21" />
36+
37+
<p>TSX</p>
38+
<GithubPermalink permalink="https://github.com/dwjohnston/react-github-permalink/blob/242681a9df549adcc9a7fca0d8421d98b7e312c4/sample_files/sample1.tsx#L1-L11" />
39+
</div>
40+
),
41+
};
42+
2643
export const WithBackground: Story = {
2744
render: () => (
2845
<div style={{ backgroundColor: "pink", padding: "1em" }}>

src/library/SyntaxHighlight/SyntaxHighlight.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const noTheme = {
125125
export function SyntaxHighlight(props: {
126126
text: string;
127127
startingLineNumber?: number;
128-
className?: string;
128+
className?: string;
129129
}) {
130130

131131
const { startingLineNumber, text, className } = props;
@@ -141,6 +141,6 @@ export function SyntaxHighlight(props: {
141141
}, [])
142142

143143

144-
return <ReactSyntaxHighlighter className={className} style={ready ? isDarkMode ? tomorrowNight : github : noTheme} language="javascript" showLineNumbers={startingLineNumber !== undefined} startingLineNumber={startingLineNumber}>{text}</ReactSyntaxHighlighter>
144+
return <ReactSyntaxHighlighter className={className} style={ready ? isDarkMode ? tomorrowNight : github : noTheme} showLineNumbers={startingLineNumber !== undefined} startingLineNumber={startingLineNumber}>{text}</ReactSyntaxHighlighter>
145145

146146
}

0 commit comments

Comments
 (0)