Search code examples
htmlcssasp.netrazorpre

Strange indentation when using pre


In C# I fill a field with strings. Every string is ending with "\r\n". Then I fill a website with this data using Razor:

<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
     align="left">
     @item.Data
</td>

Output on the website:

          - first line     (about 13 additional empty spaces)
- second line
- third line
- fourth line and so on

Desired output:

- first line
- second line
- third line
- fourth line and so on

Should I provide more code?

EDIT:

HTML:

<td style="max-width:130px; overflow-wrap:break-word; white-space:pre;"
    align="left">
    firstline&#xD;&#xA;secondline
</td>

Solution: Actually my code maid extension in Visual Studio added white space after <td ...>(many whitespace here)


Solution

  • The white spaces are generated by the "formatted" html source code. You need to "uglify" the html code as well.

    Before:

    <tr>
        <td style="max-width:130px; overflow-wrap:break-word; white-space:pre;" align="left">
            firstline&#xD;&#xA;secondline
        </td>
    </td>
    

    After:

    <tr>
        <td style="max-width:130px; overflow-wrap:break-word; white-space:pre;" align="left">firstline&#xD;&#xA;secondline</td>
    </tr>