Coder Social home page Coder Social logo

nicolas01 / highlightjs_integration Goto Github PK

View Code? Open in Web Editor NEW
8.0 8.0 3.0 386 KB

A MediaWiki extension to use the client-side syntax highlighter highlight.js

License: GNU Affero General Public License v3.0

PHP 87.30% CSS 7.86% JavaScript 4.84%

highlightjs_integration's People

Contributors

d-simon avatar nicolas01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

highlightjs_integration's Issues

XAMPP Windows, cannot load extension files

Trying to run with MediaWiki 1.35.3 in XAMPP (Windows 10), however extension files cannot be loaded, seems the path part extensions\Highlightjs_Integration is omitted(?).
Is there anything I can adjust?

Apache error.log:

[Thu Mar 16 12:10:53.189761 2023] [php:warn] [pid 10668:tid 1916] [client ::1:56357] PHP Warning:  md5_file(C:\\xampp\\htdocs\\wiki/highlight/highlight.min.js): Failed to open stream: No such file or directory in C:\\xampp\\htdocs\\wiki\\includes\\OutputPage.php on line 3993, referer: http://localhost/wiki/Template:Code_block?debug=true
[Thu Mar 16 12:10:53.189761 2023] [php:warn] [pid 10668:tid 1916] [client ::1:56357] PHP Warning:  OutputPage::transformFilePath: Failed to hash C:\\xampp\\htdocs\\wiki/highlight/highlight.min.js [Called from OutputPage::transformFilePath in C:\\xampp\\htdocs\\wiki\\includes\\OutputPage.php at line 3995] in C:\\xampp\\htdocs\\wiki\\includes\\debug\\MWDebug.php on line 430, referer: http://localhost/wiki/Template:Code_block?debug=true
[Thu Mar 16 12:10:53.190758 2023] [php:warn] [pid 10668:tid 1916] [client ::1:56357] PHP Warning:  md5_file(C:\\xampp\\htdocs\\wiki/init.js): Failed to open stream: No such file or directory in C:\\xampp\\htdocs\\wiki\\includes\\OutputPage.php on line 3993, referer: http://localhost/wiki/Template:Code_block?debug=true
[Thu Mar 16 12:10:53.190758 2023] [php:warn] [pid 10668:tid 1916] [client ::1:56357] PHP Warning:  OutputPage::transformFilePath: Failed to hash C:\\xampp\\htdocs\\wiki/init.js [Called from OutputPage::transformFilePath in C:\\xampp\\htdocs\\wiki\\includes\\OutputPage.php at line 3995] in C:\\xampp\\htdocs\\wiki\\includes\\debug\\MWDebug.php on line 430, referer: http://localhost/wiki/Template:Code_block?debug=true
[Thu Mar 16 12:10:53.192769 2023] [php:warn] [pid 10668:tid 1916] [client ::1:56357] PHP Warning:  md5_file(C:\\xampp\\htdocs\\wiki/custom.css): Failed to open stream: No such file or directory in C:\\xampp\\htdocs\\wiki\\includes\\OutputPage.php on line 3993, referer: http://localhost/wiki/Template:Code_block?debug=true
[Thu Mar 16 12:10:53.192769 2023] [php:warn] [pid 10668:tid 1916] [client ::1:56357] PHP Warning:  OutputPage::transformFilePath: Failed to hash C:\\xampp\\htdocs\\wiki/custom.css [Called from OutputPage::transformFilePath in C:\\xampp\\htdocs\\wiki\\includes\\OutputPage.php at line 3995] in C:\\xampp\\htdocs\\wiki\\includes\\debug\\MWDebug.php on line 430, referer: http://localhost/wiki/Template:Code_block?debug=true
[Thu Mar 16 12:10:53.192769 2023] [php:warn] [pid 10668:tid 1916] [client ::1:56357] PHP Warning:  md5_file(C:\\xampp\\htdocs\\wiki/highlight/styles/vs2015.min.css): Failed to open stream: No such file or directory in C:\\xampp\\htdocs\\wiki\\includes\\OutputPage.php on line 3993, referer: http://localhost/wiki/Template:Code_block?debug=true
[Thu Mar 16 12:10:53.192769 2023] [php:warn] [pid 10668:tid 1916] [client ::1:56357] PHP Warning:  OutputPage::transformFilePath: Failed to hash C:\\xampp\\htdocs\\wiki/highlight/styles/vs2015.min.css [Called from OutputPage::transformFilePath in C:\\xampp\\htdocs\\wiki\\includes\\OutputPage.php at line 3995] in C:\\xampp\\htdocs\\wiki\\includes\\debug\\MWDebug.php on line 430, referer: http://localhost/wiki/Template:Code_block?debug=true

