Skip to content

feat: improve code block feature with Expressive Code #330

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Hasenpfote
Copy link
Contributor

@Hasenpfote Hasenpfote commented Mar 4, 2025

I noticed that Expressive Code was briefly mentioned in #319, so I tried replacing the existing code block implementation with it.
Please note that this is a large-scale change, and there are still open issues related to the previous implementation.
For now, I’ve kept the features and design minimal.

Related open issues: #275
Related open PRs: #208 #283

close #319

Copy link

vercel bot commented Mar 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuwari-yags ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 5, 2025 4:01pm

@Kayxue
Copy link

Kayxue commented Mar 4, 2025

I revert changes from tutorial by other person and change the codes with file changes, but it doesn't worked.
The effect is like this, the theme is light-plus
CleanShot 2025-03-04 at 23 50 38@2x

@Hasenpfote
Copy link
Contributor Author

Hasenpfote commented Mar 5, 2025

I'm currently reviewing your repository. I've switched the light theme to rose-pine-dawn for better clarity. Everything seems to be working fine, but am I missing something?

example

One possibility is that the theme change might still be referencing cached data. Refreshing the page might resolve it.

Additionally, one noticeable difference between github-light and light-plus themes is the red line on the tabs. I believe the provided image is indeed from the light-plus theme.

example2

Themes - Expressive Code

@Kayxue
Copy link

Kayxue commented Mar 5, 2025

I'm currently reviewing your repository. I've switched the light theme to rose-pine-dawn for better clarity. Everything seems to be working fine, but am I missing something?

example

One possibility is that the theme change might still be referencing cached data. Refreshing the page might resolve it.

Additionally, one noticeable difference between github-light and light-plus themes is the red line on the tabs. I believe the provided image is indeed from the light-plus theme.

example2

Themes - Expressive Code

Sorry I mean the language badge part.
I didn't see language badge, did I miss something to change?

@Hasenpfote
Copy link
Contributor Author

The conditions for the badge to appear are as follows:

.frame:not(.has-title):not(.is-terminal)

You can check this in src/plugins/expressive-code/language-badge.ts.

The reason for this is to avoid redundancy and clutter on the screen:

  • If there is a title, the language can be identified
  • Terminals have different frame displays and can be differentiated by their titles

I don't think this is the best approach, but if you prefer to have the badge always displayed, you can simply modify the CSS.

@baka-gourd
Copy link
Contributor

related: #275

@didntchooseaname
Copy link

didntchooseaname commented Mar 5, 2025

Hello, there is an issue with the long labels on their own lines from https://expressive-code.com/key-features/text-markers/ renders like this in a vercel/netlify project :

image

The sentence is not displayed :

Codeblock in md file:

  import time
  
  # Quick, count to ten!
  for i in range(10):
      # (but not *too* quick)
      time.sleep(0.5)
      print i

With ```python {"test badge":2-5} at first.

Should render like that :
image

Work in local but breaked with vercel/netlify...

@Hasenpfote
Copy link
Contributor Author

Hasenpfote commented Mar 6, 2025

@didntchooseaname
Thank you for the report. I have confirmed the issue in my local (prod) environment as well. It may take some time to identify the cause.


Variables are broken in PROD mode, but the cause is still unknown.

prod2
prod3


@Hasenpfote
Copy link
Contributor Author

Hasenpfote commented Mar 6, 2025

@didntchooseaname
After troubleshooting, I found that the behavior changes depending on whether astro-compress is enabled. The same issue occurs with the latest version as well. Could you check if disabling astro-compress resolves the issue on your end?

// astro.config.mjs
...
export default defineConfig({
  ...
  integrations: [
    ...,
    icon({
      include: {
        "preprocess: vitePreprocess(),": ["*"],
        "fa6-brands": ["*"],
        "fa6-regular": ["*"],
        "fa6-solid": ["*"],
      },
    }),
    svelte(),
    sitemap(),
    Compress({
      CSS: false,
      HTML: false, // Add this
      Image: false,
      Action: {
        Passed: async () => true, // https://github.com/PlayForm/Compress/issues/376
      },
    }),
    expressiveCode({

Currently testing a method to resolve the issue while keeping the compression enabled.

@didntchooseaname
Copy link

@didntchooseaname After troubleshooting, I found that the behavior changes depending on whether astro-compress is enabled. The same issue occurs with the latest version as well. Could you check if disabling astro-compress resolves the issue on your end?

// astro.config.mjs
...
export default defineConfig({
  ...
  integrations: [
    ...,
    icon({
      include: {
        "preprocess: vitePreprocess(),": ["*"],
        "fa6-brands": ["*"],
        "fa6-regular": ["*"],
        "fa6-solid": ["*"],
      },
    }),
    svelte(),
    sitemap(),
    Compress({
      CSS: false,
      HTML: false, // Add this
      Image: false,
      Action: {
        Passed: async () => true, // https://github.com/PlayForm/Compress/issues/376
      },
    }),
    expressiveCode({

Currently testing a method to resolve the issue while keeping the compression enabled.

@Hasenpfote

I confirm that astro-compress cause the issue there, here is the result without:
image

@Hasenpfote
Copy link
Contributor Author

I've fixed an issue where astro-compress interfered with Expressive Code. While it may not be a perfect solution, it effectively addresses the problem. Additionally, I’ve added a new document for visual review.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add margin to code block.

.expressive-code {
  @apply mb-6;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. This feature is in the proposal phase, maintaining Expressive Code defaults.

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.

[Feature Request] 新增 Code Block with Title and Highlighting 支援
5 participants