Commit graph

85 commits

Author SHA1 Message Date
Ori Livneh 648744325c Bundle Pygments 2.0.2
Include Pygments 2.0.2 as an executable zip bundle. Also include a script to
automate the process of creating such bundles and to make it reproducible and
verifiable.

Change-Id: I67e6f804e493f065311164c610dc541a5779654e
2015-06-22 22:54:42 +00:00
Ori Livneh f1941f8a56 Only look for a compatible lexer if a direct Pygments match is unavailable
If Pygments ever adds a dedicated lexer for 'cadlisp', for example, we'd want the
extension to use that, rather than use the compatibility map.

Change-Id: Icc610695ac2826bb526f7c69e867576c660ba6ef
2015-06-22 22:47:52 +00:00
Ori Livneh 6484894497 Highlight using Pygments rather than Geshi
GeSHi is unmaintained, lacks support for many popular modern languages, and
suffers from deep architectural flaws, chief among them the inconsistent
tokenization of different languages, each of which requires a custom
stylesheet.

Pygments is a well-maintained alternative. It is, by my count, the most popular
syntax highlighting library around. It is BSD-licensed, actively maintained,
and is widely used in PHP projects.

To keep this easy to review, this change does not include update for l10n
files, and it does not delete the geshi/ directory. I will do those in a
separate patch.

The chief change between this and the previous implementation is that errors
result in the code block not being highlighted, as opposed to not being printed
at all, having been replaced by an angry red error message. I think that is the
right user experience. If you go to StackOverflow or GitHub and try to mark up
your code block as being written in some language that their highlighter
doesn't know about, you don't get an error message -- the code simply doesn't
get highlighted.

Because we don't recursively load dependencies for extensions, to test this,
you will need to create a composer.local.json in $IP and add:

    {
        "extra": {
            "merge-plugin": {
                "include": [
                    "extensions/SyntaxHighlight_GeSHi/composer.json"
                ]
            }
        }
    }

Then run `composer update`.

Bug: T85794
Change-Id: I07446ec9893fae3d1e394f435d3d95cf8be6bc33
2015-06-22 23:37:15 +01:00
Ed Sanders 28ff155a6c Use normal line numbers
'Fancy' line numbers are a fairly useless feature, not seen
in any other code highlighter. As the extension doesn't let you
choose a line number mode, default to normal.

Bug: T101602
Change-Id: Iccbd3ba6c91c58b0ea0f0c09832f1422936cd475
2015-06-09 16:02:18 +01:00
Timo Tijhof c81eb5978c Compare against '$geshi->error' instead of '$geshi->error()' in prepare()
Geshi::error() is a method that returns an HTML string representing
the error.

Geshi->$error is an integer error code.

This code clearly means to compare against the integer code given that
GESHI_ERROR_NO_SUCH_LANG is an integer.

Verified by using eval.php to instantiate "new Geshi( '', 'js' );"
and $geshi->error:
> 2
but $geshi->error():
> "<br /><strong>GeSHi Error:</strong> GeSHi could not find the language"

Change-Id: I1ca77733d4b6b5481c5db6aba9f6b7dda6803099
2015-06-08 16:05:46 +01:00
Gilles Dubuc 58c81408f5 Explicitly define module position
Style modules currently added through addModuleStyles default
to being in the head ("top" position). This is an unhealthy default,
since only critical styles that are needed at pageload should be
in the head. In order to be able to switch the default to "bottom",
existing module positions have to be defined explicitly.

Bug: T97410
Change-Id: Ie120a781ac1950abd7963d6f722aa316b5542b51
2015-05-29 15:28:06 +00:00
Kunal Mehta b4853c7633 Revert "Revert "Add extension.json, empty PHP entry point""
Try #2. Our last attempt loaded $wgGeSHiSupportedLanguages late, and
would override anything if it was already set. We still load it late, but
only if it is not already set.

This reverts commit 033ca20746.