SyntaxHighlight uses deprecated Sanitizer::validateAttributes syntax

On a page where I use SyntaxHighlight, once I click submit, I get a huge page with warnings, foremost:

Deprecated: Use of Sanitizer::validateAttributes with sequential array was deprecated in MediaWiki 1.35. [Called from HighlightjsIntegration::renderSyntaxhighlight in C:\wamp\www\wiki\extensions\Highlightjs_Integration-master\HighlightjsIntegration.class.php at line 42] in C:\wamp\www\wiki\includes\debug\MWDebug.php on line 381

I'm using Mediawiki 1.39.1 (lastest) with latest version of Highlightjs_Integration.

Line Numbers

Hello,
Does this extension support line numbers ?

Support style attribute

The SyntaxHighlight extension allows for using the style attribute, but this extension ends up stripping that. This prevents this extension from being a drop-in replacement for the SyntaxHighlight extension.

Extension not working in VisualEditor

When I try to edit a page using VisualEditor, nothing is shown in the code lines. Is there a way to make it work in VisualEditor like SyntaxHighlight_GeSHi does?

I'm using version 1.2 in xampp with MediaWiki 1.31.1, PHP 7.0.33.

Prevent removing leading spaces

When I have a block of code that has leading spaces, the leading spaces from the first line get removed, which throws off the alignment for other lines in the block. The SyntaxHighlight extension does not have this issue and leading spaces are correctly preserved.

MW common pages highlight not working

Hello,
With the default stuff in the init.js nor the suggested code below worked to highlight the commone pages of mediawiki like common.css and common.js
`hljs.configure({
cssSelector: 'pre.code2highlight, code.code2highlight, pre.mwcode'
});

hljs.highlightAll();`

The only one worked is this one from the syntaxhighlighJS v1.2
$(document).ready(function() { $('pre.code2highlight, code.code2highlight, pre.mw-code').each(function(i, block) { hljs.highlightBlock(block); }); });

Support line, start, and highlight parameters from SyntaxHighlight extension

The SyntaxHighlight MediaWiki extension (which this extension aims to provide an alternative to) supports the line parameter (with optional start parameter) for adding line numbers and the highlight parameter for emphasizing specific lines. It seems that base highlight.js does not allow these, but from a few quick Google searches, it appears that there are two plugins that add support and work together:

List Processing & Highlighting Breaks

When using this extension and attempting to use within a numbered list and more than one line of code, like such:

# Step1
# Step 2 has some code: <SyntaxHighlight lang="bash">
Totally
some
bash lines
here
</SyntaxHighlight>
# Step 3

the output is butchered:

  • The first line is highlighted
  • The middle lines are in a separate pre block and not highlighted
  • The last line is left out as as standard text
  • The list numbering resets

It appears that there is a need to strip code if a parser is used. I was able to modify the code using some slightly edited code from the native SyntaxHighlight_GeSHi module to fix this:

	if ($inline) {
		$htmlAttribs['style'] = 'display: inline;';
		$out = Html::rawElement('code', $htmlAttribs, $code);
		return $out;
	} else {
		if ( $parser ) {
			// Use 'nowiki' strip marker to prevent list processing (also known as doBlockLevels()).
			// However, leave the wrapping <div/> outside to prevent <p/>-wrapping.
			$marker = $parser::MARKER_PREFIX . '-syntaxhighlightinner-' .
				sprintf( '%08X', $parser->mMarkerIndex++ ) . $parser::MARKER_SUFFIX;
			$parser->getStripState()->addNoWiki( $marker, $code );
			$code = $marker;
		}
		$out = Html::rawElement('pre', $htmlAttribs, $code);
		return $out;
	}

Modifying the code as shown would then properly box in all the code in the numbered list and keep the list numbering intact.

Also, note really a bug or related, but more as a easy migration from the builtin tooling to this extension (since it doesn't work on Windows and this does), I also added the following to catch (enclose="none"):

		$inline = isset($param['inline']);
		if ($param['enclose'] == 'none') {
			$inline = true;
		}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.