Extension:CharRangeSpan

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
Crystal Clear action run.svg
CharRangeSpan
Release status: beta
Implementation Parser extension
Description Wraps certain ranges of characters in defined span tags
Author(s) Nick White (njwtalk)
Latest version 0.9 (2013-03-21)
Database changes No
License ISC License
Download
Parameters
  • $wgCharRangeSpanSettings
  • $wgCharRangeSpanSettings[]['ranges']
  • $wgCharRangeSpanSettings[]['attrs']
  • $wgCharRangeSpanSettings[]['maybeChars']
Hooks used
ParserBeforeTidy
Translate the CharRangeSpan extension if it is available at translatewiki.net
Check usage and version matrix.

The CharRangeSpan extension wraps characters in specified ranges in customisable span tags. The main use-case for this is to automatically set the font for certain character sets, for sites which have several languages which need different fonts.

Example output with the default configuration
Wikitext Output
Hello this is English, τηφσ ισ θοδδω, and back to English again. Hello this is English, <span lang="grc">τηφσ ισ θοδδω,</span> and back to English again.

Installation[edit]

  • Download and place the file(s) in a directory called CharRangeSpan in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/CharRangeSpan/CharRangeSpan.php";
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration[edit]

$wgCharRangeSpanSettings
An array containing all of the configuration parameters.
$wgCharRangeSpanSettings[Name]
Each set of character ranges can be named anything.
$wgCharRangeSpanSettings[Name]['ranges']
Contains arrays containing the unicode codepoints of the start and end of character ranges to match.
$wgCharRangeSpanSettings[Name]['attrs']
The attribute to set for the span tag matching the above ranges.
$wgCharRangeSpanSettings[Name]['maybeChars']
Characters which may be included in span, or may not. Each character must be escaped for a PHP regular expression (see the example below). This is useful to avoid ending and starting span tags for common characters for which the font is unimportant, for example spaces and commas.

Example configuration[edit]

This is the default configuration. It defines one set of character ranges (Greek), and encloses any such characters in <span lang="grc"> tags.

$wgCharRangeSpanSettings = array(
    'grc' => array(
        'ranges' => array(
            array( '0300', '036F' ), /* combining diacritics */
            array( '0370', '03FF' ), /* greek */
            array( '1F00', '1FFF' ), /* greek extended */
        ),      
        'attrs' => 'lang="grc"', /* sets the attribute for the span */
        'maybeChars' => '\\s\\,\\.\\-', /* characters which may (or may not) be included in span */
    ),  
);

Testing[edit]

This extension has some unit tests. To run them first install the extension, then from the command line (in the mediawiki directory) run this command:

php tests/parserTests.php --file=extensions/CharRangeSpan/tests/parserTests.txt

Note that the tests rely on the default configuration.

See also[edit]