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

Custom magic comments for CodeBlock with raw-loader not working #9129

Closed
6 of 7 tasks
felipecrs opened this issue Jul 7, 2023 · 8 comments
Closed
6 of 7 tasks

Custom magic comments for CodeBlock with raw-loader not working #9129

felipecrs opened this issue Jul 7, 2023 · 8 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution closed: question This issue is a user error/misunderstanding.

Comments

@felipecrs
Copy link
Contributor

felipecrs commented Jul 7, 2023

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

I think the title says everything. Custom magic comments are working on plain markdown code blocks but not on MDX CodeBlock with raw-loader.

myfile.yaml contents:

# hide-next-line
docsTitle: My File
# hide-start
docsDescription: |
    My File description
# hide-end
this: should-show

Reproducible demo

https://github.com/felipecrs/shiki-docusaurus-test/commit/49e3e8af2021f86df74a122b35c13908b16459c0

Steps to reproduce

Described above.

Expected behavior

To work as it works for plain md code blocks.

Actual behavior

image

Your environment

No response

Self-service

  • I'd be willing to fix this bug myself.
@felipecrs felipecrs added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Jul 7, 2023
@felipecrs
Copy link
Contributor Author

PS: I'm opening this as a bug because documentation doesn't mention anything about custom magic comments being unsupported in CodeBlocks with raw-loader. In fact the default magic comment works (highlight-next-line for example).

@Josh-Cena
Copy link
Collaborator

If the default magic comments work but not custom ones, it should probably be a bug. Otherwise I was not so sure ^^

@Josh-Cena Josh-Cena added status: needs more information There is not enough information to take action on the issue. status: accepting pr This issue has been accepted, and we are looking for community contributors to implement this and removed status: needs triage This issue has not been triaged by maintainers status: needs more information There is not enough information to take action on the issue. labels Jul 14, 2023
@slorber
Copy link
Collaborator

slorber commented Jul 20, 2023

You are using a shiki preset that is overriding our default code block

This shiki preset does not implement magic comments:
https://github.com/shikijs/twoslash/blob/main/packages/docusaurus-preset-shiki-twoslash/docusaurus-theme-shiki-twoslash/theme/CodeBlock/index.js

Please open a new repro without using any third-party plugin/preset, otherwise it can't be considered as a bug in docusaurus core

@slorber slorber closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2023
@Josh-Cena Josh-Cena added external This issue is caused by an external dependency and not Docusaurus. and removed status: accepting pr This issue has been accepted, and we are looking for community contributors to implement this labels Jul 20, 2023
@felipecrs
Copy link
Contributor Author

@slorber I'm not using the shiki preset for reproducing this issue. The branch I referred to in the example doesn't contain shiki stuff although the repo name.

@Josh-Cena Josh-Cena added status: needs more information There is not enough information to take action on the issue. and removed external This issue is caused by an external dependency and not Docusaurus. labels Jul 20, 2023
@Josh-Cena Josh-Cena reopened this Jul 20, 2023
@felipecrs
Copy link
Contributor Author

@felipecrs
Copy link
Contributor Author

I also noticed this issue first in my production website (internal), which doesn't use Shiki, and only after that I created the reproduction repo.

@slorber
Copy link
Collaborator

slorber commented Jul 20, 2023

I can reproduce, minimal repro: https://stackblitz.com/edit/github-ebe6eo-zlw6c8?file=src%2Fpages%2Findex.md

It seems related to the showLineNumbers props:

CleanShot 2023-07-20 at 17 06 54@2x

This prop overrides the display: none; CSS you set:

CleanShot 2023-07-20 at 17 09 22@2x

I think it's working as intended: the CSS className is added properly to the line, it's just "ignored" due to styling conflicts. So it's not a magic comments bug but rather a conflict between our theme CSS and your custom CSS, which is hard to avoid, unfortunately.

I'd like your custom CSS to automatically override our theme by default: but that belongs to a more general issue about CSS insertion order: #3678


The workaround is simply to use !important:

.code-block-hide-line {
  display: none !important;
}
CleanShot 2023-07-20 at 17 12 43@2x

@slorber slorber closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2023
@slorber slorber removed the status: needs more information There is not enough information to take action on the issue. label Jul 20, 2023
@felipecrs
Copy link
Contributor Author

Thanks a lot for the investigation, @slorber. And the workaround works great!

@Josh-Cena Josh-Cena added closed: working as intended This issue is intended behavior, there's no need to take any action. closed: question This issue is a user error/misunderstanding. and removed closed: working as intended This issue is intended behavior, there's no need to take any action. labels Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution closed: question This issue is a user error/misunderstanding.
Projects
None yet
Development

No branches or pull requests

3 participants