Skip to content
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

Consider switching to the syntax highlighting library in egui_extras #13

Closed
emilk opened this issue Sep 14, 2023 · 6 comments
Closed

Consider switching to the syntax highlighting library in egui_extras #13

emilk opened this issue Sep 14, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@emilk
Copy link
Contributor

emilk commented Sep 14, 2023

I recently moved the syntax highlighting code I had in egui_demo_lib to egui_extras: emilk/egui#3333

Importantly, it has a simple fallback that works even without the syntect crate (which has a tendency to bloat .wasm files quite a bit).

egui_extras::syntax_highlighing does not yet support everything that egui_commonmark offers, in particular it doesn't yet have add_syntax_from_folder, add_syntax_from_str, add_syntax_themes_from_folder, and add_syntax_theme_from_bytes.

@lampsitter lampsitter added the enhancement New feature or request label Sep 14, 2023
@lampsitter
Copy link
Owner

While being able to have fallback highlighting is nice, I don't like losing the more granular control I'm able to have by using syntect directly.

E.g: Using syntects custom cursor colour and selection colour.

@emilk
Copy link
Contributor Author

emilk commented Sep 15, 2023

Of course, I propose we expose that in egui_extras::syntax_highlighing somehow, in an interface that is agnostic to the implementation (syntect or fallback).

emilk added a commit to rerun-io/rerun that referenced this issue Sep 18, 2023
### What
```rs
    rec.log(
        "markdown",
        &TextDocument::new(
            "# Hello\n\
             Markdown with `code`!\n\
             \n\
             A random image:\n\
             \n\
             ![A random image](https://picsum.photos/640/480)",
        )
        .with_media_type(MediaType::markdown()),
    )?;
```

<img width="809" alt="image"
src="https://github.com/rerun-io/rerun/assets/1148717/d4cbf9a3-e3c9-4aba-be35-8921dae001e7">

This will let us add nice documentation explaining our examples.

### Not yet supported
* Syntax highlighting of code blocks
* `egui_commomark` uses `syntect` which is too big of a dependency imho,
see lampsitter/egui_commonmark#13
* Embedding references to images in the data store
* We should support something like `![](entity://my/image/entity)` where
`my/image/entity` is the entity path to an image you have logged.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3343) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/3343)
- [Docs
preview](https://rerun.io/preview/8b743c5708382aef1841a364442762a2abc80db3/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/8b743c5708382aef1841a364442762a2abc80db3/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
@lampsitter
Copy link
Owner

I don't think that it is possible to add a backend agnostic highlighter. add_syntax_themes_from_folder uses .tmTheme files, which are extremely syntect/sublime specific. I think it would be better to have a separate "feature" for using a crate with more primitive highlighting directly. Unfortunately I can't find such a crate...

@emilk
Copy link
Contributor Author

emilk commented Sep 18, 2023

I would suggest that add_syntax_themes_from_folder would only exist when compiling with the syntect backend, or that it would return an error when the feature was off.

@lampsitter
Copy link
Owner

I have added egui_extras as a fallback when the syntax_highlighting feature is disabled, which should have the desired effect.

@emilk
Copy link
Contributor Author

emilk commented Sep 21, 2023

That's great - thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants