0

I have a string that is HTML codes, but they are all in one row, I want to create an HTML file, with this string and organize the code by adding \t, correctly according to the HTML syntax..

From:

<!DOCTYPE htmL>
<html>
<head>
<meta charset="UTF-8">
<title>Title goes here</title>
</head>
<body>
</body>
</html>

To:

<!DOCTYPE htmL>
<html>
\t<head>
\t\t<meta charset="UTF-8">
\t\t<title>Title goes here</title>
\t</head>
\t<body>
\t</body>
</html>

I want it to be added inside the string, so that I can then create an HTML file, correctly and orderly..

I tried many ways, but I didn't find the right solution for that

  • 1
    do you mean just having a formatter? – Daniel A. White Feb 05 '22 at 20:21
  • it is called intending too – aloisdg Feb 05 '22 at 20:24
  • Right I want it to be properly formatted by JavaScript before converting it to a downloadable HTML file – Sultan Alrefaei Feb 05 '22 at 20:30
  • Where does the original file come from? Does a person create it by hand? Is it generated by an app or program? Do you only need to do it once or will these unformatted files be generated and need to be converted on a regular automatic basis? – kevintechie Feb 05 '22 at 20:35
  • https://stackoverflow.com/questions/3913355/how-to-format-tidy-beautify-in-javascript – Đinh Carabus Feb 05 '22 at 20:36
  • The string comes by recognizing an image containing HTML code. These unformatted texts are obtained through the text-in-image recognition technology, and I want the text to be formatted automatically, through a specific function or code, the text is passed to it and the format is modified, and then a file is created and the content is placed in it after formatting. I did all the operations, but I couldn't do the HTML formatting process. – Sultan Alrefaei Feb 05 '22 at 20:43
  • 1
    See the link in the comment above for some basic solutions, but really good formatting is not a trivial algorithm. You have to actually recognize the different tags, differentiate between paired and non-paired tags, handle missing optional closing tags (like `` in some cases), handle HTML comments, handle syntax mistakes, etc. – Noam Feb 06 '22 at 01:07
  • Thank you, the library works perfectly, and I have already improved the text extracted from the image, as you know when extracting text from the image, it is considered text and not correct codes in the HTML language, so I built special functions, improve and modify the text and turn it into an integrated HTML code with the addition of elements The missing brackets, and other HTML tags, I think it has become an integrated tool for recognizing HTML codes through images, whatever those images are, thank you everyone – Sultan Alrefaei Feb 06 '22 at 14:08

0 Answers0