Skip to content

STACK: add line numbers/ highlight to Question and Feedback variables#1790

Open
vuvanhieu143 wants to merge 2 commits into
maths:devfrom
vuvanhieu143:wip985752
Open

STACK: add line numbers/ highlight to Question and Feedback variables#1790
vuvanhieu143 wants to merge 2 commits into
maths:devfrom
vuvanhieu143:wip985752

Conversation

@vuvanhieu143

Copy link
Copy Markdown
Contributor

Hi @sangwinc ,

As Chris Nelson mentioned in his email, we're looking to add line numbers and syntax highlighting for STACK questions.

I've implemented this using the Ace Editor library: https://ace.c9.io/#nav=higlighter

Since Ace doesn't provide syntax highlighting for STACK/Maxima out of the box, I wrote a custom highlighting mode for it. I'm not familiar with every aspect of the STACK language, so my implementation may not cover all cases. If you notice anything that could be improved or any syntax that isn't highlighted correctly, please let me know and I'll update the rules.

This is what the new UI looks like. At the moment, I've only enabled it for the Question variables and Feedback variables fields. The feature is enabled by default, but if we'd prefer to make it optional, I can add an admin setting to turn it on or off.

image image

@sangwinc sangwinc changed the base branch from master to dev July 1, 2026 09:02
@sangwinc

sangwinc commented Jul 1, 2026

Copy link
Copy Markdown
Member

Thanks @vuvanhieu143 that's really very helpful indeed. This has been on our wishlist for sometime, and I'm very grateful to you for sorting this out. For sure, we can improve the support for Maxima syntax.

I've changed the base to "dev" so this can be staged for the next release. This is timely as we just released a new version (4.13.0) and are agreeing priorities for development for the next cycle. This feature was on the list. We'll review, test and I hope accept this.

@sangwinc sangwinc requested a review from EJMFarrow July 1, 2026 09:05
@sangwinc sangwinc added this to the 4.14.0 milestone Jul 1, 2026
@Mat-Ge

Mat-Ge commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

There is a VS Code extension that does a great job of highlighting Maxima's syntax. Perhaps some of this extension's highlighting rules could also be useful here for making Maxima easier to read.
https://github.com/nicoewok/maxima-syntax-highlighting

@EJMFarrow EJMFarrow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @vuvanhieu143 . Thanks so much for this. Looks very useful. I think it needs a little tidying up before merging.

Comment thread amd/src/ace_editor.js Outdated
Comment thread ace/ace.js
Comment thread edit_stack_form.php
@@ -217,6 +218,13 @@ protected function definition() {
if ($closebeforebuttonarr !== false) {
unset($mform->defaultRenderer()->_stopFieldsetElements[$closebeforebuttonarr]);
}
// Disable ace editor when running behat.
if (!defined('BEHAT_SITE_RUNNING')) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires more explanation but it would be better if the editor was not disabled when running Behat.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @EJMFarrow , The reason I disabled it for Behat is that the existing Behat tests can't be reused when the Ace Editor is rendered, unless we update the tests with custom Behat steps or use CSS-based workarounds.

Since we can't meaningfully test the Ace Editor itself with Behat, I don't think there's much value in enabling it during Behat runs.

Does that make sense?

@vuvanhieu143

Copy link
Copy Markdown
Contributor Author

hanks for the suggestions, @Mat-Ge. I've updated the Maxima syntax highlighting rules and added unit tests to cover the changes.

@EJMFarrow, I've switched the implementation to use RequireJS and removed the unrelated JavaScript files that were no longer needed. I've also explained why I chose not to render the Ace Editor when running Behat tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants