I would like to use Textmate's built-in Tidy (Ctrl+Shift+H) functionality to indent my HTML 'without modifying anything' in the code. I write pretty neat HTML already, I just need Tidy to indent my code with Soft-tabs.
Currently it breaks a lot of things and the formatting isn't perfect either. Can someone please write a Tidy config for me that does this:
1 - Indents only, nothing else.
2 - I don't need certain tags to be pushed on a newline. For example: Tidy does this:
<li> # link </li>
Original Code (or What I need):
<li> # link </li>
..so if I can pre-define which tags to be kept inline, that would be great.
Basically, I'd like to duplicate Dreamweaver's HTML formatting functionality with Tidy, but the two things mentioned above are really important.
I think this is my current (default?) Tidy config:
${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \ -wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \ --indent yes \ ${TM_XHTML:+-asxhtml --output-xhtml yes} \ ${TM_SELECTED_TEXT:+--show-body-only yes} \ --enclose-text yes \ --doctype strict \ --wrap-php no \ --tidy-mark no`
I'd greatly appreciate any help. Thanks!
On Sun, Sep 13, 2009 at 09:56, 3zzy iaezzy@gmail.com wrote:
I would like to use Textmate's built-in Tidy (Ctrl+Shift+H) functionality to indent my HTML 'without modifying anything' in the code. I write pretty neat HTML already, I just need Tidy to indent my code with Soft-tabs.
Wouldn’t it be easier to just not use tidy for this case and just use ⌥⌘[ to reindent your document? Martin
Not really. I manually indent where possible, but Tidy is required for tidying up someone else's files with hundreds of lines of code.
On Sun, Sep 13, 2009 at 4:00 PM, Martin Kühl martin.kuehl@gmail.com wrote:
On Sun, Sep 13, 2009 at 09:56, 3zzy iaezzy@gmail.com wrote:
I would like to use Textmate's built-in Tidy (Ctrl+Shift+H) functionality
to
indent my HTML 'without modifying anything' in the code. I write pretty
neat
HTML already, I just need Tidy to indent my code with Soft-tabs.
Wouldn’t it be easier to just not use tidy for this case and just use ⌥⌘[ to reindent your document? Martin
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Ibrahim Ezzy wrote:
Not really. I manually indent where possible, but Tidy is required for tidying up someone else's files with hundreds of lines of code.
My solution to this sort of thing is to run Tidy, then follow up with a regex replacement. In your case I'd do something like...
Find: <li>\n\s*(.*)\n\s*</li> Replace: <li>$1</li>
This should pull out the newlines and extraneous spaces.
Kind of clumsy, but I suppose you could make a macro to do all this in one keystroke if you need to do the same thing frequently.
Thanks Steve, but I'm not sure what to change in that code snippet, following is the full command source:
#!/usr/bin/env ruby -wKU
require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb' require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes.rb'
result = `"${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \ -wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \ --indent yes \ ${TM_XHTML:+-asxhtml --output-xhtml yes} \ ${TM_SELECTED_TEXT:+--show-body-only yes} \ --enclose-text yes \ --doctype strict \ --wrap-php no \ --tidy-mark no` status = $?.exitstatus
at_exit { File.unlink('/tmp/tm_tidy_errors') } # Clean up error log
if status == 2 # Errors
msg = "Errors: " + File.read('/tmp/tm_tidy_errors') TextMate.exit_show_tool_tip msg
elsif status == 1 # Warnings - use output but also display notification with warnings
log = File.read('/tmp/tm_tidy_errors').to_a.select do |line| ! (ENV['TM_SELECTED_TEXT'] and (line.include?('Warning: missing <!DOCTYPE> declaration') or line.include?("Warning: inserting missing 'title' element"))) end.join rescue nil
unless log.empty? options = { :title => "Tidy Warnings", :summary => "Warnings for tidying your document (press escape to close):", :log => log } TextMate::UI.simple_notification(options) end
end
if ENV['TM_SOFT_TABS'] == "YES" print result else in_pre = false result.each_line do |line| unless in_pre tab_size = ENV["TM_TAB_SIZE"].to_i space, text = /( *)(.*)/m.match(line)[1..2] line = "\t" * (space.length / tab_size).floor + " " * (space.length % tab_size) + text end
print line
in_pre = true if line.include?("<pre>") in_pre = false if line.include?("</pre>") end end
Thanks for any help you can offer.
Steve King-8 wrote:
Ibrahim Ezzy wrote:
Not really. I manually indent where possible, but Tidy is required for tidying up someone else's files with hundreds of lines of code.
My solution to this sort of thing is to run Tidy, then follow up with a regex replacement. In your case I'd do something like...
Find: <li>\n\s*(.*)\n\s*</li> Replace: <li>$1</li>
This should pull out the newlines and extraneous spaces.
Kind of clumsy, but I suppose you could make a macro to do all this in one keystroke if you need to do the same thing frequently.
-- Steve King Sr. Software Engineer Arbor Networks +1 734 821 1461 www.arbornetworks.com http://www.arbornetworks.com/
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
3zzy wrote:
Thanks Steve, but I'm not sure what to change in that code snippet, following is the full command source:
Don't change anything in the command. Run the Tidy command as normal, then follow it by doing a Find & Replace operation. So, say you start with the following HTML:
<h1> Hello, world! </h1><ul><li> first </li> <li>second</li><li>third </li> </ul>
Now, run the Tidy command from the HTML bundle. Your output may be slightly different, but when I run it I get:
<h1> Hello, world! </h1> <ul> <li>first </li> <li>second </li> <li>third </li> </ul>
Now, to fix up the ugly list formatting I do ⌘F to open the Find dialog.
Find: <li>[ \n]*(.*?)[ \n]*</li> Replace: <li>$1</li> Regular expression: checked
Hit "Replace All", and the list elements are lined up like they should be.
<h1> Hello, world! </h1> <ul> <li>first</li> <li>second</li> <li>third</li> </ul>
The Find expression above is a little more complex than the one I posted earlier, but it should handle some wackier formats.
Like I mentioned earlier, if you change --indent yes to --indent auto in the tidy command you will get:
<h1>Hello, world!</h1>
<ul> <li>first</li>
<li>second</li>
<li>third</li> </ul>
it's still not perfect (it likes to screw up php and it has those extra lines) but it's still better than having 3 lines per li or h1 or whatever. i've never found the setting that stops it from adding blank lines between </li>.
auto indent also helps to prevent IE bugs due to significant- insignificant whitespace when it wraps everything.
On Sep 14, 2009, at 3:59 PM, Steve King wrote:
<h1> Hello, world! </h1><ul><li> first </li> <li>second</li><li>third </li> </ul>
-- Jacob Coby
Change --indent=yes to auto.
http://tidy.sourceforge.net/docs/quickref.html#indent
On Sep 13, 2009, at 3:56 AM, 3zzy wrote:
I would like to use Textmate's built-in Tidy (Ctrl+Shift+H) functionality to indent my HTML 'without modifying anything' in the code. I write pretty neat HTML already, I just need Tidy to indent my code with Soft-tabs.
Currently it breaks a lot of things and the formatting isn't perfect either. Can someone please write a Tidy config for me that does this:
1 - Indents only, nothing else.
2 - I don't need certain tags to be pushed on a newline. For example: Tidy does this:
<li> # link </li>
Original Code (or What I need):
<li> # link </li>
..so if I can pre-define which tags to be kept inline, that would be great.
Basically, I'd like to duplicate Dreamweaver's HTML formatting functionality with Tidy, but the two things mentioned above are really important.
I think this is my current (default?) Tidy config:
${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \ -wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \ --indent yes \ ${TM_XHTML:+-asxhtml --output-xhtml yes} \ ${TM_SELECTED_TEXT:+--show-body-only yes} \ --enclose-text yes \ --doctype strict \ --wrap-php no \ --tidy-mark no`
I'd greatly appreciate any help. Thanks!
View this message in context: http://www.nabble.com/Configuring-HTML-Tidy-tp25420981p25420981.html Sent from the textmate users mailing list archive at Nabble.com.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
-- Jacob Coby
Indent works already, but not how i want. It pushes ALL tags on a new line.
Sent from my iPhone
On 13-Sep-2009, at 7:49 PM, Jacob Coby jcoby@portallabs.com wrote:
Change --indent=yes to auto.
http://tidy.sourceforge.net/docs/quickref.html#indent
On Sep 13, 2009, at 3:56 AM, 3zzy wrote:
I would like to use Textmate's built-in Tidy (Ctrl+Shift+H) functionality to indent my HTML 'without modifying anything' in the code. I write pretty neat HTML already, I just need Tidy to indent my code with Soft-tabs.
Currently it breaks a lot of things and the formatting isn't perfect either. Can someone please write a Tidy config for me that does this:
1 - Indents only, nothing else.
2 - I don't need certain tags to be pushed on a newline. For example: Tidy does this:
<li> # link </li>
Original Code (or What I need):
<li> # link </li>
..so if I can pre-define which tags to be kept inline, that would be great.
Basically, I'd like to duplicate Dreamweaver's HTML formatting functionality with Tidy, but the two things mentioned above are really important.
I think this is my current (default?) Tidy config:
${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \ -wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \ --indent yes \ ${TM_XHTML:+-asxhtml --output-xhtml yes} \ ${TM_SELECTED_TEXT:+--show-body-only yes} \ --enclose-text yes \ --doctype strict \ --wrap-php no \ --tidy-mark no`
I'd greatly appreciate any help. Thanks!
View this message in context: http://www.nabble.com/Configuring-HTML-Tidy-tp25420981p25420981.html Sent from the textmate users mailing list archive at Nabble.com.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
-- Jacob Coby
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate