3

I have a contenteditable div the user enter data. When they enter line break, each browser stores the data differently. When I export this data to Word using HtmlToOpenXml it adds a blank line for the content and I want to avoid that so the html page and word doc look the same.

One option for me is to replace the tags <br>, <div>, <p> with blank and then replace the </div> and </p> with <br/> in the C# code using RegEx. But I do not know what all formatting is used for contenteditable div by different browsers and this implementation may not help.

I would like to know what is the best way to address this or is there any open source tool/dll that helps me with this issue?

e.g. ContentEditable div actual data in browsers looks like below

Chrome -

line1<div>line2</div><div>line3</div>

IE Edge-

 <div>line1</div><div>line22</div><div>line3<br></div>

FireFox - I read it uses <p> </p> instead of <div> </div>

Safari - ????

SRAMPI
  • 373
  • 8
  • 23
  • Your question may have answer in this stack question. https://stackoverflow.com/questions/5431580/convert-html-to-docx-in-c-sharp – Pig and Cat Aug 16 '17 at 17:43
  • How about completely replacing div elements with different ones, for example span and see how your app reacts – usefulBee Aug 17 '17 at 19:13

1 Answers1

0

A Solution I found:

You could use RegEx, which I highly recommend in C# for parsing information.

Then effectively based on the formatting you could narrow down what browser it is and then move on towards parsing it's output and what its XML means universally. This will not be easy but no cross-platform ever truly is. I would give a example of how this could be done, but RegEx in all honesty takes a good amount of work and it would be quite a bit of code to make a example that could show you how to parse it and find out what the browser is.

Sean Mitchell
  • 447
  • 2
  • 21
  • Thank you for the comment, but I already mentioned he RegEx solution in my question. – SRAMPI Aug 21 '17 at 20:23
  • I understand, but I gave the point of view of using it to universalize the format which you did not state. – Sean Mitchell Aug 22 '17 at 01:56
  • @SA You also didn't specify if this was your site with the divs, how C# came into it, and all the languages at your disposal which made it much harder to extrapolate the details. If you tell me some more info I would be happy to help and change my answer to help. – Sean Mitchell Aug 22 '17 at 12:26