Extension:Text-Element Autospace
Release status: beta |
|
|---|---|
| Implementation | Parser extension |
| Author(s) | Maitian MaiLintalk |
| Latest version | 1.1 (2026-04-07) |
| Compatibility policy | Main branch maintains backward compatibility. |
| MediaWiki | 1.35+ |
| Database changes | No |
| Licence | MIT License |
| Download | GitHub:
Note: |
Text-Element Autospace is a niche MediaWiki extension designed for amateur use, essentially mimicking the functionality of CSS text-autospace, but targeting inline elements (primarily icons) and text. It was created for wikis like the Chinese Countryhumans Wiki, which extensively use icons alongside languages that typically lack spaces in their text.
This extension inserts spacing between text and .space-around elements when rendering page. This is particularly useful for writing systems like Chinese and Japanese, which do not use spaces, ensuring that copied text or extracts via TextExtracts do not contain unnecessary spaces. Additionally, it eliminates the need for users to manually add spaces around specific icons for proper formatting — something newcomers may not be aware of.
Installation
[edit]- Download and place the file(s) in a directory called
Text-Element Autospacein yourextensions/folder. - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'Text-Element Autospace' );
Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Insertion logic
[edit]Inside .space-around elements with language attributes set to ja, zh, lzh, yue, wuu, nan, cdo, cpx, gan, hsn, hak or their variants (Exclude -latn), a .text-element-space (containing a space, adjusted via CSS to be slightly narrower and not directly copyable) is inserted. Simultaneously, any adjacent spaces (U+0020) outside the .space-around element are removed. However, if a .space-around element is adjacent to specific characters or elements on one side, no action is taken on that side:
- ` • ` (commonly used as a separator for inline lists, typographic spaces should not be removed)
- ` · ` (same as above)
- ` | ` (same as above)
- U+3000-U+3003: CJK punctuation marks with built-in spacing (e.g.
。,、) - U+3008-U+3011: CJK punctuation marks with built-in spacing (e.g.
《,》,【,】) - U+FF01-U+FF60: Full-width variants of ASCII punctuation marks (e.g.
?,!,(,)) - U+2000-U+205F: Various other spaces with different widths and purposes (e.g. full-width space)
- U+0009: Tab character
- U+00A0: Non-breaking space
- HTML elements marked as
.space-around(no spaces should appear between adjacent.space-aroundelements)
Example
[edit][Icon] represents a template like <span class="icon space-around">[[File:Icon.png]]</span>, and _ denotes the spacing element <span class="text-element-space"> </span> as sub-element of [Icon] generated by this extension.
| Source code | Rendered output | test descraption |
|---|---|---|
text[icon]text text [icon] text |
text[_icon_]text |
Insert spacers and remove spaces |
text,[icon]text。 |
text,[icon_]text。 |
No insert spacers near special punctuation mark |
—— [icon]text |
—— [icon_]text |
No insert spacers near special space |
[icon] text • [icon] text |
[icon_]text • [icon_]text |
Keep ` • ` etc. and no insert spacers nearly |
(text)• [icon] text |
(text)• [icon_]text |
Keep `)• ` etc. and no insert spacers nearly |
[icon][icon] [icon] [icon] |
[icon][icon] [icon_][icon] |
No insert spacers between .space-around without spaces
|
<span lang="en">text in [icon] English.</span> |
stay the same | Only match the target language code |
<span lang="nan-latn">text in [icon] Hokkien (Latin).</span> |
stay the same | Exclude particular language extral code |
About spacing element
[edit]It's just a normal space with a CSS container. This is done because web rendering can remove overlapping spaces and hide them when a line break occurs.
.text-element-space {
word-spacing: -2px;
user-select: none;
}
In 16px-font-size, length of spacer is 2~3px.
