react-native-htmlview icon indicating copy to clipboard operation
react-native-htmlview copied to clipboard

Space between two HTML tags

Open LouisJS opened this issue 6 years ago • 13 comments

I've noticed that if you put a space between two HTML tags such as a space, it is interpreted as a content and insert a new line.

For Example: (Focus on the breaking lines, not styling)

render() {
  const htmlContent = `<p>Hello</p> <p>There</p>`;
  return (
     <HTMLView
        value={htmlContent}
     />
  );
}

It will render something like : screen shot 2018-01-29 at 18 53 06 (Two breaking lines)

When the render should be like : screen shot 2018-01-29 at 18 53 22(One breaking line)

I think that in general, it's an issue about interpreting some content that are not between HTML Tags Take another HTML such as : const htmlContent = `<p>Hello</p>tot<p>There</p>`;

It renders like : screen shot 2018-01-29 at 18 58 51(One breaking line)

While it should be something like : screen shot 2018-01-29 at 18 59 03(Breaklines between each content)

LouisJS avatar Jan 29 '18 18:01 LouisJS

+1 same issue.

ducpt2 avatar Apr 04 '18 04:04 ducpt2

same here

miniofskidev avatar Apr 04 '18 11:04 miniofskidev

@miniofskidev This did the magic for me: data.replace(/(\r\n|\n|\r)/gm, "")

ducpt2 avatar Apr 04 '18 15:04 ducpt2

Hi there! I think the main issue with your HTML examples is that the parts in between tags are not contained in any parent tag. This library expects valid HTML, which means everything should be wrapped in a single top level tag. Could you check if the expected result is achieved by wrapping your data string in for example a <div></div>?

isilher avatar Apr 07 '18 09:04 isilher

Thanks @isilher, wrapping my content in a <div></div> did it for me.

donni106 avatar May 17 '18 13:05 donni106

@isilher Can you help me. How to remove line within p tag. Many thanks screen shot 2018-05-21 at 23 53 46

GodotVN avatar May 22 '18 01:05 GodotVN

@nguyenhuyhieu1995 there are probably new lines between you HTML tags, which normal browsers are ignoring but the HMTLView is not. I think you need a trim method, like @ducpt2 was mentioning, where rendering the HTMLView:

data.replace(/(\r\n|\n|\r)/gm, "")
<HTMLView
    value={`<div>${data.replace(/(\r\n|\n|\r)/gm, "")}</div>`}
    renderNode={renderNode}
/>

This is working for me.

donni106 avatar May 22 '18 09:05 donni106

Same issue here, .replace(/(\r\n|\n|\r)/gm, "") not work for me :(

screen shot 2018-07-14 at 23 58 36

joaom182 avatar Jul 15 '18 02:07 joaom182

Any update on this?

rochapablo avatar Jul 01 '19 16:07 rochapablo

+1

pacozaa avatar Jul 25 '19 01:07 pacozaa

Guys I end up did something like this and seems to work

which basically just combine @isilher and @ducpt2 together

pacozaa avatar Jul 25 '19 02:07 pacozaa

+1

danijelmaric avatar Nov 15 '19 10:11 danijelmaric

the @donni106 codes is work for me but is not working for image. Captura de Pantalla 2020-04-27 a la(s) 12 54 13

if i add the label p, i get line break on label a . what can i do?

Captura de Pantalla 2020-04-27 a la(s) 12 57 25

fedebais avatar Apr 27 '20 15:04 fedebais