Skip to content

Commit

Permalink
Upgrade to CodeMirror 6.
Browse files Browse the repository at this point in the history
Some features of this change are improved syntax highlighting and
the addition of autocompletion.  To see available autocompletions at the
current cursor location, you can type Ctrl-Space.  In many cases,
autocompletions are offered automatically when certain things have been
typed.

CodeMirror 6 can not be used via script tags.  So a PGProblemEditor
package has been created for this.  The repository for that is
https://github.com/openwebwork/pg-problem-editor.  An initial package
has been published in npm at
https://www.npmjs.com/package/@openwebwork/pg-codemirror-editor. The
real work is done in the codemirror-lang-pg package that adds support
for the PG language in CodeMirror 6.  The repository for that package is
https://github.com/openwebwork/codemirror-lang-pg, and the npm package
at https://www.npmjs.com/package/@openwebwork/codemirror-lang-pg.

The pg-problem-editor package is designed so that it can be used by
webwork2, the standalone renderer, and possible others that want a PG
problem editor.  It may need a few tweaks to make it work for webwork3
in the future, but should also work for that.

The codemirror-lang-pg package consists of a base PG parser that is
largely derived from the codemirror-lang-perl package (at
https://github.com/drgrice1/codemirror-lang-perl and
https://www.npmjs.com/package/codemirror-lang-perl) with a modifications
specific to the perl available in a PG problem.  The main differences
are that its escape sequence is ~~, much of what can not be used in
the safe compartment has been stripped out, and there are special blocks
for PGML, PG text, and LaTeX image code.  Then there are two other
parsers.  Those are the PGML and PG text parsers.  Those parsers run on
the contents of the PGML and PG text blocks found by the base PG parser.
Note that the PGML parser is actually a javascript implementation of the
parser in PGML.pl with some modifications to track position and things
needed to associate the parsed tree with the original code.

Note that the configuration of theme, keymaps, and such are now part of
the pg-codemirror-editor, and are shown in a panel of the editor
instead of below as before.

Emacs and Vim keymaps are available, but at this point there is not a
Sublime keymap for CodeMirror 6.

The themes that are available include a basic default theme (that is
part of the pg-problem-editor package and just adds some syntax
highlighting that is missing from the CodeMirror 6 default), the OndDark
theme that is the only other theme provided by the CodeMirror 6
developers directly, the themes in the thememirror package, and the
themes from https://github.com/craftzdog/cm6-themes which are in several
separate npm packages.  Note that both thememirror and
craftzdog/cm6-themes provide a solarized light theme, and that is why
there are two of those.  They are slightly different though.

I am sure that there is a lot more work to do on this, and there are
other things available with CodeMirror 6 that could probably be
implemented.  In any case, this is a good start.
  • Loading branch information
drgrice1 committed Nov 11, 2024
1 parent 22b6dbf commit f2897ae
Show file tree
Hide file tree
Showing 15 changed files with 960 additions and 2,207 deletions.
1,567 changes: 0 additions & 1,567 deletions htdocs/js/PGCodeMirror/PG.js

This file was deleted.

287 changes: 0 additions & 287 deletions htdocs/js/PGCodeMirror/comment.js

This file was deleted.

Loading

0 comments on commit f2897ae

Please sign in to comment.