Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for unknown languages & style: Update code line for… #306

Merged
merged 5 commits into from
Mar 5, 2024

Conversation

zhuozhiyongde
Copy link
Collaborator

@zhuozhiyongde zhuozhiyongde commented Mar 4, 2024

…matting

Description

通过 bundledLanguages 来获取 Shiki 支持的全部语言,Ref: shikijs/shiki#583

对于不支持的语言,在使用 Shiki 渲染前,设置语言为空,这会触发 plain text 渲染。但是保持语言标签的传递:

image

移除了代码渲染组件的判断,这可能需要进一步的代码删除工作。

如果认为存在 CodeHighlighter 可以渲染,但是 Shiki 无法渲染的情况,可能需要再改改逻辑?

修了代码行的 padding 位置,从而使得滚动条不再触碰边界:

Before:

image

After:

image

不过还发现了一个新问题,现在右侧语言 TAG 是不是有遮挡的问题(下个 commit 加个 z-index) Fixed.:

image

Linked Issues

Additional context

另外还有个问题,我感觉现有的动态导入 shiki 的对应 mjs 是不是有点太繁琐了,能否自动导入所有 shiki 可用的 mjs 呢?

@zhuozhiyongde zhuozhiyongde requested a review from Innei March 4, 2024 16:31
Copy link

github-actions bot commented Mar 4, 2024

📦 Next.js Bundle Analysis for Shiro

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 86.89 KB (🟡 +2.28 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Copy link

github-actions bot commented Mar 4, 2024

📦 Next.js Bundle Analysis for Shiro

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 86.89 KB (🟡 +2.28 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

1 similar comment
Copy link

github-actions bot commented Mar 4, 2024

📦 Next.js Bundle Analysis for Shiro

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 86.89 KB (🟡 +2.28 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

@Innei
Copy link
Owner

Innei commented Mar 5, 2024

我不想全部导入 shiki 的语言支持,因为包体积过大。

既然这样我又想对其他语言高亮做支持所以选了这种的方案,fallback 到老的 prism 高亮,这是一个纯 cdn 的方案不用考虑包大小。

@zhuozhiyongde

@zhuozhiyongde
Copy link
Collaborator Author

我不想全部导入 shiki 的语言支持,因为包体积过大。

既然这样我又想对其他语言高亮做支持所以选了这种的方案,fallback 到老的 prism 高亮,这是一个纯 cdn 的方案不用考虑包大小。

@zhuozhiyongde

唔,原来有这种的考虑在。不过对我而言,我感觉我不太会纠结这 8MB 的体积?也可能是我没有概念xd

那我先更改回原先的判断模式,然后再在自己的博客下切换到全 Shiki 吧。

Copy link

github-actions bot commented Mar 5, 2024

📦 Next.js Bundle Analysis for Shiro

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 84.58 KB (🟢 -28 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

@zhuozhiyongde
Copy link
Collaborator Author

@Innei Revert 了,但我还是想问下,如果我想完整的切换到 Shiki 的代码高亮,我应当怎么修改 Shiki.tsx 呢?

是直接将 langs:[...] 改成 langs: ()=>import('shiki/langs.mjs') 吗?

@Innei
Copy link
Owner

Innei commented Mar 5, 2024

@Innei Revert 了,但我还是想问下,如果我想完整的切换到 Shiki 的代码高亮,我应当怎么修改 Shiki.tsx 呢?

是直接将 langs:[...] 改成 langs: ()=>import('shiki/langs.mjs') 吗?

你可以试一下,8M 还是很大的。。。

@Innei Innei merged commit 59a8f61 into main Mar 5, 2024
2 checks passed
@Innei Innei deleted the arthals-pr branch March 5, 2024 11:10
@zhuozhiyongde
Copy link
Collaborator Author

@Innei Revert 了,但我还是想问下,如果我想完整的切换到 Shiki 的代码高亮,我应当怎么修改 Shiki.tsx 呢?
是直接将 langs:[...] 改成 langs: ()=>import('shiki/langs.mjs') 吗?

你可以试一下,8M 还是很大的。。。

我看 Shiki 也可以 cdn 导入啊?

https://shiki-zh-docs.vercel.app/guide/install#%E4%BD%BF%E7%94%A8-cdn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants