You can sign up to get a daily email of our articles, see the Mailing List page!
Support us on Patreon to keep GamingOnLinux alive. This ensures we have no timed articles and no paywalls. Just good, fresh content! Alternatively, you can donate through Paypal, Flattr and Liberapay!
Code tag ignoring whitespace
stretch611 commented on 20 November 2018 at 3:24 am UTC

I noticed this while posting this comment:

I used the code tag for formatting... In preview, this allowed me to not ignore whitespace and all the numbers lines up. But when posted it started to ignore white space. So you probably have a difference in your stylesheets or a missing PRE tag in HTML.

liamdawe commented on 20 November 2018 at 10:45 am UTC

Your right, the we use the HTML code tag which isn't really all that great. Can probably achieve a better result with the pre tag since it automatically preserves whitespace with the same styling we use now. Will look into it.

stretch611 commented on 20 November 2018 at 2:38 pm UTC

Ok, so I figured why was I complaining and having you look at the code... After all it is HTML and I have all the display code here in my browser.

It appears as if the html/css formatting is not the problem here. The tags in both places appear to have the same markup and css structure.

The problem actually appears to be when you generate the HTML. When you "view source" on the article/comment page, the extra whitespace is stripped out completely. It does not show the whitespace because the page generating the HTML removes it.

However, the whitespace still exists in the database (or whatever method you use to store comments.) This is evident because if I go back and attempt to edit my comment, the whitespace still appears inside the textarea.

So in order to fix the problem, you need to determine where the whitespace is being stripped out. Most likely it is being done as a page directive when generating the whole page, or, it is probably being done when sanitizing the comment for output. (i.e. most likely where you strip harmful html tags from the posted comment.)

Of course to figure this out would require access to the actual server side source code used for the website which I don't have access too... (and you don't want to see my bill for this either )

Shmerl commented on 20 December 2018 at 4:22 am UTC

Yeah, I was hit by this. You shouldn't just use code tag. You should also apply CSS style. Something like:

.preformatted { font-family: monospace; white-space: pre; }

stretch611 commented on 21 December 2018 at 4:41 am UTC

ShmerlYeah, I was hit by this. You shouldn't just use code tag. You should also apply CSS style. Something like:

.preformatted { font-family: monospace; white-space: pre; }

Personally, I would still use the tag... It is still a valid tag in HTML 5 and it is quite useful in describing the contents withing the tag. Though, in modern CSS, I would probably make sure to use what you have as part of the tag itself instead of creating a class. (unless I wanted the class for different tags.)
code { font-family: monospace; white-space: pre; }

That being said... the problem is not with the either the tag or the CSS in this case. The site is removing the extra spaces when creating the page. Using View source on the page will confirm this.

You can actually confirm by viewing the source on this page now that you used the code tag on it. Posting or editing a reply will confirm that the spaces still exist on the database when you go into the in page editor.

Due to spam you need to Register and Login to comment.

Or login with...

Livestreams & Videos
Community Livestreams
  • Puzzle Tiles: „The Cave“
  • Date:
See more!
Popular this week
View by Category
Latest Comments
Latest Forum Posts