Skip to content

Language auto-detection in server mode #8

Description

@ajaydsouza

Summary

When no language is set on a block, use highlight.php's highlightAuto() in server mode to detect and highlight it, with an optional detected-language badge.

Details

  • In render_code_block_server() (class-blocks.php), fall back to highlightAuto() when language is empty; constrain the candidate set to the plugin's supported language list for accuracy/performance.
  • Map the detected language through remap_token_classes() as usual; optionally show the detected slug in the toolbar label with a "(detected)" hint.
  • Global setting to enable/disable (off by default to avoid surprises); cache detection results with the existing render caching if any.
  • Client mode could later get parity via Prism's autoloader/heuristics, but server mode is the quick win.

Why

Many existing posts have untagged core/code blocks; auto-detection upgrades them to highlighted output with zero editing.

Speed to implement: Fast · Usefulness: Medium · Rank: 8

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions