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

support adding attributes to code blocks #826

Closed
3 tasks done
JounQin opened this issue Jun 21, 2022 · 11 comments · May be fixed by #3519
Closed
3 tasks done

support adding attributes to code blocks #826

JounQin opened this issue Jun 21, 2022 · 11 comments · May be fixed by #3519
Labels
enhancement New feature or request stale

Comments

@JounQin
Copy link
Contributor

JounQin commented Jun 21, 2022

Describe the bug

highlightLinePlugin is used before attrs, and token.info is rewritten.

via #664 (comment)

Reproduction

image

image

Expected behavior

Render data="asdf"

System Info

System:
    OS: macOS 13.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 13.84 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/Library/Caches/fnm_multishells/95455_1655742557079/bin/node
    Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/95455_1655742557079/bin/yarn
    npm: 8.12.1 - ~/Library/Caches/fnm_multishells/95455_1655742557079/bin/npm
  Browsers:
    Chrome: 102.0.5005.115
    Firefox: 101.0.1
    Safari: 16.0
  npmPackages:
    vitepress: ^1.0.0-alpha.2 => 1.0.0-alpha.2

Additional context

No response

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@JounQin JounQin added the bug: pending triage Maybe a bug, waiting for confirmation label Jun 21, 2022
@brc-dd
Copy link
Member

brc-dd commented Jun 21, 2022

The issue is not due to highlightLinePlugin. I tried removing that. It still don't show attributes on code block. It is working if I remove highlight option altogether. :/

@kiaking
Copy link
Member

kiaking commented Jun 21, 2022

What is expected to happen here? I mean where should data="asdf" appear? On pre or code or <div class="language-...">? 👀

Is this common feature that markdown attrs plugin supports?

@kiaking kiaking added need more info Further information is requested and removed bug: pending triage Maybe a bug, waiting for confirmation labels Jun 21, 2022
@kiaking
Copy link
Member

kiaking commented Jun 21, 2022

Oh thanks! OK... well yeah seems like we should be supporting this then 😅

How do we combine this with Line Highlighting? Should below work...?

```ts{4}{data=asdf}

@brc-dd
Copy link
Member

brc-dd commented Jun 21, 2022

Don't think they both will play nice with each other. Here is a workaround for that: arve0/markdown-it-attrs#63 (comment) -- or we can probably modify our highlightLinePlugin to use different limiters.

@kiaking
Copy link
Member

kiaking commented Jun 22, 2022

Nice we have workaround. Yeah and I agree if we were to change anything, we should change highlightLinePlugin syntax. It's a small breaking change but, this is the time to introduce that change.

@JounQin
Copy link
Contributor Author

JounQin commented Jun 22, 2022

I'd like to work on this change if you agree to the current workaround solution.

@kiaking
Copy link
Member

kiaking commented Jun 22, 2022

Yeah, I think we could try! So the ideal syntax would be...

```ts[4]{data=asdf}

or

```ts {data=asdf} [4]

But I guess we need to do some try and errors and see if this API fits well without any confusing edge cases.

@JounQin
Copy link
Contributor Author

JounQin commented Jun 22, 2022

@kiaking [] could occur in {} at the same time?

```ts {data=[0]}
```

@kiaking
Copy link
Member

kiaking commented Jun 22, 2022

Well I don't think so...? Is there any use case for it?

@JounQin
Copy link
Contributor Author

JounQin commented Jun 22, 2022

Well I don't think so...? Is there any use case for it?

Oh, sorry, I'm not so familiar with highlightLinePlugin yet, will {data=[0]} be parsed incorrectly? if not, that's great.

Not a real case for now, but it could happen in theory.

@brc-dd brc-dd added enhancement New feature or request and removed need more info Further information is requested labels Jun 22, 2022
@brc-dd brc-dd changed the title attrs is not working on code block due to highlightLinePlugin support adding attributes to code blocks Jun 22, 2022
@github-actions github-actions bot added the stale label Aug 3, 2023
@brc-dd brc-dd closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants