Giter VIP home page Giter VIP logo

Comments (14)

tiendq avatar tiendq commented on June 10, 2024 7

My issue is a big white space following p tags, and marginBottom has no effect 👎

from react-native-htmlview.

richchurcher avatar richchurcher commented on June 10, 2024 5

@zarcode In a multiline string (denoted by backticks `<p>...</p>`) newlines are preserved. I suspect this is what you're seeing. Compare the behaviour of the following:

import React from 'react';
import HTMLView from 'react-native-htmlview'

export default class App extends React.Component {
  render() {
    const htmlContent = `<p>Hello this text is <strong>Bold</strong> and this one is <em>italic</em></p><blockquote><p>quote</p></blockquote><ul><li>item1</li><li>item2</li><li>item3</li></ul>`
    return (
      <HTMLView value={htmlContent} />
    )
  }
}

sample

Presumably the content you're displaying will be arriving in a non-preformatted way, so you should be ok. The spacing between blockquote and paragraph is a little wonky though.

from react-native-htmlview.

gregblass avatar gregblass commented on June 10, 2024 1

I see why now. Its wrapping the text component that you're attempting to apply a style to with another text component, which overrides the margin.

from react-native-htmlview.

sospedra avatar sospedra commented on June 10, 2024 1

@richchurcher bingo!
I suggest to add a trim when sharing the value prop

<HTMLView value={myContent.trim()} />

from react-native-htmlview.

markusguenther avatar markusguenther commented on June 10, 2024

I don't have the same issues like you. But I had whitespaces after the
tags and the htmlview package creates a new Text Component after a break but does not remove the whitespace.

So the new Text element starts with a whitespace.

    function removeTailingWhiteSpaces(text) {
        return text.replace(/\s*(<br \/> | <br>)\s*/gi, '<br\>')
    }

This is my current hack for that. But it would better to have this in the package.

Maybe you have similar problems.

from react-native-htmlview.

gregblass avatar gregblass commented on June 10, 2024

IMO, biggest issue of the library. Can't control bottom margin on p tags.

from react-native-htmlview.

gregblass avatar gregblass commented on June 10, 2024

This is driving me nuts. I've forked this repo and modified to to a barebones version, and for some reason rendering Text elements inside the parent View component just ignores margins. Other styling works (like colors), but for some bewildering reason, it ignores margins on text elements.

from react-native-htmlview.

tiendq avatar tiendq commented on June 10, 2024

@gregblass did you mean <Text><Text></Text></Text> and we're trying to style the inner Text? :(

from react-native-htmlview.

WorldWideWebb avatar WorldWideWebb commented on June 10, 2024

Is there a fix for that?

from react-native-htmlview.

gregblass avatar gregblass commented on June 10, 2024

@tiendq Yep, exactly.

@WorldWideWebb No. I modified this library pretty heavily for my own project. The double Text are gonna be hard coded in there because of the way it was written. I needed control over my paragraph margins and wanted to add stuff like unordered list items, etc.

If I remember correctly, every component gets wrapped in a parent Text component, which is what is causing the margins to be ignored.

from react-native-htmlview.

gregblass avatar gregblass commented on June 10, 2024

I believe this was the culprit: https://github.com/jsdf/react-native-htmlview/blob/master/htmlToElement.js#L42

So the 'text' there represents actual raw text, which gets put into a Text component.

That gets wrapped in a parent Text component here, recursively: https://github.com/jsdf/react-native-htmlview/blob/master/htmlToElement.js#L95

Parent text component doesn't take any styles as props, and React Native ignores the child Text margins and padding if they are passed in.

from react-native-htmlview.

WorldWideWebb avatar WorldWideWebb commented on June 10, 2024

Ah - yes. I see what's going on.

from react-native-htmlview.

richchurcher avatar richchurcher commented on June 10, 2024

So of the problems reported in the OP, the <pre> and <ol> issues are solved. The first issue,

1. Use <a href="http//asciiflow.com/" rel="nofollow">http://asciiflow.com/</a> to generate diagram<p>2. Use Ascii to SVG<span></span>

now produces:

1. Use
http://asciiflow.com/
to generate diagram
2. Use Ascii to SVG

which I guess is marginally better in that it recognises a paragraph should break to a new line! The broken appearance of the rest of the text is because each inline element is receiving a newline, which is obviously not ideal but appropriately summarised in #114 so I'm going to close this.

from react-native-htmlview.

zarcode avatar zarcode commented on June 10, 2024

@gregblass @kengorab anyone can help me with this issue
https://www.screencast.com/t/8hOZoocMHS
I am getting too much whitespaces between elements. This is how html looks:

<p>Hello this text is <strong>Bold</strong> and this one is <em>italic</em>. Add some link <a href="http://some.com" target="_blank">link</a> not <del datetime="2017-08-10T06:02:09+00:00">deleted</del>.</p>
<blockquote><p>quote</p></blockquote>
<ul>
<li>some</li>
<li>item2</li>
<li>item3</li>
</ul>
<ol>
<li>some</li>
<li>item2</li>
<li>item3</li>
</ol>

Also as you can see first <p> is too high ( marked blue )

from react-native-htmlview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.