Skip to content

Show highlighting in code blocks #191

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

Closed
gnprice opened this issue Jun 14, 2023 · 0 comments · Fixed by #242
Closed

Show highlighting in code blocks #191

gnprice opened this issue Jun 14, 2023 · 0 comments · Fixed by #242
Labels
a-content Parsing and rendering Zulip HTML content, notably message contents
Milestone

Comments

@gnprice
Copy link
Member

gnprice commented Jun 14, 2023

When a code block is marked with a language, the Zulip server will try to apply code highlighting to it for that language. This highlighting is expressed by breaking the text into many short spans, each applying a CSS class from Pygments. This is then shown in Zulip web and zulip-mobile by providing CSS rules for those classes.

Currently we ignore the highlighting information and just show the text. We should instead parse the highlighting information and use it to show the highlighting.

In widgets/content.dart, this basically means transcribing the information that's in web's pygments.css into some Dart code that produces Flutter widgets. There's no magic bullet for this, but fortunately that information is not complicated.

  • There are 62 such classes. Each rule applies to one class. (There is also a pair of rules setting background-color for the whole code block, for 64 total rules in the file.)

  • The contents of the rules are various combinations of:

    • font-weight: bold;
    • font-style: italic;
    • color: hsl(…);
    • background-color: hsl(…);
    • border: …;

    So all of those should translate very simply to Flutter widgets.

@gnprice gnprice added the a-content Parsing and rendering Zulip HTML content, notably message contents label Jun 14, 2023
@gnprice gnprice added this to the Beta milestone Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-content Parsing and rendering Zulip HTML content, notably message contents
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant