Skip to content

Normalize docs code fence languages#3004

Open
omribz156 wants to merge 2 commits into
appwrite:mainfrom
omribz156:doc-12333-code-fence-language
Open

Normalize docs code fence languages#3004
omribz156 wants to merge 2 commits into
appwrite:mainfrom
omribz156:doc-12333-code-fence-language

Conversation

@omribz156
Copy link
Copy Markdown

What does this PR do?

Normalizes code fence language strings before handing them to the docs code highlighter and before emitting the language-* class. This keeps values like csharp from missing the registered csharp highlighter or producing a trailing-space CSS class.

It also adds a focused unit test for the .NET/csharp case.

Test Plan

  • git diff --check

I could not run the Bun-based project checks locally because Bun is not installed in this environment; the project CI installs Bun and should cover bun run check and tests.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

This was implemented with Codex assistance, with the patch kept focused and manually reviewed before sending.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 18, 2026

Greptile Summary

This PR fixes a bug where code fence language strings with trailing whitespace (e.g., csharp ) could miss the registered hljs highlighter and produce a malformed CSS class like language-csharp . It also fixes the undefined language case that previously emitted a language-undefined class.

  • Adds a small normalizeLanguage helper that trims the language token and applies it to both the hljs.highlight call and the language-* CSS class in code.ts.
  • Adds two focused unit tests: one for the trailing-space normalization and one for the undefined fallback to language-sh.

Confidence Score: 5/5

Minimal, focused change touching only the code highlighter utility; both the fix and the fallback path are straightforward and backed by new tests.

The change is a two-line addition to a single utility function, with no side effects outside getCodeHtml. The normalization is safe for all valid Language values, and empty-string or undefined inputs are handled correctly. New tests cover the two previously broken paths.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/utils/code.ts Adds normalizeLanguage helper that trims whitespace from the language token; uses the normalized value consistently for both hljs.highlight and the CSS class name, fixing both the missing highlighter and the trailing-space class bug.
src/lib/utils/code.test.ts New test file covering the trailing-space language normalization case and the undefined-language fallback to language-sh.

Reviews (2): Last reviewed commit: "test: cover code block fallback language" | Re-trigger Greptile

Comment thread src/lib/utils/code.test.ts
@omribz156
Copy link
Copy Markdown
Author

Added a follow-up test for the omitted-language fallback that Greptile called out. Verification: git diff --check. I still couldn't run the Bun-based unit suite locally because Bun is not installed in this environment.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dotnet Snippets in Documentation are in backticks (csharp )

1 participant