[TxMt] unordered list nav snippet
Nithin Reddy
jashugan at gmail.com
Wed May 31 22:32:52 UTC 2006
Here's a modified version of Charilaos' script:
#!/usr/bin/env ruby
txt = "<ul>\n"
STDIN.read.each_line do |x|
txt = txt + "\t<li><a href=\"\">#{x.strip}</a></li>\n"
end
txt = txt.sub(/\n\z/) { |match| "$0#{match}" }
txt = txt + "</ul>"
print txt
This is a command, where input is Selected Text or Nothing, and where
output is Insert as Snippet. The substitution puts the carat at the
end of the last list item. If nothing is selected then it prints:
<ul>
</ul>
with the carat just after the opening ul tag.
On 5/18/06, Charilaos Skiadas <cskiadas at uchicago.edu> wrote:
>
> On May 18, 2006, at 7:32 PM, Dave Foy wrote:
>
> > I'm having trouble creating a custom snippet that, for me, would be
> > really useful.
> >
> > I want to set up a snippet to create an unordered list nav from a
> > plain text list, e.g.
> >
> > foo
> > bar
> > coo
> > tar
> >
> > I'd like to highlight the whole list, hit a key combo, which would
> > wrap each list item in <li>, wrap the whole lot in <ul>, and even
> > wrap the text within each list item in <a href=""></a> for good
> > measure.
> >
> > Can anyone help?
>
> This should get you started, i.e. you should be able to easily modify
> it to do what you want it to, even if you don't know much ruby.
> Create a command with input selected text with fallback line, output
> replace selected text (or possibly insert as snippet if you want to
> do something more clever) and text:
>
> #!/usr/bin/env ruby
> #
> print "<ul>\n"
> STDIN.read.each_line { |x|
> print "\t<li>\n\t\t<p>#{x.chomp}</p>\n\t</li>\n"
> }
> print "</ul>\n"
>
>
> I hope this is (at least relatively) clear and you should be able to
> modify it to do stuff. the syntax #{x.chomp} which might seem
> familiar tells Ruby: "I know you are inside a string now, but execute
> the thing in the {} as a ruby program and put its output in the
> string right here". x.chomp returns the string x with the possible
> newline removed.
>
> > Many thanks in advance.
>
> Haris
>
>
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
>
More information about the textmate
mailing list