Skip to content
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

Numbered list and text not aligning when rendering #592

Open
7 of 15 tasks
rikinshah23 opened this issue Nov 1, 2022 · 8 comments
Open
7 of 15 tasks

Numbered list and text not aligning when rendering #592

rikinshah23 opened this issue Nov 1, 2022 · 8 comments
Labels
bug Crush'em all.

Comments

@rikinshah23
Copy link

Decision Table

  • My issue does not look like “The HTML attribute 'xxx' is ignored” (unless we claim support for it)
  • My issue does not look like “The HTML element <yyy> is not rendered”

Good Faith Declaration

Description

Numbered list is always showing like this for me. Is there a prop or an example I can use to add some padding to the text may be?

image

React Native Information

"react-native": "0.64.2",

RNRH Version

6.3.4

Tested Platforms

  • Android
  • iOS
  • Web
  • MacOS
  • Windows

Reproduction Platforms

  • Android
  • iOS
  • Web
  • MacOS
  • Windows

Minimal, Reproducible Example

export function htmlViewer(props) {
  return (
    <HTML
      enableExperimentalBRCollapsing={true}
      tagsStyles={{
        span: theme.textAlignLeft,
        p: theme.textAlignLeft,
      }}
      source={{ html: props.source }}
      onLinkPress={props?.linkpressed}
    />
  );
}

Additional Notes

No response

@rikinshah23 rikinshah23 added the bug Crush'em all. label Nov 1, 2022
@jsamr
Copy link
Collaborator

jsamr commented Nov 1, 2022

@rikinshah23 please provide a reproducible example; this example relies on unknown props.

@codesafdar
Copy link

import React from 'react'
import RenderHtml from 'react-native-render-html'
import { myColors } from '../../theme/globals'

const tagsStyles = {
body: {
color: myColors.darkBlue700
},
p: {
margin: '0px',
padding: '0px',
lineHeight: '20px',
fontSize: '14px',
fontWeight: '400'
},
ul: {
marginTop: '0px',
marginBottom: '0px',
paddingTop: '0px',
paddingBottom: '0px',
display: 'flex',
flexDirection: 'column',
alignItems: 'baseline'
},
li: {
display: 'inline-block',
lineHeight: '20px',
fontWeight: '400',
paddingBottom: '0px',
margin: '0px'
}
}

const classesStyles = {
'ql-indent-1': {
marginLeft: '22px'
},
'ql-indent-2': {
marginLeft: '44px'
},
'ql-indent-3': {
marginLeft: '66px'
},
'ql-indent-4': {
marginLeft: '88px'
},
'ql-indent-5': {
marginLeft: '110px'
},
'ql-indent-6': {
marginLeft: '132px'
}
}
const ShowHtml = ({ data }) => {
return (
<>
<RenderHtml
source={{
html: data
}}
tagsStyles={tagsStyles}
enableExperimentalBRCollapsing
classesStyles={classesStyles}
/>
</>
)
}

export default ShowHtml
Screenshot 2023-02-27 at 6 48 40 PM

List bullets are not moving with text, please help me @jsamr

@twocs
Copy link

twocs commented Apr 18, 2023

Here's a minimal example. The baseline of the container does not line up with the baseline of the numbering.
https://snack.expo.dev/@tom.a/numbered-list-and-text-not-aligning-when-rendering

Seems that no style changes in tagsStyles can really affect the numbering, which is not intuitive or well documented (opinion).

I was able to fix the li numbering to get the lineHeight css property only by using "renderersProps". So in the example, you would need to do all the changes to the :

const renderersProps = {
    ul: {
      markerTextStyle: {
        lineHeight: '21px',
      },
    },
  };
  
<RenderHtml
  source={{html: data}}
  tagsStyles={tagsStyles}
  enableExperimentalBRCollapsing
  classesStyles={classesStyles}
  renderersProps={renderersProps}
/>

@twocs
Copy link

twocs commented Apr 18, 2023

