Open abalkin opened 9 years ago
That's correct. Only cell magics trigger language switching. There isn't any mode switching for lines. Disabling Python highlighting on line magics should probably be added to the IPython codemirror mode.
The issue is the same on the "server" side. This should probably be handled in the IPythonLexer.
The best solution would be to allow line/cell magic objects to provide the necessary pieces such as a pygments lexer and a codemirror mode.
Possibly, but the rendering code doesn't load the magic commands, so I'm not sure how the information would be conveyed.
I was thinking of just providing the name of pygments lexer which in most cases will be the same as the matching cm mode, but for better interoperability the mime types are probably better. A magic object can define a mimetypes list and other IPython components may pick the best match.
Both pygments and codemirror specify mimetypes, but since those are non-standard they don't always match. For example, pygments defines bash lexer mimetypes as
mimetypes = ['application/x-sh', 'application/x-shellscript']
but codemirror uses text/x-sh. The shell magic can specify all three and highlighters will pick the one they understand.
Interestingly, I was only able to find one IANA-registered MIME type for a computer language - application/sql for SQL. And neither pygments nor cm uses it.
Pygments:
mimetypes = ['text/x-sql']
Codemirror: text/x-sql, text/x-mysql, text/x-mariadb, text/x-cassandra, text/x-plsql, text/x-mssql, text/x-hive.
Yep, but the code rendering the notebook doesn't load the magic functions, so we'd have to come up with some way to convey the highlighting information to the frontend and store it in the notebook.
I am new to IPython development, so I would like to proceed in baby steps:
If the current behaviour isn't desired, I'm not sure it's worth writing tests for it.
Hopefully it should be fairly easy to get no highlighting in pygments and codemirror for line magic arguments.
Getting the magics' information to the lexer is probably rather more than a baby step - that bit would require a certain amount of large scale architecture design.
@ellisonbg Are there plans to support syntax highlights for line magics?
IPython notebook knows how to switch language for (some) cell magic directives, but line magics and the ! directive seem to be completely ignored.