The central location for E2E training, feature updates, member feedback and site support
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]
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:
Beyond that if you need any help with any posts in including code let me know.
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
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
should look like this:
(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.
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!
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 "<" before pasting it. I can do this mechanically, so that's also a "little grief" thing.
So, I have an acceptable workaround.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.