0

I want to insert pre-formatted text into html text, but the renderer insists on adding blank lines before and after the pre-formatted text. For example, this html code:

<html>
<body>
Before text
<pre>
Line 1: Pre-formatted text
Line 2: Pre-formatted text
</pre>
After text
</body>
</html>

results in this output:

Before text
Line 1: Pre-formatted text
Line 2: Pre-formatted text 
After text

Is there any way of getting rid of the leading and trailing blank lines? If I'd wanted them, I could have put them in myself!

TonyK
  • 16,761
  • 4
  • 37
  • 72
  • 1
    Probable duplicate: https://stackoverflow.com/questions/4233869/html-pre-tag-causes-linebreaks – Josh Cooley Oct 23 '20 at 17:23
  • 1
    Does this answer your question? [HTML
     tag causes linebreaks](https://stackoverflow.com/questions/4233869/html-pre-tag-causes-linebreaks)
    – Josh Cooley Oct 23 '20 at 17:35
  • @Josh: Thanks for those links! I found a working solution there -- see my answer. – TonyK Oct 23 '20 at 17:52
  • I'm glad you found an answer! Sorry for the duplicate comments. I didn't realize flagging a duplicate added a comment automatically. – Josh Cooley Oct 23 '20 at 18:09

1 Answers1

0

There are many suggestions in the possible duplicates posted in the comments. The solution that works for me is to replace <pre> with <pre style="margin:0">, and to add <br> outside the pre-formatted text to compensate as required.

TonyK
  • 16,761
  • 4
  • 37
  • 72