You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

私有MediaWiki中如何阻止行首空格触发自动预格式化?

Fixing Unwanted Monospace Text in MediaWiki Table Cells

Hey there! I’ve run into similar parser quirks with MediaWiki before, so let’s break down how to fix this issue and where to find the relevant docs.

Solution: Override Preformatted Text Styles via CSS

Since you can’t modify the auto-generated content, the most straightforward fix is to tweak MediaWiki’s CSS to override <pre> styling specifically for table cells. Here’s how to do it:

  1. Access your MediaWiki’s custom CSS:
    • For user-specific changes, go to Special:MyPage/common.css.
    • For site-wide changes (requires admin rights), edit MediaWiki:Common.css.
  2. Add this CSS snippet:
    /* Remove monospace formatting from <pre> tags inside table cells */
    td pre {
        font-family: inherit; /* Use the same font as normal text */
        white-space: normal; /* Let text wrap like regular content */
        background-color: transparent; /* Remove pre's default gray background */
        border: none; /* Get rid of pre's default border */
        padding: 0; /* Match table cell's default padding */
    }
    
    This will force any <pre> tags inside table <td> elements to render exactly like normal text, ditching the monospace font and preformatted styling.

If you need more control (like targeting only specific tables), you could add a custom class to your tables (if the auto-generator allows it) and adjust the selector to .your-custom-table-class td pre, but the snippet above works universally for all table cells.

Understanding MediaWiki’s Automatic <pre> Behavior

MediaWiki’s parser automatically wraps content in <pre> tags when it detects line-leading whitespace (one or more spaces or tabs) — that’s exactly what’s triggering the monospace font in your first table cell.

To dive deeper into this behavior:

  • Check your MediaWiki’s official help system (usually linked in the sidebar) and search for Preformatted Text — this covers when and why <pre> tags are auto-added.
  • Look into the MediaWiki Parser Rules documentation, which outlines all the automatic formatting triggers, including the whitespace rule for preformatted text.

内容的提问来源于stack exchange,提问作者gabriel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:38:31