-1

I have a html as string(with Tag in it as shown below in p tag ) and I want to slice only contain data but problem is slice method divide the string with html tag and that can't generate required output.

So I Want to slice the String with opening and closing tag of the html and divide the content into section with tags and their styling should not be removed.

My Present function slice with static value with index of interval like slice(0,500), slice(500, 1000) and so on. In doing that I divide the string with their respective styling properties also because of that styling is divide into two parts and for that reason it does not apply on the tag.

<p style="margin: 0px 0px 15px; font-size: 14px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, "</p> <h3 style="margin: 15px 0px; padding: 0px; font-size: 14px; color: rgb(0, 0, 0); font-family: &quot;Open Sans&quot;, Arial, sans-serif;">Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC</h3>

I am generating pdf from html in react-native. I want To divide the above html string into different pages so I am using the slice method to divide into sections and then applying page break but it divide the string with respect to tags and style property.

BiRjU
  • 733
  • 6
  • 23

1 Answers1

0

I would have a variable that stores indexOf the > character and a variable for <. I would find the index of the first and then use that as the start position for the next character(<). e.g.

const myString = "<p>Some text content</p>"

const firstIndex = myString.indexOf('>')
const secondIndex = myString.indexOf('<', firstIndex)
LeKoels27
  • 13
  • 5