Sublime Forum

Convert tabs to HTML tables like TextMate

#1

When I used TextMate there was a very neat plugin that allowed you to basically paste an Excel document into the TextMate document and then when you ran it, the tab separated columns/cells would be converted into an HTML table. This was a huge time saver when we needed to update several tables a day in a site. The client would sent us the Excel documents with the updated information, I would just open it, copy all the columns into TextMate, run the command (called “tabs to tables” or something like that) and I could just copy the resulting HTML code into the website.

I’ve been looking for something like this for Sublime Text with no luck, is there a plugin with said functionality?

0 Likes

#2

How’s this?

https://github.com/jbrooksuk/TabsToTable

Very quickly hacked together, I just borrowed a function from Dr. Drang, so it can be improved I’m sure.

0 Likes

#3

The separator is completely customisable now. I suggest using " | " for visible table structure.

I’ve submitted to Package Control, so it should be too long.

0 Likes

#4

Column values can now be aligned left/right. I’m sure there is a better way of doing that though.

0 Likes

#5

Hey jbrooksuk thanks for that! Sure was quick.

However I haven’t been able to get it to work but going by the description and example you put, I don’t think it is the same functionality I was referring to. I downloaded TextMate and added the HTML Bundle in order to give you a visual example of what I mean:

Tabs to Table Example in TextMate

Click the magnifying glass on the bottom right corner of the video so that you can see it better.

It is basically a command palate function that interprets the tabs and lines and converts them into a formatted HTML table.

That is really the ONLY thing I personally miss from TextMate. If Sublime had this feature it would be practically perfect in my view. I’ll give your plugin another try to see if I can get it to work. Thanks!

0 Likes

#6

Ah right, I completely missed the HTML bit. I was too excited! :blush:

0 Likes

#7

Hehe, no worries :stuck_out_tongue:

That functionality is part of TextMate’s HTML Bundle. I’ve read that there is some compatibility between TextMate and Sublime plugins, would it be possible to include this functionality in Sublime? When I open that specific command from the bundle in a text editor I see the following code:

[code]<?xml version="1.0" encoding="UTF-8"?>

beforeRunningCommand nop command #!/usr/bin/env ruby table = STDIN.readlines table = table.collect { |row| row.gsub(/\n/, '').split(/\t+/) } puts "<table>" table.each do |row| print "\t<tr>" row.each { |cell| print "<td>#{cell}</td>" } print "</tr>\n" end puts "</table>" input selection keyEquivalent ^~@T name tabs -> table output replaceSelectedText scope text.html uuid 8B7C5284-8665-408A-9EA5-469503B7EE54 [/code]

I honestly have no clue how one would begin but could that be turned into a sublime command?

0 Likes

#8

There is no compatibility between TextMate commands and Sublime. The stuff that’s compatible is syntaxes (.tmLanguage), color schemes (.tmTheme) and some settings files (*.tmPreferences). And even then there are some differences.

If it’s possible to make the separators a little more sophisticated, you’re all set:

beginning of table:


beginning of line:
end of table:

separator:

end of line:

(Support for headers would be quite a bit more complicated, I’d imagine.)

Alex

0 Likes

#9

jbrooksuk said the selector is completelly customizable, could it be done with a change in the plugin settings?

0 Likes

#10

The column separator is customizable. I’m not sure how easily it would be to add a “Wrap in HTML table” command to it.

0 Likes