Add openCypher syntax highlighting for code blocks

What does this MR do and why?

Chroma has no openCypher lexer. An opencypher fence renders as plain text, and the GitLab Orbit docs, which use gql fences for Orbit queries, get the GraphQL lexer.

This MR adds _partials/highlight-opencypher.html. One replaceRE applies the rules of the Rouge lexer that GitLab uses for openCypher in Markdown, in Rouge's order. It emits the Chroma classes that the syntax themes already style. No JavaScript runs in the browser.

The render hook sends opencypher fences on every page, and gql fences in the GitLab Orbit section, through the partial. The GitLab GraphQL API docs keep the GraphQL lexer. The language badge and the copy button work as before.

Relates to https://gitlab.com/gitlab-org/gitlab/-/work_items/633612.

Details
  • Each rule is a list of class and pattern pairs. Classes that look the same in both docs themes share one class (for example, all numbers are m), and names get no span.
  • Control characters mark the spans until the code is HTML-escaped, so code text cannot inject markup.
  • Like the editable code blocks, the output has no per-line line spans.
  • I compared the visible color of every character in all 49 openCypher and Orbit gql blocks of a local build against the first version of this MR. Only one character changed: a lone : that Rouge leaves plain.

The GitLab Orbit docs v2 preview uses this change: https://docs-upstream-orbit-2966.gitlab-marketing.workers.dev/orbit/v2/prompt-examples/

Light Dark
Before before-prompt-examples-light before-prompt-examples-dark
After after-prompt-examples-light after-prompt-examples-dark
Shortcode tests after-shortcode-light after-shortcode-dark

How to set up and validate locally

  1. Configure a local GitLab Docs environment.
  2. Check out this branch.
  3. Run make view, then open /shortcode-tests/#opencypher-code-blocks.
  4. Switch between the light and dark appearance.

Merge request acceptance checklist

  • I have evaluated the MR acceptance checklist for this merge request.
  • If this MR changes how markdown is interpreted, share this MR in the #tech-docs-localization slack channel.
Edited by Michael Angelo Rivera

Merge request reports

Loading
Loading