This is my complete minimal sample, currently available at https://snack.expo.dev/@tom.a/numbered-list-and-text-not-aligning-when-rendering

import React from 'react';
import RenderHtml from 'react-native-render-html';

export default function App() {
  const tagsStyles = {
    p: {
      margin: '0px',
      lineHeight: '26px',
    },
    ol: {
//      lineHeight: '26px',
    },
    li: {
//      lineHeight: '26px',
    }
  };

  const renderersProps = {
    ol: {
      markerTextStyle: {
        lineHeight: '26px',
      },
    },
  };

  const source = {
    html: `<ol>
    <li>
      <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
    </li>
    <li>
      <p>Aliquam tincidunt mauris eu risus.</p>
    </li>
    <li>
      <p>Vestibulum auctor dapibus neque.</p>
    </li>
    <li>
      <p>Nunc dignissim risus id metus.</p>
    </li>
  </ol>`,
  };

  return (
    <>
      <RenderHtml
        source={source}
        tagsStyles={tagsStyles}
      />

      <RenderHtml
        source={source}
        tagsStyles={tagsStyles}
        renderersProps={renderersProps}
      />
    </>
  );
}

I left the commented out ol/li styling because they don't do anything to the numbers even though intuitively that's what I would try to do to change their formatting. Unfortunately some editors (e.g. Tiptap) just add <p> tags even inside <li> tags, and that's causing the issue because the numbering doesn't align with the baseline of the text but with the top of the margin.

@ntienanh
Copy link

you can try p: { marginVertical: 0 } at tagsStyles.

@codesafdar
Copy link

codesafdar commented May 27, 2023 via email

@oliuradu
Copy link

import React from 'react' import RenderHtml from 'react-native-render-html' import { myColors } from '../../theme/globals'

const tagsStyles = { body: { color: myColors.darkBlue700 }, p: { margin: '0px', padding: '0px', lineHeight: '20px', fontSize: '14px', fontWeight: '400' }, ul: { marginTop: '0px', marginBottom: '0px', paddingTop: '0px', paddingBottom: '0px', display: 'flex', flexDirection: 'column', alignItems: 'baseline' }, li: { display: 'inline-block', lineHeight: '20px', fontWeight: '400', paddingBottom: '0px', margin: '0px' } }

const classesStyles = { 'ql-indent-1': { marginLeft: '22px' }, 'ql-indent-2': { marginLeft: '44px' }, 'ql-indent-3': { marginLeft: '66px' }, 'ql-indent-4': { marginLeft: '88px' }, 'ql-indent-5': { marginLeft: '110px' }, 'ql-indent-6': { marginLeft: '132px' } } const ShowHtml = ({ data }) => { return ( <> <RenderHtml source={{ html: data }} tagsStyles={tagsStyles} enableExperimentalBRCollapsing classesStyles={classesStyles} /> </> ) }

export default ShowHtml Screenshot 2023-02-27 at 6 48 40 PM

List bullets are not moving with text, please help me @jsamr

i have the same problem, do you know any solution? thanks

@olegmilan
Copy link

Here's a minimal example. The baseline of the container does not line up with the baseline of the numbering. https://snack.expo.dev/@tom.a/numbered-list-and-text-not-aligning-when-rendering

Seems that no style changes in tagsStyles can really affect the numbering, which is not intuitive or well documented (opinion).

I was able to fix the li numbering to get the lineHeight css property only by using "renderersProps". So in the example, you would need to do all the changes to the :

const renderersProps = {
    ul: {
      markerTextStyle: {
        lineHeight: '21px',
      },
    },
  };
  
<RenderHtml
  source={{html: data}}
  tagsStyles={tagsStyles}
  enableExperimentalBRCollapsing
  classesStyles={classesStyles}
  renderersProps={renderersProps}
/>

Your solution works perfectly fine, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Crush'em all.
Projects
None yet
Development

No branches or pull requests

7 participants