Bug: T88063
Change-Id: Iae0806e06a95b2d8932b3d9e078e6135dd6750a3
2015-05-20 14:36:46 -07:00
Legoktm 033ca20746 Revert "Add extension.json, empty PHP entry point"
This reverts commit 72d1e92263.

Change-Id: I47eab2842f195bf302de0ae3bf15beff1b48290f
2015-05-20 21:21:11 +00:00
Derk-Jan Hartman 72d1e92263 Add extension.json, empty PHP entry point
Bug: T88063
Change-Id: I42afa0bf81f4f89b81a11bcafcb8e4c032a2d173
2015-05-19 17:05:43 -07:00
Brad Jorsch 3fe85b9313 Add api-pretty-content class when pretty-printing API output
The API has wrapped its pretty-printed output since Id9cdf102. Apply an
appropriate class to preserve this now that GeSHi is handling it.

Unfortunately GeSHi itself doesn't support adding more than one arbitrary class
to the <pre> (and we're already using that), so we have to add it in a
post-processing step.

Bug: T88742
Change-Id: I38e41db5c341fe06ff825c82d5a9cd4810b7cc24
2015-02-27 19:12:36 -05:00
Chad Horohoe c8297429a6 Remove obvious function-level profiling
Change-Id: Idd5f9178987000df892dde70c11686ddd9306f10
2015-02-10 13:29:40 -08:00
paladox 966ed89270 Set Geshi version in main php file
The version was set from the ExtensionTypes hook (which runs only on
Special:Version). WikiApiary and other API consumers were unable to
detect the version.

This is an amended resubmission of the reverted d69ae1f3ac, in which
the constant was declared twice.

Change include_once to require_once for langs file (follows-up 168e1296).

Bug: T75666
Change-Id: I836e0df942a066d80255c1b68472e7ee58124357
2015-01-05 12:39:45 +00:00
Ori Livneh 1369e4b813 Initialise in getSupportedLanguages()
Change-Id: Ic155c54ef9fe0dac3a3c09e563828ccb0dcaf481
2014-11-19 12:05:20 -08:00
Reedy a03277741a Revert "Fix tracking for version"
This reverts commit d69ae1f3ac.

Change-Id: Ic724f6fe1b1cbc969ac195762bdf517e129cd9dd
2014-11-19 16:29:52 +00:00
Ori Livneh 168e1296db Avoid file glob in SyntaxHighlight_GeSHi::getSupportedLanguages()
Store the list of supported languages in SyntaxHighlight_GeSHi.langs.php, which
is auto-generated via a maintenance script, updateLanguageList.php.

Change-Id: Ie0be7c42fa6716555c3e03e3f28734d7e0302664
2014-11-18 16:50:59 -08:00
paladox d69ae1f3ac Fix tracking for version
* wikiapiary does not detect the version so this way fixes the issue.

Note this has been tested.

Change-Id: I2ad43801cc71285cad8576657c5dc5e4668a37b3
2014-11-14 21:36:42 +00:00
Kunal Mehta 53e1b42012 Check $wgUseSiteCss inside ResourceLoaderGeSHiLocalModule
This way the module is always loaded, but will be empty or not
depending on the config setting.

Change-Id: Id4f18c58f62c530fbf7d81ff0880281684296b7d
2014-10-13 16:35:49 -07:00
Brad Jorsch 8dde10991c Implement 'ApiFormatHighlight' hook
Core change I04b1a3842 adds a hook to allow extensions to
syntax-highlight the pretty-printed output from the API.

Change-Id: If0413a1d922ff8a47afc355e0a2cc276cf54b400
2014-10-13 16:22:59 -07:00
Kunal Mehta da41c89fb7 Fix incorrect casing of "ContentHandler" class name
Change-Id: I502c4d2f401f655153976ddce5c3d08e469b050f
2014-09-14 21:50:20 -07:00
Bartosz Dziewoński 9d69259b13 Parse page content using the standard parser first for link tables
We could do this using TextContent::fillParserOutput(), but alas it is
'protected', so we have to duplicate a tiny bit of code from there.

Bug: 68757
Change-Id: I7d98fa0f97fb195d23caa3d7448a15c3bbe430ca
2014-07-30 21:09:05 +02:00
Bartosz Dziewoński d7b87ac836 Use ContentGetParserOutput hook instead of ShowRawCssJs
Depends on I58679856 in core MediaWiki.

This breaks compatibility with MW < 1.24.

Bug: 64859
Change-Id: Idf4ad4397101a4d19be2ac773cd4bad52188d903
2014-06-20 19:57:59 +00:00
Reedy 5cdceae3c3 Update comments
Add a couple of GPL headers

Change-Id: I55acc3bf4e45ae62e41ffe16f081073111171779
2014-06-15 17:22:00 -07:00
Reedy 13dfba4f9a Rename hook subscriber
Swap global function for closure

Change-Id: I41a17461546ac76e223db1c2dc5b2be1ff093af8
2014-06-16 00:20:08 +00:00
Bartosz Dziewoński 44177a6b13 Make sure font size in GeSHi output is not too small
Follow-up to I7bbdcc0a, see it for details.

Also cleared up the comment describing this here.

Bug: 26204
Change-Id: I103a6d5c3e1f91cf74e244756c2ad318e429a78e
2014-05-06 01:50:04 +02:00
Bartosz Dziewoński 79b37aa109 Remove unused backwards-compatibility code
Change-Id: Iffa42d7579d882cd119851a075b6e63f670c02bc
2014-05-05 12:32:56 +02:00
Bartosz Dziewoński b6d8b1a5b9 Use ResourceLoader modules for style loading
We want to be able to track what styles were added to be able to deliver
this information to MediaWiki's live preview functionality (in order
to solve bug 24134).

