Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Code blocks on this forum need fixing

    The code blocks on this forum give weird output every now and then.
    Specifically, multi-line code is rendered as a single line, which makes the code completely useless.

    From personal experience, this happens when one or both of the opening/closing code blocks is on he same line as the actual code.
    I cannot say his problem is perfectly producible. It probably would have been fixed by now if it was. It seems to happens sometimes, perhaps because some characters are or are not included and interfere with proper rendering.
    A recent example can be seen in post #5 here: https://www.statalist.org/forums/for...ments-for-date
    I've experienced this myself plenty of times, and I have seen code of other members mangled like this, including from some members with plenty of experience on here.

    My personal experience is that it never happens if you put opening and closing code blocks on separate lines, i.e.:
    {CODE}
    some code
    {/CODE}

    I would appreciate if this behavior could be fixed, or alternatively, if pressing # would not result in
    {CODE}{/CODE}
    but instead would result in
    {CODE}

    {/CODE}
    being written in the textbox.

    I'd be happy if anyone could suggest if maybe there is some error on the user side that makes this happen (and how to prevent).
    If other members have noticed the same, please do also comment. If I'm not he only one that bumps into this every now and then maybe a forum admin might look into this.

  • #2
    What I've noticed many times is that copy and paste of code from code block in a previous post to code block in a post I am writing (using in my case the Windows clipboard) often doesn't preserve end of line breaks and at worst I have to re-insert the line breaks. I've sometimes tried intermediate copy and paste into Stata or my own favourite text editor Vim as a work-around.

    I am flagging Pete Huckelba on sladmin for any comments StataCorp may have.

    Comment


    • #3
      I toyed with some examples, including the long sample dataset provided by Edward here. Interestingly, my initial test only displayed the Code block in a wide format. No amount of change from:

      {CODE}<dataset>{/CODE}

      to

      {CODE}
      <dataset>
      {/CODE}

      nor filtering the data through vi/cat/strings would change the format of the code block from wide to long. Frustrated, I tried it again with same the code block and it displayed in long form. Since I was doing my tests in the Sandbox, I visually diffed what I had copied and pasted and it looked the same. It was not until I checked for non-printable characters that the issue became clear, there were non-printable characters in what I had copied/pasted.

      The current work around is to paste as plain text via <ctrl><shift>v instead of the normal <ctrl>v. In Google Chrome, you can also right-click to select "Paste as plain text".

      -Pete

      Comment


      • #4
        Okay, hanks for looking into it.
        I did not mean to say that using separate lines for the open/close code blocks could 'fix' a block of code displayed as a single line to display as multi-line code. Only that it would prevent single-line display of a block of code when first posting. I can't say this with certainty, as I didn't check for non-printing characters when I bumped into this before.

        Comment

        Working...
        X