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

Add syntax highlighting for all code snippets across all languages #5331

Open
pastelcyborg opened this issue Aug 28, 2024 · 5 comments
Open
Labels
P3 Triaged Issue has been reviewed as part of legacy backlog grooming (project P3). Triaged: new architecture Triaged, to be addressed in new architecture of the design system

Comments

@pastelcyborg
Copy link
Contributor

pastelcyborg commented Aug 28, 2024

The code snippet blocks used across the website should all be syntax highlighted for their appropriate languages. Right now, only snippets on certain pages are syntax highlighted, while others are not:

https://vanillaframework.io/docs/building-vanilla

There's probably an additional CSS theme or whatnot for our syntax highlighting lib that would add this functionality.

@pastelcyborg pastelcyborg added the WG: Proposal Working group proposals label Aug 28, 2024
@pastelcyborg pastelcyborg self-assigned this Aug 28, 2024
Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/WD-14575.

This message was autogenerated

@pastelcyborg pastelcyborg changed the title Add syntax highlighting for code snippets of all languages Add syntax highlighting for all code snippets of all languages Aug 28, 2024
@pastelcyborg pastelcyborg changed the title Add syntax highlighting for all code snippets of all languages Add syntax highlighting for all code snippets across all languages Aug 28, 2024
@jmuzina
Copy link
Member

jmuzina commented Aug 28, 2024

The example code snippets (support syntax highlighting for HTML, JS, CSS), because they use Prism to highlight their source (here's where we call it).

We could do this for pre code blocks throughout the rest of our documentation, but we'd have to find a way to intercept whatever process reads our markdown and turns it into markup, and call Prism there. Or, probably more simply, we could check for all pre code elements on our docs pages and run Prism on them.

@jmuzina
Copy link
Member

jmuzina commented Aug 28, 2024

Adding to my initial exploration:

Prism.highlightAllUnder, which is the function we call to highlight syntax, relies on the pre element having a class language-<language_identifier>, where language_identifier is some language in Prism's language set.

We set this ourselves for examples here. Coincidentally, it seems like Jinja is not a valid option here, which is why the macros in #5321 have no syntax highlighting.

It's a bit harder to apply to the whole site as we would have to set the language manually (or otherwise detect it), so we can add the class name accordingly.

I started with this as a brief exploration, and found that it doesn't highlight anything because the language class is not present.

(function () {
  function setupPreCodeHighlights() {
    if (!Prism) return;

    document.querySelectorAll('pre code').forEach(Prism.highlightAllUnder);
  }

  document.addEventListener('DOMContentLoaded', setupPreCodeHighlights)
})();

So, what we probably need is to either find a way to detect languages (which is probably full of errors and false identifications), or to manually set the language on all of our pre code blocks, inside the markup.

Edit: it's also possible that my example didn't work because I was calling highlight on "code" rather than "pre"

@bartaz bartaz removed the WG: Proposal Working group proposals label Sep 18, 2024
@bartaz
Copy link
Member

bartaz commented Sep 25, 2024

Triage: This seems quite high effort. Not sure how useful it is to explore more in current codebase and docs. Needs discussion.

@bartaz bartaz added the P3 Needs decision Needs team agreement in terms of triaging. label Sep 25, 2024
@bartaz
Copy link
Member

bartaz commented Oct 24, 2024

Triage: not worth exploring in current codebase. We could consider it when looking at new architecture documentation considerations.

@bartaz bartaz added Triaged: v4 Triaged, to be implemented as part of Vanilla v4 Triaged: new architecture Triaged, to be addressed in new architecture of the design system P3 Triaged Issue has been reviewed as part of legacy backlog grooming (project P3). and removed P3 Needs decision Needs team agreement in terms of triaging. Triaged: v4 Triaged, to be implemented as part of Vanilla v4 labels Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Triaged Issue has been reviewed as part of legacy backlog grooming (project P3). Triaged: new architecture Triaged, to be addressed in new architecture of the design system
Projects
None yet
Development

No branches or pull requests

3 participants