question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request: Lists (<ol> and <ul>) should align/indent properly

See original GitHub issue

Currently, react-native-htmlview treats bullets and numbers in ordered and unordered lists as simply additions to the beginning of list item strings (enclosed in <li></li> tags). This results in improper alignment of multiline word-wrapped list items.

This is a request for properly left-aligned lists in this repo. In the meantime, are there any existing forks that have addressed this list alignment issue?

Example desired alignment: image

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:9
  • Comments:12

github_iconTop GitHub Comments

8reactions
donni106commented, May 17, 2018

I have played around a bit with some possibilities. With the following renderNode method I can achieve an usable result @koesbong @sunweiyang @dann1609:

  renderNode(node, index, siblings, parent, defaultRenderer) {
    if (node.name == 'li') {
      return (
        <View key={index} style={{ marginTop: index === 0 ? 10 : 0 }}>
          <View style={{ flexDirection: 'row' }}>
            <View style={{ flexDirection: 'column', marginLeft: 20, width: 20 }}>
              <Text>{'\u2022'}</Text>
            </View>
            <View style={{ flexDirection: 'column', width: '90%' }}>
              <Text>{defaultRenderer(node.children, parent)}</Text>
            </View>
          </View>
        </View>
      );
    } else if (node.name == 'ul') {
      return (
        <View>
          {defaultRenderer(node.children, parent)}
        </View>
      );
    }
  }

Before:

bildschirmfoto 2018-05-17 um 16 20 36

After:

bildschirmfoto 2018-05-17 um 16 19 47

I don’t know why, but the list is endless growing without the second part:

 else if (node.name == 'ul') {
      return (
        <View>
          {defaultRenderer(node.children, parent)}
        </View>
      );
    }

Any ideas what is happening there @isilher and @ everybody?

2reactions
koesbongcommented, Apr 12, 2018

@isilher I am also having the same issue as @dann1609 where I am getting an Invariant Violation: Objects are not valid as a React child error and this is on iOS.

Here is my code:

function renderNode(node, index, siblings, parent, defaultRenderer) {
  // TODO: how do I get the number for an ordered list?
  let bullet;

  if (node && node.name === 'li') {
    bullet = '\u2022';

    if (parent && parent.name === 'ol') {
      bullet = index;
    } 
  }

  return (
    <View style={styles.bulletedTextContainer}>
      <Text>{bullet}</Text>
      <Text style={styles.contentStyle}>{node.children}</Text>
    </View>
  )
}

const styles = {
  p: {
    fontSize: 15,
    marginBottom: 10
  },
  ul: {
    marginBottom: 10
  },
  strong: {
    fontWeight: '600'
  },
  bulletedTextContainer: {
    flexDirection: 'row'
  },
  contentStyle: {
    flex: 1,
    paddingLeft: 5
  }
};

Is there something I am missing?

Read more comments on GitHub >

github_iconTop Results From Across the Web

proper indenting for ordered lists in html - css - Stack Overflow
Actually, the solution is pretty simple, just set ol {list-style-position: inside;}. And your numbers should "align to the left" like you ...
Read more >
Consistent list indentation - CSS: Cascading Style Sheets | MDN
In Internet Explorer and Opera, the lists are indented by setting a left margin of 40 pixels on the <ul> element.
Read more >
What is the way to keep list of elements straight in HTML file
Lists are automatically indented, by default & it is important to keep the list aligned according to the display preferences. In order to...
Read more >
The Ultimate Guide to Bullet Points in HTML Email - Litmus
Adding bulleted lists in emails can be trickier than you think. ... </ li >. </ ul >. < ol style = "margin:0;...
Read more >
Styling lists and links - W3C Wiki
Figure 7: Bullets are positioned to the left of the text. So, to align the bullets to the left you can now set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found