[Feature request] Vertical spacing (margins) for headings and lists in htmlStyle
Maintainers usually reply within 4 days
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 20/100
Research direction
The request covers htmlStyle rendering in EnrichedTextInput and EnrichedText on iOS, Android, and web; an open linked pull request (#838) is already addressing it. For context, compare the sibling library's ParagraphStyleUtils.m and MarginBottomSpan.kt, linked in the issue, and review the proposed examples and platform behaviors. Done means block margins work across platforms while leaving HTML, plain text, and selection offsets unchanged.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
This is the separate request @kacperzolkiewski asked for in #259: a way to add vertical space around block elements.
We render the same HTML with EnrichedTextInput on web and on native. On web we style it with CSS: margin: 18px 0 8px on h1–h3, margin: 6px 0 on ul/ol, and line-height: 1.55. On native we can match the line height with the lineHeight style, and soon on EnrichedText too (#724). But we can't add space above or below headings or lists. HeadingStyle only has fontSize and bold, on main as well.
As a result, headings sit flush against the paragraph before and after them. Long documents read as one dense block on phones, while the same document looks well spaced on web. Our users reported exactly this.
Describe the solution you'd like
Per-block vertical spacing in htmlStyle, for both EnrichedTextInput and EnrichedText:
htmlStyle={{
h2: { fontSize: 20, bold: true, marginTop: 18, marginBottom: 8 },
ul: { gapWidth: 8, marginLeft: 20, marginTop: 6, marginBottom: 6 },
}}
- iOS:
paragraphSpacingBeforeon a block's first paragraph andparagraphSpacingon its last. - Android: a span that adds top and bottom space.
- Web: CSS margins.
The spacing should be visual only, with no change to the HTML, the plain text or selection offsets. #470 (paragraphSpacing for checkbox lists) is a similar idea for one block type.
The sibling library react-native-enriched-markdown already ships this API in its renderer: markdownStyle.h1–h6 take marginTop and marginBottom (docs).
- iOS:
paragraphSpacing(ParagraphStyleUtils.m). - Android: a
LineHeightSpan(MarginBottomSpan.kt). - Edges: it collapses adjacent margins and drops the last block's bottom margin (
allowTrailingMargin).
Matching those prop names and behaviours here would keep the two libraries consistent. One difference for an editor: the space above a block should come from paragraphSpacingBefore rather than an inserted spacer character, so the text and offsets stay unchanged.
Describe alternatives you've considered
- Inserting
<br>around headings before rendering: the editor then saves those<br>s back into the document. - A large
lineHeight: it spreads out every line, not just the gaps between blocks (as noted in #259).
Additional context
react-native-enriched-html 1.1.1, React Native 0.86.3, Expo SDK 57, tested on the iOS 18.6 simulator.
- Dominant language
- C
- Stars
- 1.4k
- Forks
- 77
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 24
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from software-mansion/react-native-enriched-html
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
software-mansion/react-native-enriched-html#862 ·
Maintainers usually reply within 4 days
-
Typing or autocorrecting inside a mention strips it to plain textPossibly taken @JaydeepAgravat claimed this 8 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 70/100
software-mansion/react-native-enriched-html#855 · 8 comments · 1 reaction ·
Maintainers usually reply within 4 days
-
[iOS] Tags not parsed on iOS below a certain string lengthPossibly taken @hejsztynx claimed this 33 days ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 42/100
software-mansion/react-native-enriched-html#811 · 3 comments ·
Maintainers usually reply within 4 days
-
[iOS, Android, Web] Return on an empty list item adds another item instead of ending the listPossibly taken @szydlovsky claimed this 7 days ago. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 50/100
software-mansion/react-native-enriched-html#810 · 1 comment ·
Maintainers usually reply within 4 days
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
software-mansion/react-native-enriched-html#803 ·
Maintainers usually reply within 4 days
All issues in software-mansion/react-native-enriched-html
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
libretro/parallel-n64#858 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Mbed-TLS/TF-PSA-Crypto#984 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
enhancement help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100