Page MenuHomePhabricator

Syntax highlighting for viewing ShExC code (EntitySchema pages)
Closed, ResolvedPublic5 Estimated Story Points

Description

As a Wikidata editor, I would like to be able to read ShEx more easily.

Problem:
We do not have syntax highlighting when viewing EntitySchema pages – just a dull, grey <pre>.

Note that this is distinct from syntax highlighting when editing the pages (T224962).

Example:
https://www.wikidata.org/wiki/EntitySchema:E10

Screenshots/mockups:
Current:


With Pygments:

Tech notes:
Pygments support for ShEx was merged recently-ish (pull request), but has not made it into any release yet. And once it’s released, we’ll presumably have to wait for Extension:SyntaxHighlight to pull in the new Pygments version.

Alternative option discussed in the bug triage hour: use a view-only mode of YASHE.

BDD
GIVEN a Entity Schema
WHEN in view mode
THEN the ShEx code has syntax highlighting

Acceptance criteria:

  • the view mode of an Entity Schema page has syntax highlighting for the ShEx code

Event Timeline

Color is nice but imho decoding the P and Q numbers is critical. See this comment for details https://phabricator.wikimedia.org/T224962#5789394

Pygments support for ShEx was merged recently-ish (pull request), but has not made it into any release yet. And once it’s released, we’ll presumably have to wait for Extension:SyntaxHighlight to pull in the new Pygments version.

Pygments support for ShEx was released in Pygments 2.5.0, and SyntaxHighlight now ships with 2.8.0, so this long ago ceased to be an issue.

So this should be fairly straightforward now, I assume – check if the SyntaxHighlight extension is loaded, and if yes, ask it to parse the equivalent of a <syntaxhighlight> tag with the ShExC code, and put the result into the HTML output. (Otherwise, keep doing whatever we’re doing at the moment, which I assume is just a plain <pre> element.)

Change 681169 had a related patch set uploaded (by Lucas Werkmeister; author: Lucas Werkmeister):

[mediawiki/extensions/EntitySchema@master] Use SyntaxHighlight if available

https://gerrit.wikimedia.org/r/681169

So this should be fairly straightforward now, I assume – check if the SyntaxHighlight extension is loaded, and if yes, ask it to parse the equivalent of a <syntaxhighlight> tag with the ShExC code, and put the result into the HTML output. (Otherwise, keep doing whatever we’re doing at the moment, which I assume is just a plain <pre> element.)

It did turn out to be fairly straightforward, at least in my opinion. (I suppose code reviewers are free to disagree.)

Though this doesn’t answer the question of whether we want pygments- or YASHE-based highlighting.

Change 681169 merged by jenkins-bot:

[mediawiki/extensions/EntitySchema@master] Use SyntaxHighlight if available

https://gerrit.wikimedia.org/r/681169

Addshore added a subscriber: Addshore.

Looking good on beta

Shouldn't this now be live on Wikidata? https://www.wikidata.org/wiki/EntitySchema:E10 this still has no syntax highlighting even after purging the cache.

Nevermind, it seems to work fine after purging the cache. No idea why it seemed to not work the first time.