Skip to content

Support for inline code blocks #695

@cubuspl42

Description

@cubuspl42

Introduction

Multiple existing apps (both native and web apps) have support for so-called inline code blocks. Just a few examples:

Slack

image

Discord

image

GitHub

Lorem ipsum dolor lorem ipsum

Inline code blocks can span across multiple lines if necessary.

image

Details

It's difficult or impossible to directly achieve the inline code block effect in React Native.

As I see it, there are three things in React Native that block us from achieving the discussed effect easily.

The line gap

Unlike CSS on the Web, if the inline text has a background color set, it fills the whole line. In CSS, it tightly wraps the inline text.

CSS:

image

React Native:

image

What's interesting, it seems there's no straightforward way to achieve the first effect on the second platform and vice-versa.

Such a feature exists in another W3 standard, TTML, and is named fillLineGap. It was added in 2017.

image

Figure 1 Illustrative rendition of the example immediately above with itts:fillLineGap="true" removed (left) or preserved (right). Blue lines have been added to show the before-edge and after-edge of each line area, which are coincident for successive line areas.

Also in 2017, there was some discussion about adding such a feature to CSS.

Doing just the inline-padding isn't the only place we want to do something with line areas.
... Another feature, fill-line-gap, says "draw background areas between lines".

It doesn't seem like much was done on this topic after that.

CSS behaves as if it had implicit fill-line-gap: false, and React Native behaves as if it had fill-line-gap: true.

Inline padding

In CSS, inline elements can have padding.

image

In React Native, the padding style property is ignored for inline text. As the current behavior is to fill the whole line height, it's not clear how padding should behave (or if it should be honored at all).

Borders

In CSS, inline elements can have borders, also with rounded corners.

image

The exact behavior is controlled by the box-decoration-break property.

In React Native, border styles for inline text are ignored.

Discussion points

I'd like to discuss what's necessary to support inline code blocks in React Native.

  • Is adding a boolean TTML-like fillLineGap style property to React Native reasonable?
    • The default value could be true (fill the whole gap), for backward compatibility
    • The false value would mean CSS-like behavior
  • If we supported fillLineGap, do we see any blockers from implementing these two inline text styles:
    • Padding
    • Borders

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions