Extension talk:SyntaxHighlightPages/Flow

About this board

how to replace SyntaxHighlight for file extension

5
Nicole Sharp (talkcontribs)

How do I change the SyntaxHighlight for mac files so that they are highlighted as ma files instead? Wolfram Mathematica (Pygments language mma) ma filetype is the closest I can find in Pygments to represent Maxima mac files (which is not included with Pygments), but the mac filetype is already assigned in Pygments to Easytrieve (Pygments language easytrieve). Nicole Sharp (talk) 17:15, 14 March 2021 (UTC)

Nicole Sharp (talkcontribs)

It might be easier if the Pygments language could be manually selected as the page content model, instead of a generic "syntaxhighlight." This would allow for example XHTML files saved as htm to be displayed using either Pygments html or Pygments xml. Nicole Sharp (talk) 17:25, 14 March 2021 (UTC)

Gittenburg (talkcontribs)

Selecting a language is out of the scope of this extension.

More feasible would be allowing extensions to be mapped to lexer names like:

$wgSyntaxHighlightPagesSuffixes = ["htm" => "html"];

I opened an issue for this on GitHub. While I don't have time to implement this, I would accept a pull request that implements this feature.

Nicole Sharp (talkcontribs)

Being able to manually assign languages to file extensions would definitely be helpful. Extension:Highlightjs_Integration allows this type of customization. Would it be possible to apply HighlightJS instead of Pygments for SyntaxHighlightPages? HighlightJS supports Maxima whereas Pygments does not. The closest language to Maxima (maxima / .mac) in Pygments is actually mupad (.mu) instead of mma (.ma) but full Maxima support would be better. Nicole Sharp (talk) 22:32, 8 April 2021 (UTC)

Gittenburg (talkcontribs)

I'm afraid switching to Highlightjs is also out of the scope of this extension. Mapping extensions to languages could be very easily implemented but I don't have the time for it -- however someone responded on GitHub maybe they'll implement it.

Once this has been solved you might be able to use https://github.com/FoamScience/maximalexer ... pygments allows the installation of unofficial lexers, but I don't know how easy it is to use them with the MediaWiki extension.

Reply to "how to replace SyntaxHighlight for file extension"
Nicole Sharp (talkcontribs)

There are no examples given of how to add file extensions. Is this the correct syntax?

$wgSyntaxHighlightPagesSuffixes = array('txt', 'htm', 'html', 'css', 'xml', 'js', 'php', 'htaccess', 'ma');

Nicole Sharp (talk) 17:07, 14 March 2021 (UTC)

Nicole Sharp (talkcontribs)

SyntaxHighlight of .htm files does not seem to work (though .html does). Did I add the .htm extension incorrectly? Nicole Sharp (talk) 19:49, 14 March 2021 (UTC)

Nicole Sharp (talkcontribs)

I tried using '.htm' instead of 'htm' but that does not appear to work either. Nicole Sharp (talk) 19:52, 14 March 2021 (UTC)

Nicole Sharp (talkcontribs)

SyntaxHighlightPages does recognize the .htm pagename though and automatically applies the syntaxhighlight content model. It just does not display the SyntaxHighlight formatting for the HTML content like it does with the .html pagename. So looks like a bug maybe if it is recognizing the pagename as a valid filetype, but not colorizing the page with HTML SyntaxHighlight. Nicole Sharp (talk) 19:58, 14 March 2021 (UTC)

Gittenburg (talkcontribs)

Hi, thanks for this report.

This extension uses Extension:SyntaxHighlight which in turn uses the Python Pygments library. While the Pygments library does have a get_lexer_for_filename function that correctly returns the HTML lexer for the html extension, the Extension:SyntaxHighlight does not provide a PHP wrapper around that method, because it doesn't need it ... which is of course unfortunate for this extension.

I'll update the page to add an example and explain this pitfall. I however don't have the time to work on a PHP wrapper for Extension:SyntaxHighlight, so as long as there is none this problem will persist for this extension.

There are no older topics
Return to "SyntaxHighlightPages/Flow" page.