Page MenuHomePhabricator

Provide basic source code editor features in VisualEditor SyntaxHighlight plugin
Closed, ResolvedPublic1 Estimated Story Points

Description

Author: suitongbowgn

Description:
Feature request:

A feature that supports insertion and simple editing of source code snippets in a general article. It may include a simple grammar checking mechanism which checks some fundamental grammatical errors such as having a { without closing it, having a () with a trailing period and nothing else, having solely a pair of brackets, etc.; an indentation correction tool which will perform indentation formatting on the codes; a beautify code tool which will reorganize code formatting, including indentation to make the code more reader-friendly in format.

Features:

  • Insert or edit a code block.
  • Basic IDE features (perhaps re-use WikiEditor/CodeEditor)
    • Syntax validation (matching quotes/parenthesis/braces etc.)
    • Follow indentation level when breaking lines.
    • Live grammar highlighting.

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:44 AM
bzimport added a project: SyntaxHighlight.
bzimport set Reference to bz47742.
  • This bug has been marked as a duplicate of bug 43133 ***

suitongbowgn wrote:

I believe that request is too broad and this one is more specific. (In reply to comment #1)

> *** This bug has been marked as a duplicate of bug 43133 ***

If anything, it seems like this request would build on top of that one. It's currently just not possible to edit almost anything else than plaintext in VisualEditor (and it's not just an interface issue, but a backend one as well).

I'm reopening and marking as dependent on that one, then. Feel free to adjust this :)

Making sure that arbitrary wikitext does not interact with other parts of the page is difficult. It is possible to enforce this for extension content, but generally not for arbitrary parts of a page.

Ah, it seems I misunderstood, sorry. I though you are talking about the source code *of the article itself*, and it appears like you meant source code in different languages, such as what's included in a <syntaxhighlight> tag.

Sorry and please disregard my comments :)

suitongbowgn wrote:

I understand that the rich text is just a presentation and I can see in article source that the formats are defined using a set of markups. What I'm proposing is a plugin/feature which will take care of write the markup(plaintext) for the user when editing code snippets, just like what VisualEditor is intended to do (in my opinion). In addition source code needs special formatting that is different from natural written human language, so that's why I think the feature should include automatic indentation and such.
For editing just a part of the text, I'm thinking of an interface similar to a pop-up window, obscuring parts of the editing window. Just like when you insert an image the editor will have a new window pop up asking image url, alt text, target, etc. When you click insert the editor will convert your choice in that pop-up window to the plaintext with tags and other markups, which will be visually reflected in the main WYSIWYG editor.

(In reply to comment #5)

Ah, it seems I misunderstood, sorry. I though you are talking about the
source
code *of the article itself*, and it appears like you meant source code in
different languages, such as what's included in a <syntaxhighlight> tag.

Sorry and please disregard my comments :)

(In reply to comment #4)

Making sure that arbitrary wikitext does not interact with other parts of the
page is difficult. It is possible to enforce this for extension content, but
generally not for arbitrary parts of a page.

Given that this is about desired enhancements to a VisualEditor plugin for the SyntaxHighlight extension - bug 43126 - moving this there and marking as a dependency.

suitongbowgn wrote:

In a nutshell it would be a major front-end JS work and will leave backend as-is as much as possible. I'm pretty sure that it will only utilize tags currently available and won't affect backend at all.(In reply to comment #6)

Just a note to say that Tongbo Sui has submitted a GSoC proposal related to this report: https://www.mediawiki.org/wiki/User:Beanixster

Good luck!

suitongbowgn wrote:

Somebody with the power could you change the bug status to assigned, and it was assigned to me.
Also anyone who is interested please feel free to give code review at the following patch.

Related URL: https://gerrit.wikimedia.org/r/68615 (Gerrit Change
I4adede9e05fd2236cee50ce03f597e8ff6b1914d)

Change 68615 had a related patch set uploaded by Jforrester:
Source code editing

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

If you don't have permission to do it yourself, it's probably because you don't have the 'editbugs' right. Hopefully, someone on this bug can give it you. If not, ask on IRC.

CCing Andre who can give you editbugs.

Tongbo: Re: your implmementation so far: Is the language spec something you've come up with yourself? Have you considered using an existing highlighter library, or at least basing your implementation on a existing language spec format (e.g. implementing GeSHi language specs in JS?)

suitongbowgn wrote:

The highlighter spec is ported from GeSHi's php into js. I didn't find spec for validator so I came up with myself.

(In reply to comment #15)

Tongbo: Re: your implmementation so far: Is the language spec something
you've
come up with yourself? Have you considered using an existing highlighter
library, or at least basing your implementation on a existing language spec
format (e.g. implementing GeSHi language specs in JS?)

(In reply to comment #15)

Have you considered using an existing highlighter
library, or at least basing your implementation on a existing language spec
format (e.g. implementing GeSHi language specs in JS?)

GeSHi is GPLv2+, whereas VisualEditor is MIT. So if any GeSHi code is reused, the authorship and licensing should be made clear.

suitongbowgn wrote:

For now no codes from GeSHi are directly reused. I just used them as reference for regex patterns. I said 'port' due to this fact.

(In reply to comment #17)

(In reply to comment #15)

Have you considered using an existing highlighter
library, or at least basing your implementation on a existing language spec
format (e.g. implementing GeSHi language specs in JS?)

GeSHi is GPLv2+, whereas VisualEditor is MIT. So if any GeSHi code is
reused,
the authorship and licensing should be made clear.

GSoC "soft pencils down" date was yesterday and all coding must stop on 23 September. Has this project been completed?

suitongbowgn wrote:

Yes.

(In reply to comment #19)

GSoC "soft pencils down" date was yesterday and all coding must stop on 23
September. Has this project been completed?

Marking this also as fixed by gerrit 68615 - congratulations again!

Re-opening as this is now unmerged.

Change 114529 had a related patch set uploaded by Jforrester:
[WIP] Add VisualEditor support

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

Jdforrester-WMF lowered the priority of this task from Medium to Lowest.May 29 2015, 2:28 PM
Jdforrester-WMF removed a project: Patch-For-Review.
Jdforrester-WMF set Security to None.
Krinkle renamed this task from Support simple source code editing tools for the VisualEditor plugin for the SyntaxHighlight extension to Provide basic source code editor features in VisualEditor SyntaxHighlight plugin.Jun 26 2015, 8:41 AM
Krinkle updated the task description. (Show Details)

I think the best approach would be to convert the editor to a dialog and drop in CodeEditor's existing code editor (Ace), or some equivalent (CodeMirror).

I think the best approach would be to convert the editor to a dialog and drop in CodeEditor's existing code editor (Ace), or some equivalent (CodeMirror).

That could work.

A first step would be putting making an RL module for Ace in core. Each language is a separate JS file so we'd want submodules for each, like we used to do with GeSHi.

Change 247474 had a related patch set uploaded (by Esanders):
WIP Use Ace editor when available

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

Change 247851 had a related patch set uploaded (by Esanders):
Introduce Ace editor widget

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

Jdforrester-WMF assigned this task to Esanders.
Jdforrester-WMF removed a project: Patch-For-Review.
Jdforrester-WMF edited a custom field.