Switch Commonmarker output
Switch Commonmarker output (github_pre_lang: false)
Part of: lang attribute must have a valid value
Depends on: Step 1 (CodeLanguageFilter refactoring) and Step 2 (html_gitlab.rb refactoring)
What does this MR do and why?
This MR introduces a feature flag to control how the GLFM markdown engine outputs language information for code blocks, preparing for the transition from invalid lang attributes to valid CSS classes.
Key Changes:
- Adds feature flag
use_css_language_classes(disabled by default) -
When disabled: Outputs
<pre lang="ruby"><code>(current behavior) -
When enabled: Outputs
<pre><code class="language-ruby">(new behavior) - Refactors
render_optionsmethod to evaluate feature flag at render time - Updates tests to cover both behaviors
Why this approach?
This feature flag enables safe, gradual rollout of the accessibility fix:
- Safe deployment: Flag disabled by default maintains current behavior
- Gradual testing: Can enable for specific projects to validate changes
- Easy rollback: Can disable flag if issues are discovered
- Preparation for Step 4: CodeLanguageFilter (refactored in Step 1) already handles CSS class extraction
How to set up and validate locally
-
Test default behavior (flag disabled):
# In Rails console Feature.disabled?(:use_css_language_classes) # Should be true- Code blocks should show:
<pre lang="ruby"><code>
- Code blocks should show:
-
Test new behavior (flag enabled):
# Enable flag in Rails console Feature.enable(:use_css_language_classes)- Code blocks should show:
<pre><code class="language-ruby">
- Code blocks should show:
-
Run tests:
bundle exec rspec spec/lib/banzai/filter/markdown_filter_spec.rb
Verification
-
Feature flag disabled: Code blocks use
langattributes (current behavior) - Feature flag enabled: Code blocks use CSS classes (new behavior)
- Math blocks follow same pattern as regular code blocks
- All tests pass for both flag states
- No behavior change with flag disabled (safe default)
Related
- Previous steps: Step 1 (CodeLanguageFilter refactoring), Step 2 (html_gitlab.rb refactoring)
-
Next step: Step 4 - Replace
langwithdata-langin Rouge and AsciiDoc formatters -
Final goal: Replace invalid
langattributes withdata-langfor WCAG compliance - Addresses accessibility violations where
lang="ruby"is invalid HTML