MediaWiki Custom Pygments: Difference between revisions
From Leo's Notes
This page was last edited on 19 February 2017, at 08:19.
Created page with "To create a custom Pygments lexer for MediaWiki, do the following: # Clone the Pygments project in the {{code|extensions/SyntaxHighlight_GeSHi/pygments}} directory. This shou..." |
mNo edit summary |
||
| Line 12: | Line 12: | ||
""" | """ | ||
pygments.lexers.terminal | pygments.lexers.terminal | ||
------------------------ | |||
Lexers for terminal output | Lexers for terminal output | ||
Revision as of 08:19, 19 February 2017
To create a custom Pygments lexer for MediaWiki, do the following:
- Clone the Pygments project in the
extensions/SyntaxHighlight_GeSHi/pygmentsdirectory. This should replace thepygmentizebinary with the python script. - Create your lexer in the
extensions/SyntaxHighlight_GeSHi/pygments/pygments/lexersdirectory. - Update the map by running
make mapfilesinextensions/SyntaxHighlight_GeSHi/pygments - Update the
SyntaxHighlight_GeSHi.lexers.phpfile to contain the new lexer alias.
A simple lexer used on this wiki is for the Terminal output. It has the following lexer code which is just a couple regexes.
# -*- coding: utf-8 -*-
"""
pygments.lexers.terminal
------------------------
Lexers for terminal output
:copyright: Leo's stuff
:license: Leo's stuff
"""
import re
from pygments.lexer import RegexLexer, bygroups
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Punctuation, Error
__all__ = ['TerminalLexer']
class TerminalLexer(RegexLexer):
"""
For terminal output
.. versionadded:: 0.1
"""
name = 'terminal'
aliases = ['terminal']
tokens = {
'root': [
(r'^([a-zA-Z0-9\@:~\/\s]*[\$#]{1})(\s*[^#\n]*)(#*.*)', bygroups(Name, String, Comment )),
(r'.*\n', Text)
],
}