This required moving some code in SyntaxHighlight_GeSHi class around.

The old way still works and is used for MediaWiki 1.20 and lower.

Bug: 24134
Change-Id: Iafd91de8922be55688fedef4e43a8e7f54d4e1cc
2014-05-04 20:46:21 +02:00
Brad Jorsch 335a5e9a9c Protect tabs from HTML Tidy
HTML Tidy doesn't care for tabs, and likes to always output spaces. This
can break the syntax-highlighted output, since Tidy converts tabs to
spaces on the source-code level instead of on the rendered HTML level,
even inside <pre> tags where it really shouldn't (this is probably a bug
in Tidy).

r97300 fixed the bad indenting by converting tabs to spaces before
highlighting, which works around Tidy's bug but breaks highlighting of
languages where tabs are significant (e.g. Whitespace).

It turns out that Tidy's tab mangling occurs while it's reading the
source file, before the conversion of entities such as &#9; to tab. So
GeSHi can armor its <pre>-wrapped output against Tidy's bug by encoding
all tabs as &#9;.

Bug: 30930
Bug: 57826
Change-Id: Id541e2712bd3f94446442ccf2e1e2f214e2801ba
2013-12-02 16:43:36 +00:00
Bryan Petty cd001a9ed9 Add Option to Enable Keyword Links
Patch by Bryan Petty

Bug: 53787
Change-Id: I8c818859df8240cfcfef94d06d5d12a848cc76dc
2013-10-09 09:03:03 +00:00
Dereckson f976a48f37 (bug 44214) Fix bundled GeSHi library inclusion path
Currently, the SyntaxHighlight GeSHi extension includes geshi/geshi.php.

This creates a conflict when an up to date GeSHI library exists in PHP included path.

This change let the SyntaxHighlight GeSHi include our bundled version instead.

Change-Id: Ie8f9aa6182a38508201d639723e876c156d8b0d1
2013-03-06 03:40:00 +00:00
daniel 064fb261db Use new ContentGetParserOutput hook.
Using ContentGetParserOutput instead of ShowRawCssJs allows highliting to be applied
for other kinds of scripts as well (e.g. Lua). It also allows more special case code
for CSS and JS to be phased out.

