Skip to content

Support selecting programming language in code snippets #55

Open

Description

@szabosteve

Is this feature required for your content to migrate?
It is not required for migration.

Describe the solution you need
The documentation often contains code snippets as examples of an operation. The code snippets are "Console" commands by default but it would be great to have the option to select another language and see the example in that language.

Impact
With this feature, repeating the same commands in various languages on the same page is unnecessary. One snippet could contain and display the commands for all the available languages.

Additional context

Screenshot 2022-09-07 at 10 06 09

Activity

  1. added
    documentation
    on Sep 7, 2022
  2. changed the title [-]Add the possibility of selecting programming language for code snippets in the docs[/-] [+]Support selecting programming language for code snippets[/+] on Oct 5, 2022
  3. changed the title [-]Support selecting programming language for code snippets[/-] [+]Support selecting programming language in code snippets[/+] on Oct 5, 2022
  4. scottybollinger commented on Feb 9, 2023

    @scottybollinger

    @szabosteve do you have an example of this in the legacy (current) docs that I can use for reference? Thanks!

  5. szabosteve commented on Feb 14, 2023

    @szabosteve
    ContributorAuthor

    @scottybollinger Well, this was the page where I took the screenshot above: https://www.elastic.co/guide/en/cloud/current/ec-working-with-elasticsearch-clients.html#ec_connect_a_client
    It has been deleted since then and – according to the conf.yml in elastic/docs – all the previous branches have been mapped to Clients: https://github.com/elastic/docs/blob/master/conf.yaml#L85. So I cannot link to a previous version of that page either. The asciidoc file is still available in a previous branch of the repo though: https://github.com/elastic/cloud/blob/ms-80/docs/shared/ec-ce-working-with-elasticsearch.asciidoc. I hope it helps a bit.

    We do have other examples in the current docs, however, for example on the create index API page. Sadly, the function does not work here since the project was stopped.

    I don't know if these are helpful to any degree. Please let me know if I can help anyhow.

  6. scottybollinger commented on Feb 14, 2023

    @scottybollinger

    @colleenmcginnis, do you happen to know of an example of legacy docs that have a language-switching component with multiple languages actually used? The example above only has one language for each example and I'd like to see how one with multiple languages works. Thanks!

  7. colleenmcginnis commented on Feb 14, 2023

    @colleenmcginnis
    Contributor

    I can't find any with language switching that actually works. I brought this to #docs in Slack to see if this is expected to work anywhere. I'll post back when I get a response.

    In the meantime, I don't think switching languages is a high priority for docsmobile. We haven't, however, had a discussion about the other functionality available in the console_widget. The user can click the gear icon to specify a few settings, save them, and then close out of the modal and click the View in Console button to open Kibana's console with the snippet pre-populated and ready to run.

    Screenshot 2023-02-14 at 5 12 52 PM

    This functionality is available in the example @szabosteve linked to in his last comment: Create index API.

    However, I don't think we have any data on how many users take advantage of this feature (I think I may have asked @KOTungseth in passing at some point) so I'm not sure if it's worth investing the time in building out this feature right now. To get a clearer picture of the need, I could open up a writer discussion and open a fresh issue here if there's engineering work to do.

  8. scottybollinger commented on Feb 14, 2023

    @scottybollinger

    The user can click the gear icon to specify a few settings, save them, and then close out of the modal and click the View in Console button to open Kibana's console with the snippet pre-populated and ready to run.

    Thanks! I saw this as well and think it should be fairly simple to implement.

  9. colleenmcginnis commented on Feb 15, 2023

    @colleenmcginnis
    Contributor

    It looks like there are a few examples of these drop downs working (see Slack thread), but that the functionality has probably been largely broken for quite a while (maybe even since 2020). My guess (without knowing exactly how it works) is that it stopped working at some point (2020-ish), but snippets that use language drop downs that haven't been added/edited since it broke might still work because the alternative language snippets were already generated.

    In my opinion, we should have a discussion about this functionality before committing dev resources to building it into docsmobile. The discussion could include:

    • Should we attempt to fix this functionality in the current AsciiDoc system? If so, who will fix it? If not, can we remove the broken drop downs that are currently on the live docs site?
    • Should we prioritize adding this feature to docsmobile ahead of migration since it doesn't currently work in AsciiDoc? Could we delay development and go back to it as a new feature rather than part of reaching feature parity with AsciiDoc?
    • Since no one (that I've heard from) knows how we autogenerate snippets in alternative languages and how they are pulled into the docs, should we do some discovery around what we want out of a feature like this and start from scratch in docsmobile rather than trying to understand how it works in the current AsciiDoc system?

    What do you think about this approach @scottybollinger @szabosteve @KOTungseth?

  10. scottybollinger commented on Feb 15, 2023

    @scottybollinger

    It looks like there are a few examples of these drop downs working (see Slack thread), but that the functionality has probably been largely broken for quite a while (maybe even since 2020). My guess (without knowing exactly how it works) is that it stopped working at some point (2020-ish), but snippets that use language drop downs that haven't been added/edited since it broke might still work because the alternative language snippets were already generated.

    In my opinion, we should have a discussion about this functionality before committing dev resources to building it into docsmobile. The discussion could include:

    • Should we attempt to fix this functionality in the current AsciiDoc system? If so, who will fix it? If not, can we remove the broken drop downs that are currently on the live docs site?
    • Should we prioritize adding this feature to docsmobile ahead of migration since it doesn't currently work in AsciiDoc? Could we delay development and go back to it as a new feature rather than part of reaching feature parity with AsciiDoc?
    • Since no one (that I've heard from) knows how we autogenerate snippets in alternative languages and how they are pulled into the docs, should we do some discovery around what we want out of a feature like this and start from scratch in docsmobile rather than trying to understand how it works in the current AsciiDoc system?

    What do you think about this approach @scottybollinger @szabosteve @KOTungseth?

    Thanks, Colleen! I agree 100% with this proposal. I am going to unassign, remove this from in progress, and place in the backlog. We can revisit once a decision has been made.

    If we decide to deprioritize this completely for the migration, I can remove it from the Current Work project.

  11. removed their assignment
    on Feb 15, 2023
  12. KOTungseth commented on Feb 16, 2023

    @KOTungseth
    Contributor

    We have a few issues in the Kibana repo for the broken API docs functionality. A few people have worked on them over the years, but nothing has been resolved. Since we don't collect metrics on these components in the docs, I'm not sure how often they are used.

    For the Serverless API docs functionality, I think we need input from a technical perspective and a design perspective on whether or not we need this functionality to GA.

  13. sethmlarson commented on Mar 29, 2023

    @sethmlarson

    Hello! 👋 I'm from the clients team, we've been getting many requests for more extensive examples for language clients and we see these auto-generated API request examples as a great way to fulfill this customer request. @picandocodigo did some digging into the current state of the end-to-end pipeline for these examples and we found that everything is still operational from our POV, we've been able to update generated examples and have those changes appear on elastic.co. Full investigation here: https://github.com/elastic/clients-team/issues/577

    We'd like to get more examples generated (previously we had an per-page incremental rollout for our examples, but there's no foundational reason we couldn't just "generate everything" beyond ensuring that the examples are valid). We'd also like to add examples for more languages, currently per this report we only have some examples for PHP, Python, Ruby, Go, and JS:

    {
      "console": {
        "total": 3711,
        "alternatives": {
          "php": {
            "found": 75
          },
          "python": {
            "found": 74
          },
          "ruby": {
            "found": 289
          },
          "go": {
            "found": 200
          },
          "js": {
            "found": 74
          }
        }
      }
    }

    Hopefully we can also have this support in the next docs system as well?

  14. lcawl commented on Apr 25, 2023

    @lcawl
    Contributor

    This is a total fly-by comment, but does the tabs functionality in docsmobile help address this request?

  15. leemthompo commented on Apr 11, 2024

    @leemthompo
    Member
    • Per Seth's latest comment, the biggest challenge is the whole behind-the-scenes examples generation owned by the clients team. This is the pipeline that will populate MDX files with actual examples.
    • One requirement on Docsmobile side would be to add some state to the tab functionality so that when a user picks a language all the examples on the page switch to that language.
  16. removed
    documentation
    on Nov 11, 2024
  17. bmorelli25 commented on Nov 11, 2024

    @bmorelli25
    Member

    Moving to V3

  18. transferred this issue fromon Nov 11, 2024
  19. cotti commented on May 26, 2026

    @cotti
    Contributor

    Codebase audit (2026-05-26)

    Doing a sweep of the oldest open issues and checking whether they're still actionable against the current codebase. Sharing what I found here.

    Current state in docs-builder

    Piece Status Where
    Manual workaround: tab-set + tab-item with :group: / :sync: ✅ Implemented src/Elastic.Markdown/Myst/Directives/Tabs/, frontend sync in src/Elastic.Documentation.Site/Assets/tabs.ts
    Cross-tab-set sync (click one, all matching tabs flip) ✅ Implemented, sessionStorage-backed (despite the comment saying "local storage") tabs.ts
    URL-driven seeding (?languages=java) ✅ Implemented tabs.ts
    Kibana console fenced blocks (HTTP verb + JSON) ✅ Implemented src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs (console → json + ApiSegments)
    clients-flight-recorder / alternatives_summary consumption ❌ No references anywhere —
    Dedicated {console_widget} / {alternatives} / {multilang} directive ❌ Not implemented —
    Global "preferred programming language" preference (independent of an author-built tab group) ❌ Not implemented —
    Pre-paint sync (right tab checked before first render → no FOUC) ❌ Selection applied after JS load —

    So the toolchain has the rendering substrate (synced tabs) but neither the data pipeline (auto-generating equivalent snippets) nor the persistent UX (one click → site-wide language preference) that the original request implies.

    Suggested incremental progress (frontend only, no pipeline dependency)

    1. Global language preference — when a tab-set has :group: languages (configurable allowlist), persist the choice in localStorage instead of sessionStorage so it survives across sessions.
    2. Pre-paint sync — inline blocking script in _Head.cshtml reads the localStorage key and sets the correct <input> checked before paint to avoid FOUC.

    These are isolated to src/Elastic.Documentation.Site/Assets/tabs.ts + _Head.cshtml and ship value even if the alternatives pipeline never lands.

    Lingering questions (need stakeholder input before doing more)

    • Pipeline ownership — sethmlarson's 2023 comment said the clients team owns the alternatives generator. Is anyone currently committing to a stable JSON contract docs-builder can ingest? Without that, an {language-examples} directive has nothing to consume.
    • UX model — colleenmcginnis's question about whether language switching is actually a high-priority docsmobile/V3 feature was never resolved. Do we have any usage telemetry from the legacy console_widget that would justify the work?
    • Languages list — if we do auto-generate, which set of clients/languages is the source of truth? console + PHP/Python/Ruby/Go/JS only (per the legacy report), or do we add Rust/.NET/Java?
    • Scope of "preferred language" — should the global preference apply only to a languages group, or to any tab-set whose tabs match a known-language identifier?

    If any of these have answers I missed, happy to adjust.

  20. added
    ai-triaged
    on May 26, 2026
  21. github-actions commented on Aug 30, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open 90 days with no activity. Remove the stale label, or leave a comment, or this will be closed in 14 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions