Skip to content

Open respective tab item with URL query string #7008

@YOU54F

Description

@YOU54F

Have you read the Contributing Guidelines on issues?

Description

Can multi-language support code blocks, support anchors which allow the anchored code block to open?

https://docusaurus-five-rho.vercel.app/docs/markdown-features/code-blocks#multi-language-support-code-block

For example, I would like to be able to offer a user a link, either via the docusaurus side bar, or directly, that allows them to jump to a language specific block.

EG clicking Java https://docusaurus-five-rho.vercel.app/docs/markdown-features/code-blocks#java would navigate to that part of the page and make that tab visible.

Screenshot 2022-03-25 at 20 55 52

  • The anchor link from the side bar will only work if the anchor is visible
  • Hotlinking via the full url plus anchor if in a code block, will not move to the code block even if the anchor is in a visible tab.

This might just be a limitation of my HTML scripting foo, as is possible, if so, please show me the way!

Has this been requested on Canny?

No response

Motivation

we support an open source project which has a significant feature set across multiple language implementations.

I would like to be able to connect this up with syncing tab choices as it would enable readers to ensure they only see information that is relevant to them, in their preferred programming language.

API design

No response

Have you tried building it?

Yes,
See example from docusaurus master, only addition is https://github.com/YOU54F/docusaurus/commit/0e297b966a34e68c4d612a42b1ad3f634d923395 to insert anchors on each of the code block tabs.

Deployed here via vercel however the headers aren't showing

https://docusaurus-you54f.vercel.app/docs/markdown-features/code-blocks

You can clone my master branch g clone git@github.com:YOU54F/docusaurus.git

npm install && cd website && npm start

Headers added and visible locally

Screenshot 2022-03-25 at 21 47 59

clicking from TOC will anchor to Javascript tab

Screenshot 2022-03-25 at 21 48 05

If java tab is pre selected and therefore visible

Screenshot 2022-03-25 at 21 48 14

clicking from TOC will anchor to Java tab

Screenshot 2022-03-25 at 21 48 20

Hot linking to any of the code block anchors
http://localhost:3000/docs/markdown-features/code-blocks#javascript even the visible javascript one will take the user to the top of the page.

Self-service

  • I'd be willing to contribute this feature to Docusaurus myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: starterIssues that are starter difficulty level, e.g. minimal tweaking with a clear test plan.domain: themeRelated to the default theme componentsfeatureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.status: accepting prThis issue has been accepted, and we are looking for community contributors to implement this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions