| (24 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 1 : | Ligne 1 : | ||
{{intralink|link=MediaWiki/Mes_Extensions}} | |||
{{Extension | {{Extension | ||
|name=SyntaxHighlight | |name=SyntaxHighlight | ||
|link=Extension:SyntaxHighlight | |link=Extension:SyntaxHighlight | ||
|description=Mise en forme de code | |description=Mise en forme de code | ||
|githublink= | |githublink=[[wikimediagerrit:extensions/SyntaxHighlight_GeSHi]] | ||
|translated=true | |||
}} | }} | ||
<br | {{mediawiki |name=Extension:SyntaxHighlight/fr}} | ||
<br> | |||
== Nouvelle version avec pygments == | == Nouvelle version avec pygments == | ||
La nouvelle version utilise la librairie Pygments . <br> | La nouvelle version utilise la librairie Pygments . <br> | ||
Elle permet d'ajouter un langage. <br> | Elle permet d'ajouter un langage. <br> | ||
Pour cela il faut modifier la librarie utilisée écrite en python et disponible sur github, voir ici {{Intralink|link=MediaWiki/Mes_Extensions/SyntaxHighlight#Comment_ajouter_un_%22lexer%22_%C3%A0_l'outil_pygments|text=Comment}} <br> | Pour cela il faut modifier la librarie utilisée écrite en python et disponible sur github, voir ici {{Intralink|link=MediaWiki/Mes_Extensions/SyntaxHighlight#Comment_ajouter_un_%22lexer%22_%C3%A0_l'outil_pygments|text=Comment}}<br> | ||
J'ai ajouté le langage Clearcase <br> | J'ai ajouté le langage Clearcase <br> | ||
Je l'utilise au travers du modèle [[Modèle:Syntaxhighlight]] | Je l'utilise au travers du modèle [[Modèle:Syntaxhighlight]]<br> | ||
Il est nécessaire aussi de configurer le binaire associé à pigments. Par défaut celui fourni par Mes Extensions/SyntaxHighlight ne fonctionne pas forcément; il a été généré sur une plateforme Linux avec une version de python assez récente.<br> | |||
Pour ma part j'ai configuré ceci dans mon fichier {{File |LocalSettings.php}} | |||
{{syntaxhighlight |lang=php |code= | |||
if ( $isWindows ) { | |||
$wgPygmentizePath = "$IP/extensions/SyntaxHighlight_GeSHi/pygments/pygments/dist/__main__.exe"; | |||
} else { | |||
$wgPygmentizePath = "/homez.913/jltryoen/python/pygments/pygmentize"; | |||
} | |||
}} | |||
<br> | |||
== Syntaxe == | == Syntaxe == | ||
{{syntaxhighlight| lang=text|code = | |||
<nowiki> | <nowiki> | ||
{{syntaxhighlight | lang=php|wfLoadExtension("SyntaxHighlight_GeSHi" );}} | {{syntaxhighlight | lang=php|wfLoadExtension("SyntaxHighlight_GeSHi" );}} | ||
| Ligne 33 : | Ligne 49 : | ||
Voir {{weblink |link=https://pygments.org/docs/lexerdevelopment/}} | Voir {{weblink |link=https://pygments.org/docs/lexerdevelopment/}} | ||
* Cloner la repository de pygments en local | * Cloner la repository de pygments en local | ||
: Le site est {{githublink |link=pygments/pygments}} {{syntaxhighlight |lang=bash |code = git clone https://github.com/pygments/pygments.git}} | |||
* Ajouter le lexer souhaité sous le répertoire {{File |pygments/lexers}} en respectant bien les champs à remplir:<br> | * Ajouter le lexer souhaité sous le répertoire {{File |pygments/lexers}} en respectant bien les champs à remplir:<br> | ||
: example de fichier {{accordion | {{file|}}clearcase.py | | |||
<include src="https://raw.githubusercontent.com/JLTRY/pygments/refs/heads/python_3.7/pygments/lexers/clearcase.py" lang="python" nocache nopre/>}} | |||
* Mettre à jour pygments avec le nouveau "lexer"{{syntaxhighlight |lang=bash|code= | |||
}} | |||
* Mettre à jour pygments avec le nouveau "lexer" | |||
python scripts/gen_mapfiles.py | python scripts/gen_mapfiles.py | ||
}} | }} | ||
* On peut ensuite soit générer un executable | * On peut ensuite soit générer un executable {{syntaxhighlight |lang=bash|code= | ||
pyinstaller --onefile __main__.py | pyinstaller --onefile __main__.py | ||
}} | }} | ||
* On peut aussi utiliser un lanceur python ex: | * On peut aussi utiliser un lanceur python ex: {{File |pygments/pygmentize}}{{syntaxhighlight |lang=python|code={{#!: | ||
#!/usr/bin/python3 | #!/usr/bin/python3 | ||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||
| Ligne 73 : | Ligne 72 : | ||
}} | }} | ||
<br> | <br> | ||
< | {{information | ma version de python chez OVH est la <pre>Python 3.7.3 (default, Mar 23 2024, 16:12:05)</pre> | ||
Du coup j'ai du revenir en arrière sur la version de pygments, juste avant cette version: | |||
<pre> | |||
SHA-1: e7f50060fd644b17de8debbd2a5c259c64898d4f | |||
* Drop support for EOL Python 3.7 (#2601) | |||
</pre> | |||
* soit la version du 30/11/2023 | |||
<pre> | |||
SHA-1: 276dcf8ae4af6e959e13ea6f63d9f5e7bc80ea48 | |||
* Update CHANGES | |||
</pre> | |||
{{syntaxhighlight |lang=bash|code= | |||
git reset --hard 276dcf8ae4af6e959e13ea6f63d9f5e7bc80ea48 | |||
}} | |||
et rajouter mon fichier clearcase.py, relancer la commande de génération {{syntaxhighlight |lang=bash|code=python scripts/gen_mapfiles.py}} | |||
et relancer la commande de génération du binaire {{syntaxhighlight |lang=bash |code= | |||
pyinstaller --onefile __main__.py}} | |||
}} | |||
MediaWiki/Mes_Extensions
| MediaWiki/Mes Extensions/SyntaxHighlight | |
|---|---|
| Nom | SyntaxHighlight |
| Lien | |
| Github | |
Mise en forme de code
L'extension SyntaxHighlight, anciennement connue sous le nom de SyntaxHighlight_GeSHi, fournit un formatage riche du code source à l'aide de la balise <syntaxhighlight>. Il est propulsé par la bibliothèque Pygments et prend en charge des centaines de langages de programmation et de formats de fichiers différents.
La nouvelle version utilise la librairie Pygments .
Elle permet d'ajouter un langage.
Pour cela il faut modifier la librarie utilisée écrite en python et disponible sur github, voir ici Comment
J'ai ajouté le langage Clearcase
Je l'utilise au travers du modèle Modèle:Syntaxhighlight
Il est nécessaire aussi de configurer le binaire associé à pigments. Par défaut celui fourni par Mes Extensions/SyntaxHighlight ne fonctionne pas forcément; il a été généré sur une plateforme Linux avec une version de python assez récente.
Pour ma part j'ai configuré ceci dans mon fichier
LocalSettings.php
if ( $isWindows ) {
$wgPygmentizePath = "$IP/extensions/SyntaxHighlight_GeSHi/pygments/pygments/dist/__main__.exe";
} else {
$wgPygmentizePath = "/homez.913/jltryoen/python/pygments/pygmentize";
}
{{syntaxhighlight | lang=php|wfLoadExtension("SyntaxHighlight_GeSHi" );}}
wfLoadExtension("SyntaxHighlight_GeSHi" );
Voir
https://pygments.org/docs/lexerdevelopment/
git clone https://github.com/pygments/pygments.git
"""
pygments.lexers.clearcase
~~~~~~~~~~~~~~~~~~~~~
Lexers for clearcase
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.lexer import Lexer, RegexLexer, ExtendedRegexLexer, include, \
bygroups, default, LexerContext, do_insertions, words, line_re
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Punctuation, Error, Generic, Whitespace
from pygments.util import shebang_matches
__all__ = ['ClearcaseLexer']
class ClearcaseLexer(RegexLexer):
"""
Lexer for (ba|k|z|)sh shell scripts.
"""
name = 'Clearcase'
mimetypes = ['application/text']
filenames = ['*.clr']
aliases = ['clearcase']
url = 'https://en.wikipedia.org/wiki/Unix_shell'
version_added = '0.6'
tokens = {
'root': [
include('basic'),
(r'`', String.Backtick, 'backticks'),
include('data'),
include('interp'),
],
'interp': [
(r'\$\(\(', Keyword, 'math'),
(r'\$\(', Keyword, 'paren'),
(r'\$\{#?', String.Interpol, 'curly'),
(r'\$[a-zA-Z_]\w*', Name.Variable), # user variable
(r'\$(?:\d+|[#$?!_*@-])', Name.Variable), # builtin
(r'\$', Text),
],
'basic': [
(r'\b(ct|clearcase)(\s*)\b',
bygroups(Keyword, Whitespace)),
(r'\b(chtype|rmname|rmelem|find|rmbranch|rmtype|mklbtype|mklabel|mkbrtype|rename|rmlabel,lsvob|lsview|setview|rmview|lsvob|pwv|checkout|checkin|co|ci|lsc)(?=[\s)])',
Name.Builtin),
(r'\A#!.+\n', Comment.Hashbang),
(r'#.*\n', Comment.Single),
(r'\\[\w\W]', String.Escape),
(r'(\b\w+)(\s*)(\+?=)', bygroups(Name.Variable, Whitespace, Operator)),
(r'[\[\]{}()=]', Operator),
(r'<<<', Operator), # here-string
(r'<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
(r'&&|\|\|', Operator),
],
'data': [
(r'(?s)\$?"(\\.|[^"\\$])*"', String.Double),
(r'"', String.Double, 'string'),
(r"(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
(r"(?s)'.*?'", String.Single),
(r';', Punctuation),
(r'&', Punctuation),
(r'\|', Punctuation),
(r'\s+', Whitespace),
(r'\d+\b', Number),
(r'[^=\s\[\]{}()$"\'`\\<&|;]+', Text),
(r'<', Text),
],
'string': [
(r'"', String.Double, '#pop'),
(r'(?s)(\\\\|\\[0-7]+|\\.|[^"\\$])+', String.Double),
include('interp'),
],
'curly': [
(r'\}', String.Interpol, '#pop'),
(r':-', Keyword),
(r'\w+', Name.Variable),
(r'[^}:"\'`$\\]+', Punctuation),
(r':', Punctuation),
include('root'),
],
'paren': [
(r'\)', Keyword, '#pop'),
include('root'),
],
'math': [
(r'\)\)', Keyword, '#pop'),
(r'\*\*|\|\||<<|>>|[-+*/%^|&<>]', Operator),
(r'\d+#[\da-zA-Z]+', Number),
(r'\d+#(?! )', Number),
(r'0[xX][\da-fA-F]+', Number),
(r'\d+', Number),
(r'[a-zA-Z_]\w*', Name.Variable), # user variable
include('root'),
],
'backticks': [
(r'`', String.Backtick, '#pop'),
include('root'),
],
}
def analyse_text(text):
return 1
python scripts/gen_mapfiles.py
pyinstaller --onefile __main__.py
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pygments.cmdline import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Python 3.7.3 (default, Mar 23 2024, 16:12:05) Du coup j'ai du revenir en arrière sur la version de pygments, juste avant cette version: SHA-1: e7f50060fd644b17de8debbd2a5c259c64898d4f * Drop support for EOL Python 3.7 (#2601)
SHA-1: 276dcf8ae4af6e959e13ea6f63d9f5e7bc80ea48 * Update CHANGES git reset --hard 276dcf8ae4af6e959e13ea6f63d9f5e7bc80ea48
python scripts/gen_mapfiles.py
pyinstaller --onefile __main__.py
|