Skip to content

Commit a2829c6

Browse files
authored
fix few issues related to READMEs rendering (#2094)
1 parent 8e1b382 commit a2829c6

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

components/Package/PackageAuthor.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export default function PackageAuthor({ author, compact }: Props) {
3636
<View>
3737
<Caption style={labelStyle}>{ghUsername}</Caption>
3838
<span style={sublabelStyle}>
39-
{author.replace(/\s*\(?https?:\/\/\S+\)?\s*/g, '').trim()}
39+
{author
40+
.replace(/\s*\(?https?:\/\/\S+\)?\s*/g, '')
41+
.replace(/[<>()]/g, '')
42+
.trim()}
4043
</span>
4144
</View>
4245
</A>

components/Package/ReadmeBox.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ export default function ReadmeBox({ packageName, githubUrl, isTemplate, loader =
103103
a: (props: any) => {
104104
if (props.href && !props.href.startsWith('//')) {
105105
if (!props.href.startsWith('http')) {
106-
return <A {...props} href={`${githubUrl}/blob/HEAD/${props.href}`} />;
106+
return (
107+
<A
108+
{...props}
109+
href={`${githubUrl}/blob/HEAD/${props.href.startsWith('/') ? props.href.slice(1) : props.href}`}
110+
/>
111+
);
107112
}
108113
return <A {...props} />;
109114
}
@@ -146,12 +151,19 @@ export default function ReadmeBox({ packageName, githubUrl, isTemplate, loader =
146151
/>
147152
),
148153
pre: ({ children }: any) => {
149-
const langClass = children.props.className;
154+
const langClass = children?.props?.className;
155+
if (langClass) {
156+
return (
157+
<ReadmeCodeBlock
158+
code={children.props.children}
159+
lang={langClass ? (langClass.split('-')[1] ?? 'sh').toLowerCase() : 'sh'}
160+
/>
161+
);
162+
}
150163
return (
151-
<ReadmeCodeBlock
152-
code={children.props.children}
153-
lang={langClass ? (langClass.split('-')[1] ?? 'sh').toLowerCase() : 'sh'}
154-
/>
164+
<div style={tw`relative my-2`} className="readme-code-block">
165+
<pre className="shiki">{children}</pre>
166+
</div>
155167
);
156168
},
157169
blockquote: ({ children }: any) => {

scenes/PackageOverviewScene.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default function PackageOverviewScene({
6464
<ReadmeBoxWithLoading
6565
packageName={packageName}
6666
isTemplate={library.template ?? false}
67-
githubUrl={library.githubUrl}
67+
githubUrl={library.github.urls.repo}
6868
/>
6969
{library.examples && library.examples.length > 0 && (
7070
<>

0 commit comments

Comments
 (0)