Skip to content

Commit 137b29a

Browse files
authored
Merge pull request #38 from taezaz/move-haskell-tag-aliases-into-new-extension
Move <haskell/> and <hask/> aliases for syntax highlighting into a new extension - remove related logic from LocalSettings.php
2 parents 5fc1918 + f8058ef commit 137b29a

File tree

5 files changed

+95
-32
lines changed

5 files changed

+95
-32
lines changed

etc/mediawiki/LocalSettings.php

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -246,37 +246,6 @@
246246
wfLoadExtension( 'SpamBlacklist' );
247247
wfLoadExtension( 'TitleBlacklist' );
248248
wfLoadExtension( 'CollapsibleVector' );
249-
250-
# CODE BELOW IS SPECIFIC TO HAWIKI.
251-
# It should be moved to its own extension.
252-
#
253-
# Make <haskell> a synonym for <source lang='haskell'>.
254-
#
255-
# The following is pretty hackish, but otherwise we'd have to edit the
256-
# extension code.
257-
function haskellKeywordHook( $text, $args = array(), $parser ) {
258-
$args["lang"] = "haskell";
259-
return SyntaxHighlight_GeSHi::parserHook( $text, $args, $parser );
260-
}
261-
262-
function haskKeywordHook( $text, $args = array(), $parser ) {
263-
$args['lang'] = 'haskell';
264-
$args['enclose'] = 'none';
265-
$out = SyntaxHighlight_GeSHi::parserHook( $text, $args, $parser );
266-
return '<span class="inline-code">' . $out . '</span>';
267-
}
268-
269-
function addHaskellKeywordHook() {
270-
global $wgParser;
271-
$wgParser->setHook( 'haskell', 'haskellKeywordHook' );
272-
$wgParser->setHook( 'hask', 'haskKeywordHook' );
273-
return true;
274-
}
275-
276-
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
277-
$wgHooks['ParserFirstCallInit'][] = 'addHaskellKeywordHook';
278-
} else {
279-
$wgExtensionFunctions[] = 'addHaskellKeywordHook';
280-
}
249+
wfLoadExtension( 'SyntaxHighlight_GeSHi_HaskellAlias' )
281250

282251
unset( $wgFooterIcons['poweredby'] );
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Syntax highlighting tag alias for Haskell
2+
3+
This extension adds ability to use `<haskell></haskell>` and `<hask></hask>` to highlight blocks of Haskell code.
4+
The functionality of this extension relies on SyntaxHighlight_GeSHi module.
5+
6+
## Running the tests
7+
8+
The extension contains standard Mediawiki parser tests placed in tests/parser/parserTests.txt directory.
9+
10+
To execute them, run this command in the root directory of your Mediawiki installation:
11+
```
12+
php tests/parser/parserTests.php --file={your_extensions_directory_path}/SyntaxHighlight_GeSHi_HaskellAlias/tests/parser/parserTests.txt
13+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "SyntaxHighlight_GeSHi_HaskellAlias",
3+
"author": "Tomas Račys",
4+
"url": "https://github.com/haskell/haskell-wiki-configuration",
5+
"description": "This extension adds support for <haskell/> and <hask/> tags to enable Haskell code syntax highlighting",
6+
"version": "1.0",
7+
"license-name": "GPL-2.0-or-later",
8+
"type": "parserhook",
9+
"requires": {
10+
"MediaWiki": ">= 1.31"
11+
},
12+
"AutoloadClasses": {
13+
"SyntaxHighlightHaskellAliasHooks": "includes/SyntaxHighlightHaskellAlias.php"
14+
},
15+
"Hooks": {
16+
"ParserFirstCallInit": [
17+
"SyntaxHighlightHaskellAliasHooks::onParserFirstCallInit"
18+
]
19+
},
20+
"manifest_version": 1
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
class SyntaxHighlightHaskellAliasHooks
4+
{
5+
public static function onParserFirstCallInit(Parser &$parser)
6+
{
7+
$parser->setHook('haskell', [self::class, 'haskellKeywordHook']);
8+
$parser->setHook('hask', [self::class, 'haskKeywordHook']);
9+
}
10+
11+
public static function haskellKeywordHook($text, $args = array(), $parser)
12+
{
13+
$args['lang'] = 'haskell';
14+
return SyntaxHighlight_GeSHi::parserHook($text, $args, $parser);
15+
}
16+
17+
public static function haskKeywordHook($text, $args = array(), $parser)
18+
{
19+
$args['lang'] = 'haskell';
20+
$args['enclose'] = 'none';
21+
$out = SyntaxHighlight_GeSHi::parserHook($text, $args, $parser);
22+
return '<span class="inline-code">' . $out . '</span>';
23+
}
24+
}
25+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
!! hooks
2+
haskell
3+
hask
4+
!! endhooks
5+
6+
!! test
7+
Check that the code that is placed inside <haskell/> element is correctly
8+
highlighted using Haskell syntax highlighting and is displayed on multiple lines.
9+
!!input
10+
<haskell>
11+
module Main (main) where
12+
13+
main :: IO ()
14+
main = putStrLn "Hello, World!"
15+
</haskell>
16+
!! result
17+
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span><span class="kr">module</span> <span class="nn">Main</span> <span class="p">(</span><span class="nf">main</span><span class="p">)</span> <span class="kr">where</span>
18+
19+
<span class="nf">main</span> <span class="ow">::</span> <span class="kt">IO</span> <span class="nb">()</span>
20+
<span class="nf">main</span> <span class="ow">=</span> <span class="n">putStrLn</span> <span class="s">&quot;Hello, World!&quot;</span>
21+
</pre></div>
22+
23+
!! end
24+
25+
!! test
26+
Check that the code that is placed inside <hask/> element is correctly
27+
highlighted using Haskell syntax highlighting and is displayed on a single line.
28+
!!input
29+
<hask>
30+
repeat n t = take t $ cycle [n]
31+
</hask>
32+
!! result
33+
<p><span class="inline-code"><code class="mw-highlight" dir="ltr"><span class="nf">repeat</span> <span class="n">n</span> <span class="n">t</span> <span class="ow">=</span> <span class="n">take</span> <span class="n">t</span> <span class="o">$</span> <span class="n">cycle</span> <span class="p">[</span><span class="n">n</span><span class="p">]</span></code></span>
34+
</p>
35+
!! end

0 commit comments

Comments
 (0)