Code formatting issue 'pre' tags ignore spaces.

When formatting code enclosing it in 'pre' tags, spaces are lost.
For example:

[pre]

if (-not $null) {
Write-Output 'not null'
}
[/pre]
Should look like
if (-not $null) {
Write-Output 'not null'
}
EDIT: Never mind. It works using the 'Text' editor instead of the 'Visual' editor, as the latter adds 'div' tags which break the code within the 'pre' tags. Maybe something that can be improved.
Text editor:
[pre] if (-not $null) { Write-Output 'not null' } [/pre]

EDIT: I’m having a hard time getting this to work consistently. I got it working in https://powershell.org/forums/topic/help-with-a-foreach/#post-119013, however I see that Wes has no indenting.

So, here’s the thing: This is shrink-wrap software. We don’t have a dev team to do major code modifications, and personally I can only tweak it within the realms of my PHP programming capabilities (which are slight).

If you paste a Gist, then GitHub handles all the formatting and it usually turns out pretty beautifully. Tab characters (vs spaces) are challenging in HTML no matter what, and HTML as a rule tends to ignore whitespace. Using the PRE HTML tag will get you as close as I’ve been able, on my own meager skills. I’ve tried numerous code-formatting plugins, and the one we’re currently using was the best of the bunch. I just unfortunately have a limited amount of time - working around my full-time job - to fuss with it.

As a test…

 - one space
  - two spaces
   - three spaces

What happens when you’re copying and pasting from a code editor or IDE, sometimes, is that you’re getting tab characters, which are less reliable, or you’re getting something like a nonbreaking space or other whitespace character that isn’t an actual space, and which gets interpreted differently. Bear in mind that it’s ultimate the browser, not the website code, that determines what the eventual display will look like. Coming up with something that’s consistent across the half-dozen major browser choices is even more challenging.

This was changed to PREFORMATED in the Visual Editor
This was surrounded by PRE tags in the Text editor

[pre]This was surrounded by PRE bbCodes in the Visual Editor.[/pre]

This is at least
  three
     lines
        long

https://gist.github.com/concentrateddon/b7fd261bda772c5a6d2d

Yeah, I think I’m not seeing the same behaviors as you.

Bear in mind the square-bracket PRE tags are bbCodes; those get interpreted under the hood into HTML angle-bracket PRE tags. So long as you haven’t monkeyed around with what’s between them, it SHOULD NOT add additional DIV tags and whatnot. However, if you’re pasting from something like VS Code, know that it puts several versions of your code into the clipboard. That’s intended to facilitate pasting into different apps. When you paste into a browser, it can paste an HTML version, because it’s attempting to make it “pretty.” That’s going to conflict with what the website is doing - you need to paste a plain-text version instead, which the Text tab lets you see more easily.

Frankly, the most reliable is to use the Visual tab, paste your code, highlight it, and change it to PREFORMATED from the “Paragraph” drop-down - that’s what the instructions right above the posting box indicate. That applies an HTML PRE tag, which is what our syntax highlighting plugin is looking for. I did several examples ^^ above, though, and they all worked as expected for me. If you’re getting inconsistency, it’d be helpful to know what your copying and pasting from (or if you’re typing freeform), and what browser(s) you’re using, and exactly what formatting approach you’re trying. Helps narrow down the possibilities.

Thanks for your response.

I was pasting from Visual Studio Code into the “Visual” editor on the Microsoft Edge browser. I’ve been getting better results pasting from notepad into the “Text” editor.

It can be hard to read forum posts where large scripts have been pasted that are missing indenting. I completely understand that you have a limited amount of time, nevertheless I wanted to leave the feedback here.

I’ve noticed that using the regular <Enter> keypress to break lines tends to terminate the code formatting blocks and start a new one; this might be due to the precedence rules of which tags can contain others, and the default behaviour of the <Enter> key. Using Shift+Enter is a relatively easy workaround in the meantime, but not everyone may be aware of or think to try it. :slight_smile: