Extension talk:SyntaxHighlight/Archive 2019
Add topic| This page used the Structured Discussions extension to give structured discussions. It has since been converted to wikitext, so the content and history here are only an approximation of what was actually displayed at the time these comments were made. |
In MediaWiki 1.26 this extension went through a major rewrite and switched from the 3rd party library Geshi to the 3rd party library Pygments. Make sure to mention which version of MediaWiki you are using when asking questions. |
Please do not make requests for support for languages or bug reports for highlighting errors on this page. This extension uses the Pygments library, which is not maintained by the MediaWiki developers. Bug reports and feature requests for the highlighting should be made to the Pygments developers. |
Previous discussion was archived at Extension talk:SyntaxHighlight/Archive 2017 on 29 March 2017.
Size limit
[edit]I suggest adding this to Extension:SyntaxHighlight#Syntax highlighting error category:
"The category may also be added if there are more than 1000 lines or more than 100 kB text.[1]"
It was reported at w:Wikipedia:Village pump (technical)#Syntax highlighting. I have not actually been able to produce the error with 5000 lines at enwiki but it does happen above 100 kB.
PrimeHunter (talk) 17:59, 3 February 2019 (UTC)
- Added. Thanks for the good notes. :-) –Quiddity (talk) 20:03, 3 February 2019 (UTC)
Is there a defined language for MediaWiki syntax?
[edit]I would like to use the <source> tag to present MediaWiki wikicode, but I couldn't find any related lexer. Is there any one I can use? Epok (talk) 16:42, 14 February 2019 (UTC)
- Nope. See phab:T29828. 「ディノ奴千?!」☎ Dinoguy1000 17:18, 14 February 2019 (UTC)
- Thanks for the link. Too bad MediaWiki doesn't support its own syntax! Epok (talk) 20:09, 14 February 2019 (UTC)
- Two points:
- Try html. It's better than nothing.
- The tag source is deprecated. Use syntaxhighlight instead. IKhitron (talk) 22:17, 14 February 2019 (UTC)
- Try "moin" as well. Mediwiki format was orignated from Moinmoin.
- See https://www.wikimatrix.org/compare/mediawiki+moinmoin Cedar101 (talk) 07:09, 15 February 2019 (UTC)
- MediaWiki's syntax was mostly derived from UseModWiki's, not Moinmoin's, which shouldn't be particularly surprising since UseMod was its predecessor on WMF wikis. (Where the syntax ultimately comes from is a completely different question, of course, and one I'm not sure would be particularly easy to answer.)
- Of course, this doesn't really matter much for syntax highlighting; as long as the markup systems are sufficiently similar to each other, using Moinmoin's lexer for MediaWiki markup should still be a decent stopgap. 「ディノ奴千?!」☎ Dinoguy1000 17:00, 15 February 2019 (UTC)
- Yet, I tried 'lang=moin', and it doesn't really do anything concerning syntax highlight. Precision: what I'm trying to show in the code is template inclusion.
- Anyway, I just would like that the page I created were not automatically categorized as a "Page with syntax highlighting errors". I think the only way to do so is not to use this tag... Epok (talk) 17:06, 15 February 2019 (UTC)
Is there a way to add keywords to a language from the wiki(a) side of things?
[edit]I help to maintain a small wiki on Wikia (aka Fandom) for the PICO-8 fantasy video game console, which is programmed in a modified version of Lua. We've got syntaxhighlight working for Lua code blocks, which is great, but it would be nice if we could add built-in keywords (only functions, I think) that aren't present in vanilla Lua. It's not crucial, but it would be nice.
Obviously we only have just so much access, as we don't maintain the Fandom servers, so it's quite possible that what we'd need to configure is out of our reach, but I figured it can't hurt (much) to ask. Even knowing it's not possible is useful information.
Thanks!
Edit: Not sure exactly what version is installed on Wikia, but I think it's at least the Pygments version. Felice Enellen (talk) 07:49, 11 March 2019 (UTC)
- What you're asking for would require server-side access, which you don't have on most server farms (including Wikia/Fandom). Even before that, though, your first step would be writing (or finding someone else to write for you) a Pygments lexer for your language; it sounds like you could just modify the Lua lexer, which would greatly simplify that process. Once that's done, you should contact Wikia/Fandom staff to find out if they'll add the lexer for your wiki (or, if they prefer not to fragment the SyntaxHighlight configuration between their wikis, if they'll add it for all wikis). Alternatively, you could try to get the lexer added to Pygments itself and then try to get the WMF to update the Pygments version/lexer library packaged with the extension, then try to get Wikia/Fandom to upgrade to the new extension version, but obviously that route would be far more work (with far more places it could stall out).
- If none of this appeals to you, of course, you could look into Javascript-based syntax highlighting; this would only require Wikia/Fandom staff to approve the JS code (though you would also have to support the code itself for as long as you used it). 「ディノ奴千?!」☎ Dinoguy1000 19:29, 13 March 2019 (UTC)
- I think the lexer idea might be the best choice, and if that's not an option, then maybe just let it go and use the vanilla highlighting. As I said, even knowing it's not likely to happen is useful info. :) Thanks! Felice Enellen (talk) 22:05, 15 March 2019 (UTC)
using parameters driving me crazy
[edit]LS,
I have installed mediawiki version 1.30 and trying to get this working on my page:
===eind schakelaars===
// Mechanical endstop with COM to ground and NC to Signal uses "false" here (most common setup).
#define X_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
#define Y_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
#define Z_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
#define X_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
#define Y_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
#define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
#define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the probe.
It places a correct border around the code but no line numbers infront ore highlighted ones.
So whats wrong here?? Gharryh (talk) 18:40, 3 April 2019 (UTC) try
<syntaxhighlight lang="c++" line start="530" highlight="2-3" style="border:2px dashed red"> // Mechanical endstop with COM to ground and NC to Signal uses "false" here (most common setup). #define X_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Y_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define Z_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop. #define X_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Y_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop. #define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the probe. </syntaxhighlight>
The language you specified, does not exist (there is no language "c / c++"). Either use "c" or "c++". The example above looks like:
// Mechanical endstop with COM to ground and NC to Signal uses "false" here (most common setup).
#define X_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
#define Y_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
#define Z_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
#define X_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
#define Y_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
#define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
#define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the probe.
- edit* strangely, when I tested it, lines 2-3 were highlighted correctly. Now, the highlight is gone and I do not seem to get it to work again. sorry. -- Tobias (talk) 19:12, 3 April 2019 (UTC)
- But under supported languages it says:....
- BrainFuck
- C / C++
- C#
- This is not realy clear that one should only use C++
- edit:
- It looks also to be a version problem As I have wiki version1.30 installed where it doesnt work, and this website uses 1.33 where it works. Gharryh (talk) 15:03, 4 April 2019 (UTC)
Installation / upload caveat
[edit]If you upload whole mediawiki installation or just this extension via FTP manager that can use ASCII mode (for Filezilla use Edit -> Settings -> Transfers -> FTP:File Types and check OFF "Treat files without extension as ASCII files") for file transfer this extension wont work with error "zipimport.ZipImportError: bad local file header:". Besuglov.S (talk) 04:25, 18 April 2019 (UTC)
- If you're using an FTP manager to upload files to your server, and you mess with the ASCII mode settings, you're generally going to have a lot of problems of this nature; it's nothing specific to this extension (the default settings are default for a reason). 「ディノ奴千?!」☎ Dinoguy1000 13:21, 18 April 2019 (UTC)
- The thing is Filezilla defaults to "Treat files without extension as ASCII files" and pygmentize is falling into this category.
- Filezilla uploads extension damaged.
- I was unable to find zipimport error message anywhere on this page and it gives no clue about the actual problem. Besuglov.S (talk) 17:14, 18 April 2019 (UTC)
Dirty Hack to get it work on Windows
[edit]Since passing parameters and results to the pygmentizer through stdin/stdout does not work on Windows,
i tried to use files for input and output. Pleas adjust the temporary directory to your environment.
Works for me on MediaWiki 1.33.
Greetings,
Ralf Naujokat
function ( $oldValue, &$ttl ) use ( $code, $lexer, $options, &$error ) {
$optionPairs = [];
foreach ( $options as $k => $v ) {
$optionPairs[] = "{$k}={$v}";
}
$tmp = tempnam( 'D:\\MediaWiki\\tmp', 'SH' );
$tmp_out = $tmp . ".out";
$tmp_in = $tmp . ".in";
file_put_contents( $tmp_in, $code );
$result = Shell::command(
self::getPygmentizePath() .
' -l ' . $lexer .
' -f ' . 'html' .
' -O ' . implode( ',', $optionPairs ) .
' -o ' . $tmp_out .
' ' . $tmp_in
)
// ->input( $code )
->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )
->execute();
if ( $result->getExitCode() != 0 ) {
$ttl = WANObjectCache::TTL_UNCACHEABLE;
$error = $result->getStderr();
return null;
}
$out = file_get_contents( $tmp_out );
unlink( $tmp );
unlink( $tmp_in );
unlink( $tmp_out );
return $out;
}
153.100.131.97 (talk) 09:48, 2 August 2019 (UTC)
- Oops, forgot to mention:
- Modify the file 'includes\SyntaxHighlight.php', starting at line 305
153.100.131.97 (talk) 09:50, 2 August 2019 (UTC)- Thank you so much for sharing this - I was ripping my hair out! 5.148.147.130 (talk) 10:28, 31 October 2019 (UTC)
- Also thank you, but have you get syntax highlighter working when attribute highlight is used (highlight="1,5,6" for example)? 94.124.185.2 (talk) 15:41, 19 December 2019 (UTC)
- I´ve tried with MediaWiki 1.35.3, but the tmp.out files are not created for the results, thus not working so far. Escalatr (talk) 14:32, 16 March 2023 (UTC)
Highlighting and numbering skipping lines?
[edit]I just updated to 1.32 and now the code that has highlights skips a line for the highlighting? Example at http://pundit.pratt.duke.edu/wiki/Sandbox Thoughts? The issue does not happen if line numbers are not requested. I'm running on Bluehost and...I will note the code that looks wrong on my site looks fine on this one so...merde. DukeEgr93 (talk) 04:22, 7 August 2019 (UTC)
- Edit: I had a $wgPygmentizePath in LocalSettings that pointed to the pygmentize because originally, after updating to 1.32, I didn't get colors. I just installed the newest version of pygmentize into the SyntaxHighlighter folder and got rid of the $wgPygmentizePath line and - poof - everything's good again! DukeEgr93 (talk) 02:19, 11 August 2019 (UTC)
Using composer to install after run Mediawiki Wizard
[edit]There are a reported bug in the Mediawiki Wizard, so, it is a workaround.
- Solicitate SyntaxHighlight with the Online Mediawiki Wizard, and install it (the "bug install");
- Test to edit source code using the Wiki (edit some source tag)
- If not running:
- With SSH, at the Mediawiki folder, run again the Composer by the command
php composer.phar update --no-dev. - Check that is executable,
ls -l /path/to/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize(will return for example-rwxr-xr-x).
It this the most important after all install... Dochmod a+x pathwhen necessary. - Try again
- .... other checks
- With SSH, at the Mediawiki folder, run again the Composer by the command
That the item 3.1, if try again, the messages will be:
> ComposerHookHandler::onPreUpdate Loading composer repositories with package information Updating dependencies Generating optimized autoload files > ComposerVendorHtaccessCreator::onEvent
If there are some permission errors or a kind of "Composer: file_put_contents(./composer.json): failed to open stream", etc. Try:
sudo chown -R $USER yourHtmlMediawikiFolder/sudo chown -R $USER ~/.composer/
and, after it, run composer again (item 3.1). You your user is a problem, after run composer put back www-data:
sudo chown -R www-data yourHtmlMediawikiFolder/. Krauss (talk) 14:43, 17 September 2019 (UTC)
Disruption in syntaxhighlight codes
[edit]The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.
I insert <syntaxhighlight> codes into the page through the visual editor.
But after saving the page, and editing it again with the visual editor, I see the <syntaxhighlight> code incorrectly !!!
please guide me
Thanks Sokote zaman (talk) 21:14, 3 October 2019 (UTC)
- Same here. If anyone has a solution to this, it would be appreciated 5.148.147.130 (talk) 10:29, 31 October 2019 (UTC)
- Worked this out.
- The Uri API param in my Parsoid config.yaml was set to http : / / localhost/api.php, but needed to point at the exact URL to avoid any 302 redirects.
- Once changed to https: / / mywikihostname/api.php, SyntaxHighlighter started working correctly in Visual Editor :D 5.148.147.130 (talk) 12:27, 18 November 2019 (UTC)
- Thank you for your comment
- Thank you very much!
- My going was resolved and everything returned to normal
- Thank Sokote zaman (talk) 01:01, 24 November 2019 (UTC)
how to change <source> into <syntaxhighlight>?
[edit]Hi there,
I am using Geshi quite long and therefor all my pages use the code
<source>foobar</source>do I need to change them all into "syntaxhiglight"?
176.198.80.41 (talk) 12:47, 5 October 2019 (UTC)
- I would recommend that to avoid confusion with the HTML element, but there is no urgent need. PerfektesChaos (talk) 17:14, 5 October 2019 (UTC)