2

[email protected]

Is there a way to force all text that gets rendered in any element to have a default font size?

I am displaying HTML from a web editor and don't have control over how the HTML is rendered. For instance, the text can be in a div, span, or nested inside a span and a b tag.

<div>
    <div>text in div</div>
    <span>text in span</span>
    <span><b>text in bold</b></span>
</div>

I know you can use renders like this, but I cannot do this with all divs.

const renderers = {
  h1: (html, children, styles, {key}) => <Text key={key} style={styles.h1}>{children}</Text>,
};

<HTML
  html={html}
  renderers={renderers}
/>

1 Answer 1

2

Try the below solution:

const defaultTextProps = {
   style: {
    fontSize: 16, // Your default font size
   },
 };


<HTML
   html={htmlContent}
   defaultTextProps={defaultTextProps} //Apply default styles to all text elements
/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.