Code formatting issue 'pre' tags ignore spaces.

Welcome Forums Web Site Feedback & Assistance Code formatting issue 'pre' tags ignore spaces.

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
1 month, 2 weeks ago.

  • Author
    Posts
  • #119016

    Participant
    Points: 113
    Helping Hand
    Rank: Participant
    When formatting code enclosing it in 'pre' tags, spaces are lost.
    For example:
    if (-not $null) {
        Write-Output 'not null'
    }
    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:
    if (-not $null) {
    Write-Output 'not null'
    }
    

    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.

  • #119119

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #119137

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero
    This was changed to PREFORMATED in the Visual Editor
    This was surrounded by PRE tags in the Text editor
    This was surrounded by PRE bbCodes in the Visual Editor.
    This is at least
      three
         lines
            long
    

  • #119139

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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.

  • #119223

    Participant
    Points: 113
    Helping Hand
    Rank: Participant

    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.

  • #119998

    Participant
    Points: 292
    Helping Hand
    Rank: Contributor

    I've noticed that using the regular 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 key. Using Shift+Enter is a relatively easy workaround in the meantime, but not everyone may be aware of or think to try it. 🙂

You must be logged in to reply to this topic.