NOTE: this requires Ibfb2cbef to be merged in core!

Change-Id: Ie260c22680ec9a31e505c685d70e17efe8a7bf44
2013-03-05 19:52:04 +00:00
Ori.livneh 0122c20452 Merge "(bug 26204) font-size is too small" 2013-02-22 23:41:19 +00:00
Ori Livneh 9fd1639d46 Disable some highlighting for MOUSs
(...modules of unusual size.)

Enabling full syntax highlighting for very long Lua modules can produce DOMs
that have hundreds of thousands of elements and cause browsers to lock up.

I took a count of spans by class (which amounts to a count of tokens by type)
of https://en.wiktionary.org/wiki/Module:languages and came up with:

       sy0:      62545 (symbols)
       br0:      61952 (brackets)
       st0:      39291 (strings)
       kw3:       7746 (keywords)
       kw1:          3
       kw2:          2
       co2:          2
       co1:          2
       nu0:          1
     ------     ------
     Total:     171544

GeSHi allows you to disable highlighting for a particular token type (see
<http://qbnz.com/highlighter/geshi-doc.html#disabling-lexics>) which like a
good way of handling this issue.

Disabling symbols (set_symbols_highlighting(false)) removes both sy0 and br0
elements from the DOM (about 124k elements in the case of Module:languages),
with about 47k elements remaining on the page. This is enough to make Chromium
responsive on my laptop (2.3ghz i5, 8 GB RAM), but it's still noticeably
sluggish. Adding 'set_string_highlighting(false);' removes another 40k elements
from the rendered output, and the resulting DOM is quite zippy at 8k elements.

Proposed solution: disable symbols highlighting when >100 kB; disable strings
highlighting too when >200 kB.

Change-Id: I90c645f9d03bbdc135058a3717a463dec40aa77d
2013-02-20 22:06:59 -08:00
Antoine Musso 6d54985ad6 (bug 26204) font-size is too small
The Geshi rendered output has a font-size of 10px where we would expect
13px just like for <pre>.

Bug 33496 against MediaWiki core dealt with that issue already: in some
(all?) browser 'monospace' has a size of 13px where as the default is
16px. When defining a font-size of 0.8em the monospace is scaled down to
10 px which is too small. By appending another font statement, the
browser treat monospace as a default font and thus scale it starting
with 16px instead of 13px.

This patch append a style to geshi which set the font-family to
"monospace, monospace" thus tricking the browser in considering
monospace a regular font.

Change-Id: I7bbdcc0a21010513473a7ca9d784df77e9920b5b
2013-02-13 22:37:00 +01:00
Siebrand Mazeland c602c5a4a7 Maintenance for extension SyntaxHighlight_GeSHi.
* Use Message class where possible.
* Removed superflous newlines.
* Update .gitignore.

Change-Id: Ic2386183e240662331656ebadcaad1057569fb7c
2012-08-26 11:24:29 +02:00
Catrope a62433879b Shut up a PHP notice when the (css|js) expression doesn't match anything
This can happen if the TitleIsCssOrJsPage hook causes a page without a
.css or .js extension to be considered a CSS/JS page.

Change-Id: I875a7f89f683336f18e70358fe589cef706fd5d1
2012-07-18 16:33:04 -07:00
Timo Tijhof b06fbd3b60 Remove usage of mw-code-inline
Remove usage of mw-code-inline:
 * That class ended up not being merged into core, so it does nothing.
   Only mw-code (for the <pre> wrap) is needed.
   7c9b2273c9cbdae90c9f4e3890a13619f769c5d0 (mediawiki/core) had both
   in an earlier patch version, but only mw-code was merged.

Follows-up:
 * mediawiki/extensions/SyntaxHighlight_GeSHi:
   dc147a5ef1
   Use .mw-code and .mw-code-inline

 * mediawiki/core
   7c9b2273c9cbdae90c9f4e3890a13619f769c5d0
   Add .mw-code styles in core

Change-Id: I793c05c3e103209cf966d9e35ab37c05528cdbb8
2012-05-11 04:36:18 +02:00
Timo Tijhof dc147a5ef1 Use CSS classes .mw-code and .mw-code-inline
- Follows-up I4ff5d0197ba8dc0dad3cafd03f2b120bc22e75cb

- Reverts r113190 (redundant fix that caused 35875)

- Fixes:
 * bug 19416
 * bug 35875

Change-Id: Iaa2227348ca632d4a261c149bdf2428b4b48adc7
2012-04-14 06:08:20 +02:00
Sam Reed d2f784ca96 Documentation, spaces, braces, explicit member variables 2012-03-09 23:33:42 +00:00
Krinkle 5dfa1034c1 [SyntaxHighlight GeSHi] Use <code> and <pre> instead of <span> and <div> to allow skins to universally style these without requiring local wikis to manually maintain a copy of each skins's <pre> style and apply it to .mw-geshi
* Fixes
-- (bug 19416) GeSHi-generated blocks should use <pre> style for the container
2012-03-06 22:35:40 +00:00
Robin Pepermans b81f422ffc Add mw-content-ltr/rtl class: fixes bug 33538: Line numbers are outside of left border when using <source ... line start= > on RTL wikis
Also make sure mw-content-ltr/rtl is the same as the dir attribute value. Restrict that value to either ltr or rtl (not sure if rtl really needed; source code is always ltr). Also remove text-align:left; as it can/should be set manually in the <source> tag.
2012-01-05 19:46:42 +00:00
Sam Reed 65ffff273a Fix whitespace
Don't use direct member variable access
2011-12-16 14:51:31 +00:00
Sam Reed 01139727ee Documentation 2011-12-02 17:00:19 +00:00
Roan Kattouw 4227b5510d (bug 27714) Load MediaWiki:Geshi.css using ResourceLoader. Modified patch by Lewis Cawte 2011-11-20 18:07:20 +00:00
Brion Vibber e739c5d3b8 * (bug 30930) Fix bad tab-to-space conversion in SyntaxHighlight_GeSHi when $wgUseTidy on
Tidy always converts tabs to spaces on input; on a big <pre> section this is ok but it tends to fail on syntax-highlighted output, where the spacing should depend on the *output* not the *input markup*.
As a workaround, when $wgUseTidy is enabled we now apply our own tab-to-space conversion preemptively on the input before feeding it into GeSHi for highlighting; this keeps the right spacing through to output.
2011-09-16 17:52:28 +00:00
Victor Vasiliev bcd5a74456 Make certain members of the SyntaxHighlight_GeSHi class public, so other
extensions may use it.
2011-08-14 06:59:35 +00:00
Brion Vibber 0cd1f4b868 * (bug 10201) SyntaxHighlight_GeSHi now shows the text unformatted along with warning if the language is invalid or unrecognized.
Uses a simple <pre> which may not be ideal but works ok. :D
Consolidated a few repeat lines.
2011-05-13 13:27:29 +00:00
Max Semenik 25fb269d86 SyntaxHighlight_GeSHi: collapse language list by default to look less scary 2011-02-25 16:38:23 +00:00
Sam Reed 8b3fe7231c Minor followup to r81865, only set dir to ltr if it's not already set to something else 2011-02-11 00:31:17 +00:00
Sam Reed 0ed4e3e390 *(bug 10081) Allow html attribute on SyntaxHighlight GeSHi extension
Patch by Umherirrender

(Seems to be all but based on the Poem implementation, as per Brions suggestion)
2011-02-10 01:59:14 +00:00
Sam Reed 40db2f22e7 Explicitally define a couple of variables 2011-01-23 09:38:33 +00:00