Improved plain-text handling in Firefox
8 March, 2013 § 30 Comments
If you’ve ever tried to read a plain-text file in Firefox, you may have noticed that we didn’t have an option to apply word wrapping to the text. New in today’s Firefox Nightly build, we are now applying word wrap to plain text documents by default.
For example, this file is very hard to read when the lines aren’t wrapped. The lines scroll offscreen horizontally, and the user has to use the horizontal scrollbar on the bottom of the screen to read the file (yuck!). Here’s a screenshot of what I’m talking about:
With word wrapping applied, the text is much easier to read and the line length will adapt to the size of the browser window:
Some documents aren’t ideal for word wrapping, and to aid that we have made it easy to disable the feature. To toggle whether the document is wrapped on a case-by-case basis, you can change between the “Wrap Long Lines” stylesheet and “No Style”.
If you’d like to disable the feature entirely, you can go to
about:config and set the
plain_text.wrap_long_lines preference to
We can’t have the thousands of text files on our website wrap. Is there a way to insert a directive (like in an .htaccess file) so that all browsers do not wrap the text?
Can you try changing the mime-type of the text files to text/html? Let me know if that doesn’t work for you.
Thank you for the suggestion. That doesn’t seem to work though. I also tried text/plain and text/rtf mime-types. Hope there is a solution! Any other ideas?
I tried some mime types and saw the same result you got. text/html won’t work because HTML documents will by default text-wrap their contents as well.
It seems you may need to wrap your content with “pre” tags in order to tell the browser that this is preformatted text and to not wrap.
Yes, content must be wrapped with something, but I just couldn’t edit thousands of files. Here is the solution I finally employed.
In .htaccess: RedirectMatch (.*)\.txt$ textdisplay.php?file=$1.txt.
In the .php file, inside
Here is the solution again, in case anyone needs it, for disabling word wrap using htaccess and php, since my earlier comment did not format correctly: In .htaccess: RedirectMatch (.*)\.txt$ textdisplay.php?file=$1.txt In the .php file, inside a “pre” tag: echo file_get_contents(“$_GET[‘file’]);
Oops, wish I could edit my last comment. Looks like comments pay attention to “pre” tags!