Forums





Learn E2E

Learn E2E

Learn E2E

The central location for E2E training, feature updates, member feedback and site support

pre+code markup tags lose all pre-formatting

This question is not answered
Mastermind40900 points

I frequently need to paste code snippets into posts, and they usually need a fixed-width font to look right.  I try to do this with the <pre> tag to indicate that the forum should not mess with the spacing, followed by a single <code> tag to get courier font.  However, in that combination, the forum seems to reduce all consecutive whitespace to a single space.  Using the <span> tag with courier font gives the same behavior.  The only solution I've found so far is to create a <pre> section, and then line-by-line mark each line <code>.  Is there a faster way to paste a large block of pre-formatted text in a fixed-width font?

[Edit: I did not correctly describe the conditions the first time --Archaeologist]

All Replies
  • Mastermind18505 points

    Pasting the code directly in should work though using "Paste from Word" if its being copied by chance from a Microsoft product.

    The pre HTML tag will cause anything included in it not to wrap.

    Brad Griffis has a good write up of using code and the rich text editor here:

    http://e2e.ti.com/group/helpcentral/f/301/t/156936.aspx#588929

    Beyond that if you need any help with any posts in including code let me know.

    Blake 


    Blake Ethridge, Social Media Community Engagement Manager, Texas Instruments

    E2E Blog - Stay up to date on all E2E news and updates | About E2E | Updating Your Avatar


  • Mastermind40900 points

    The HTML in Brad's post corresponding to the fixed-width example does not use "pre", it is a single paragraph "p" with multiple "br"-separated lines, each of which has its font changed by a "span" pair.  This is essentially the same method as the "code per line" workaround that I describe above.

    I am usually not cutting from a Microsoft product, I am cutting from a Linux plain-text file, and pasting into the HTML edit subwindow.

    It is the HTML edit subwindow that is causing the problem.  The editor does not respect whitespace inside "pre" if the whitespace occurs within a nested tag.

    In HTML, the construct

    <pre><code>abc
    def</code></pre>

    should look like this:

    abc
    def

    (You can verify this in any web browser with a plain HTML file.)

    In fact, the same problem occurs if I view that same plain HTML file in IE and cut-and-paste it into a forum reply.

    Basically, what I want is an HTML editor that does absolutely no reformatting of the underlying raw text.  I realize that the HTML editor does some reformatting to remove unbalanced tags and whatnot, so this might be unachievable.


  • Mastermind18505 points

    Agreed and we are reviewing updates to the editor to be more code friendly and better options for supporting. Thanks for the feedback and input!

    Blake


    Blake Ethridge, Social Media Community Engagement Manager, Texas Instruments

    E2E Blog - Stay up to date on all E2E news and updates | About E2E | Updating Your Avatar


  • Mastermind40900 points

    An update:

    To my surprise, leaving out the "code" tag entirely and just using "pre" makes the preformatted fixed-width when the post is actually made.  While the post is still being composed, preformatted text is shown in a proportional font, which causes me a little grief, but I can deal with that.

    The other thing I noticed is that when I place a C example with something like "#include <stdio.h>" using the HTML editor, it mistakenly treats "<stdio.h>" as a tag and drops consecutive whitespace once more, so I need to take care to replace "<" with "&lt;" before pasting it.  I can do this mechanically, so that's also a "little grief" thing.

    So, I have an acceptable workaround.