Skip to content

Show highlighting in code blocks #191

Closed
@gnprice

Description

@gnprice

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-contentParsing and rendering Zulip HTML content, notably message contents

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions