Formatting Text to the Left...
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Formatting Text to the Left...
Hi;
TextPad is great! I'm a new user though and have a question.
I'm working on HTML files that were created long ago and when opening them in TextPad I would like all the text to automatically move to the left.
So there would be no identation of any lines.
The idea being that I want to get rid of any dead space. I hope there's a way to make it do that
TextPad is great! I'm a new user though and have a question.
I'm working on HTML files that were created long ago and when opening them in TextPad I would like all the text to automatically move to the left.
So there would be no identation of any lines.
The idea being that I want to get rid of any dead space. I hope there's a way to make it do that
Best Regards;
Marvin Miller
Marvin Miller
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
You may not really want to do that, HTML code does not use conventional line breaks. It may be coded for visual reading by programmer but have no effect on execution by browser. You may have a "return" code on the line for visual purposes, but it might break the syntax if you do automated replacements. Some leading spaces may be required to keep correct HTML syntax.
But, if you insist, try this:
================================
For some control about the spacing this is one method.
From the Main Menu
Edit, Select All.
Edit Reduce Indent. Repeat this as necessary until all text is shifted to left
===============================
Or use this method which will give no control on indentation.
Search and Replace using Regular Expressions (POSIX format):
Before doing Search and Replace, press CTRL-Home to go to beginning of document. You may also want to turn Word Wrap OFF for better visual of results.
NOTE: I have inserted underscore "_" to represent a visual space character. Actual code should be a real "space" character. (Using POSIX format)
Search for: \n(_+|\t+)(.*)
Replace with: \n\2
Explanation of RegEx Search expression:
\n ........ = Return code
( ......... = start of first tagged expression
_ ......... = space character
+ ........ = one or more of preceeding character (space)
| ......... = OR
\t ......... = Tab code
+ ......... = one or more of preceeding character (tab)
) ......... = end of first tagged expression
( .......... = start of second tagged expression
. .......... = any character
* ......... = any number of preceeding character (any character)
) .......... = end of second tagged expression
Explanation of RegEx Replace expression:
\n ........ = Return code
\2 ........ = second tagged expression
But, if you insist, try this:
================================
For some control about the spacing this is one method.
From the Main Menu
Edit, Select All.
Edit Reduce Indent. Repeat this as necessary until all text is shifted to left
===============================
Or use this method which will give no control on indentation.
Search and Replace using Regular Expressions (POSIX format):
Before doing Search and Replace, press CTRL-Home to go to beginning of document. You may also want to turn Word Wrap OFF for better visual of results.
NOTE: I have inserted underscore "_" to represent a visual space character. Actual code should be a real "space" character. (Using POSIX format)
Search for: \n(_+|\t+)(.*)
Replace with: \n\2
Explanation of RegEx Search expression:
\n ........ = Return code
( ......... = start of first tagged expression
_ ......... = space character
+ ........ = one or more of preceeding character (space)
| ......... = OR
\t ......... = Tab code
+ ......... = one or more of preceeding character (tab)
) ......... = end of first tagged expression
( .......... = start of second tagged expression
. .......... = any character
* ......... = any number of preceeding character (any character)
) .......... = end of second tagged expression
Explanation of RegEx Replace expression:
\n ........ = Return code
\2 ........ = second tagged expression
Last edited by Bob Hansen on Wed Nov 26, 2003 3:44 am, edited 1 time in total.
Hope this was helpful.............good luck,
Bob
Bob
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
Hmmm, I just tried a few more test pages, and saw some lines that still had a few leading spaces.
No time to look at it now, but the RegEx above will probably get rid of most of the leading spaces for you.......perhaps someone else will correct this before I get back to it again?
No time to look at it now, but the RegEx above will probably get rid of most of the leading spaces for you.......perhaps someone else will correct this before I get back to it again?
Hope this was helpful.............good luck,
Bob
Bob
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
Hey Marvin, looks like you are all set!
ben_josephs got back before me with a better solution. The errors I mentioned that I saw were as noted, some spaces following tabs.
My new solution is just about the same as his.
Again I have included underscore "_" as a visual "space" character. (Using POSIX format):
Search for:^[\t_]*
Replace with nothing.
Explanation of RegEx Search expression:
^ ...... = start at beginning of line
[ ....... = start of specific character class
\t ...... = tab character
_ ....... = space character (use a real "space")
] ....... = end of specific character class
* ...... = any number of preceeding expression
ben_josephs got back before me with a better solution. The errors I mentioned that I saw were as noted, some spaces following tabs.
My new solution is just about the same as his.
Again I have included underscore "_" as a visual "space" character. (Using POSIX format):
Search for:^[\t_]*
Replace with nothing.
Explanation of RegEx Search expression:
^ ...... = start at beginning of line
[ ....... = start of specific character class
\t ...... = tab character
_ ....... = space character (use a real "space")
] ....... = end of specific character class
* ...... = any number of preceeding expression
Hope this was helpful.............good luck,
Bob
Bob
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
It's a good habit to avoid regular expressions that match empty strings, so that you can use them conveniently for repeated searches. If you match an empty string, the current position doesn't advance, so the next attempt matches the same empty string, and so does the next one, and the next one...
When you search and replace using a regex that matches empty strings, the engine secretly advances one character after each empty match to ensure that it doesn't loop endlessly.
When you search and replace using a regex that matches empty strings, the engine secretly advances one character after each empty match to ensure that it doesn't loop endlessly.
Thanks guys!
The reason why I want to get rid of leading spaces is to make the file sizes as small as possible. You'd be surprised how much space in a file is taken up by dead space.
What I'm doing is re-vamping my website. It was originally coded with Front Page so I'm in there trimming & editing to make it fully W3C compliant.
While I'm at it I want to add new content, re-write sections to get rid of clunky and inefficient code and also remove any whitespace from the files.
I'm finding significatnt reductions in file sizes and I'm not done yet Once completed the site should load way faster and my monthly traffic will be much less due to smaller sizes.
As well, the Internet itself should be less congested due to my cleaner code
The reason why I want to get rid of leading spaces is to make the file sizes as small as possible. You'd be surprised how much space in a file is taken up by dead space.
What I'm doing is re-vamping my website. It was originally coded with Front Page so I'm in there trimming & editing to make it fully W3C compliant.
While I'm at it I want to add new content, re-write sections to get rid of clunky and inefficient code and also remove any whitespace from the files.
I'm finding significatnt reductions in file sizes and I'm not done yet Once completed the site should load way faster and my monthly traffic will be much less due to smaller sizes.
As well, the Internet itself should be less congested due to my cleaner code
Best Regards;
Marvin Miller
Marvin Miller
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact: