-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse, validate, and highlight code blocks #574
Comments
Well for start I would not semantically highlight the code - just make it bold or italic or something like that - simple attribute of the Highlighting code semantically would require highlighting individual words like in #545, so that is harder even without the extra work of matching parsed elements to code spans and highlighting those. |
Ah, that makes sense, yes, that should be possible. |
Turns out there is a library for this: In particular, this function to which we can pass tokenized lines: renderRawSource
:: (T.Text -> Widget n) -- just put txt function here
-> [Sky.SourceLine] -- [SourceLine] == [[Token]] == [[(TokenType, Text)]]
-> Widget n So we can use our already processed terms and just label them. |
Well, it also needs to work with our pretty printing. 🤔 The way to do that seems to be to:
|
Since I think the implementation is clear now, I will do semantic highlighting too. Notes:
|
I looked into this and ended up quite confused. 😕 (See WIP in 98ee109) Adding annotations is simple enough, but there are more steps to the
|
@byorgey if you have some idea how to approach this, I would be glad to hear it. 😅 The good news is that once we figure this out, we should get nicely coloured code widgets everywhere. The bad news is that highlighting is more work than I expected and I will not implement it in #1106. I will probably have to render inline code simply and blocks can get properly highlighted later. @byorgey so I will probably rename this issue back to "Highlight code blocks". 😅 |
Makes sense. I don't have any particular ideas off the top of my head. If you wanted to schedule a meeting sometime to think about it together I'd be happy to do that. |
* use CommonMark to parse simple markdown AST parametrised on inline/block code * validate swarm code (`Document Text -> Document Syntax`) * update descriptions to use markdown with following conventions: - `move` - valid swarm code (the easy to write default) - `wedge`{=entity} - for swarm entities - `unit`{=type} - for swarm types - `require <a> <b>`{=snippet} - raw snippets for invalid code - **Alt-G** - bold for keyboard shortcuts - highlight code in brick widgets - closes #309 - closes #545 - precedes #574 - precedes #1406 - precedes #1407
As a quick improvement, we should be able to parse markdown code blocks and highlight those in the game UI.
If the first and last line of
Text
is ```, the lines in the middle should be (parsed as swarm code and) highlighted.Before:
After:
As a bonus, we could easily check that the code parses in the CI. #309
The text was updated successfully, but these errors were encountered: