Skip to content

Code Block Highlighting is broken #4729

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

Closed
4 tasks done
AzonInc opened this issue May 3, 2025 · 4 comments
Closed
4 tasks done

Code Block Highlighting is broken #4729

AzonInc opened this issue May 3, 2025 · 4 comments

Comments

@AzonInc
Copy link

AzonInc commented May 3, 2025

Describe the bug

Heya, I'm experiencing a weird issue with Code Blocks which started by the beginning of this year after updating to a newer version from 1.3.2.
The Highlighting used to work fine with an older version of vitepress but now it seems to be broken.

Result right now:
Image
Image

The affected file is located here: https://github.com/AzonInc/Doorman/blob/master/docs/en/guide/firmware/additions.md

Reproduction

Create a Code Block using this MD:

binary_sensor: // [!code ++] // [!code focus]
  - platform: tc_bus // [!code ++] // [!code focus]
    name: "Custom Command" // [!code ++] // [!code focus]
    type: open_door // [!code ++] // [!code focus]
    address: 0 // [!code ++] // [!code focus]
    web_server: // [!code ++] // [!code focus]
      sorting_group_id: sorting_group_listeners // [!code ++] // [!code focus]

Expected behavior

// [!code ++] // [!code focus] shouldn't be visible and also not randomly applied.

System Info

System:
    OS: Windows 11 10.0.26120
    CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
    Memory: 9.89 GB / 31.91 GB
  Binaries:
    Node: 21.1.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.2.5 - C:\Program Files\nodejs\npm.CMD
    pnpm: 6.11.0 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Chrome: 135.0.7049.116
    Edge: Chromium (136.0.3240.29)
  npmPackages:
    vitepress: ^2.0.0-alpha.5 => 2.0.0-alpha.5

Additional context

Am I doing anything wrong or is it really broken?

Validations

@AzonInc AzonInc added the bug: pending triage Maybe a bug, waiting for confirmation label May 3, 2025
@brc-dd brc-dd added upstream Related to the dependencies and removed bug: pending triage Maybe a bug, waiting for confirmation upstream Related to the dependencies labels May 3, 2025
@brc-dd
Copy link
Member

brc-dd commented May 3, 2025

You should use yaml style comments in yaml. If you were using some language with C-like comment style then // [!code... would've worked fine.

```yaml
binary_sensor: # [!code ++] [!code focus]
  - platform: tc_bus # [!code ++] [!code focus]
    name: "Custom Command" # [!code ++] [!code focus]
    type: open_door # [!code ++] [!code focus]
    address: 0 # [!code ++] [!code focus]
    web_server: # [!code ++] [!code focus]
      sorting_group_id: sorting_group_listeners # [!code ++] [!code focus]
```

Older versions were using different transformer implementation which used bunch of regexes to parse stuff instead of relying on shiki tokens.

In case of values like tc_bus // [!code ++] [!code focus] probably stuff is getting broken into multiple highlighted tokens.
In case of properties like binary_sensor: // [!code ++] [!code focus] it wasn't.
Also, when writing multiple markers in same line, you shouldn't write // or # multiple times.

@brc-dd brc-dd closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2025
@AzonInc
Copy link
Author

AzonInc commented May 3, 2025

Thanks a lot for clarification :) That worked.
However i still have a problem with comments itself.

Example:

# Extend the doorbell_pattern event entity [!code ++] [!code focus]
# Add a new apartment_special event type [!code ++] [!code focus]
event: # [!code ++] [!code focus]
  - id: !extend apartment_doorbell_pattern # [!code ++] [!code focus]
    event_types: # [!code ++] [!code focus]
      - "apartment_special" # [!code ++] [!code focus]

# Extend the apartment_doorbell / entrance_doorbell entity [!code ++] [!code focus]
# and add your new special pattern [!code ++] [!code focus]
binary_sensor: # [!code ++] [!code focus]
  - id: !extend apartment_doorbell # [!code ++] [!code focus]
    on_multi_click: # [!code ++] [!code focus]
      # Special Pattern [!code ++] [!code focus]
      - timing: # [!code ++] [!code focus]
          # Press twice with no more than one second between each press. [!code ++] [!code focus]
          - ON for at most 0.5s # [!code ++] [!code focus]
          - OFF for at most 1s # [!code ++] [!code focus]
          - ON for at most 0.5s # [!code ++] [!code focus]
          - OFF for at least 2s # [!code ++] [!code focus]
        then: # [!code ++] [!code focus]
          - logger.log: "Special pattern detected!" # [!code ++] [!code focus]
          - event.trigger: # [!code ++] [!code focus]
              id: apartment_doorbell_pattern # [!code ++] [!code focus]
              # Use the previously defined new event type here [!code ++] [!code focus]
              event_type: apartment_special # [!code ++] [!code focus]

Results in:

Image

@brc-dd
Copy link
Member

brc-dd commented May 3, 2025

Hmm, seems like the fix of shikijs/shiki#934 didn't handle all cases. For now you can do:

# Extend the doorbell_pattern event entity // [!code ++] [!code focus]
# Add a new apartment_special event type // [!code ++] [!code focus]
event: # [!code ++] [!code focus]
  - id: !extend apartment_doorbell_pattern # [!code ++] [!code focus]
    event_types: # [!code ++] [!code focus]
      - "apartment_special" # [!code ++] [!code focus]

# Extend the apartment_doorbell / entrance_doorbell entity // [!code ++] [!code focus]
# and add your new special pattern // [!code ++] [!code focus]
binary_sensor: # [!code ++] [!code focus]
  - id: !extend apartment_doorbell # [!code ++] [!code focus]
    on_multi_click: # [!code ++] [!code focus]
      # Special Pattern // [!code ++] [!code focus]
      - timing: # [!code ++] [!code focus]
          # Press twice with no more than one second between each press. // [!code ++] [!code focus]
          - ON for at most 0.5s # [!code ++] [!code focus]
          - OFF for at most 1s # [!code ++] [!code focus]
          - ON for at most 0.5s # [!code ++] [!code focus]
          - OFF for at least 2s # [!code ++] [!code focus]
        then: # [!code ++] [!code focus]
          - logger.log: "Special pattern detected!" # [!code ++] [!code focus]
          - event.trigger: # [!code ++] [!code focus]
              id: apartment_doorbell_pattern # [!code ++] [!code focus]
              # Use the previously defined new event type here // [!code ++] [!code focus]
              event_type: apartment_special # [!code ++] [!code focus]

I'll create an issue on shiki repo.

@brc-dd
Copy link
Member

brc-dd commented May 3, 2025

Please track shikijs/shiki#1007 instead.

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

No branches or pull requests

2 participants