Results 1 to 4 of 4

Thread: [RESOLVED] Code Tag Removes New Lines

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,755

    Resolved [RESOLVED] Code Tag Removes New Lines

    So I'm trying to use the <code> tag but for whatever reason it keeps removing new line characters. This is my markup:
    HTML Code:
    <code><span class="code-blue">Dim</span> firstName <span class="code-blue">As String</span> = <span class="code-red">"David"</span>
    <span class="code-blue">Dim</span> age <span class="code-blue">As Integer</span> = 101 <span class="code-green">'At least I feel this old some times!</span>
    <span class="code-blue">Dim</span> height <span class="code-blue">As Double</span> = 70.5 <span class="code-green">'Represented in inches</span></code>
    And this is my CSS:
    Code:
    code {
      border: 1px solid #666;
      display: flex;
      font-family: monaco,Consolas,Lucida Console,monospace;
      font-size: 15px;
      min-height: 5em;
      white-space: pre;
      width: 100%;
      word-break: normal;
      word-wrap: normal;
    }
    
    .code-blue {
      color: #0000ff;
    }
    
    .code-red {
      color: #ff0000;
    }
    
    .code-cyan {
      color: #00FFFF;
    }
    
    .code-green {
      color: #00A550;
    }
    Any reason why it would be doing that? Also, do y'all know of a way that the syntax highlighting can be done automatically? I'm getting really tired of creating all those <span> elements.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Code Tag Removes New Lines

    HTML strips all excess whitespace, so newlines will be ignored. The HTML5 spec mentions wrapping the <code></code> tags in <pre></pre> tags to preserve the whitespace.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  4. #4

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,755

    Re: [RESOLVED] Code Tag Removes New Lines

    Awesome! The syntaxhighlighter one worked best and had a VB.Net brush too, so I went in that direction.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width