![bbedit bbedit](https://raw.githubusercontent.com/ogham/Rust-BBEdit/master/screenshots.png)
Looking at the script, I realize that none of the regular expressions are necessary. The -p option is one of those time-saving Perlisms that eliminates the need to write a line-reading-and-writing loop. A Python script would’ve been longer but no clearer. I wrote it in Perl because Perl is particularly good at this sort of thing. Here it is: perl:Ĥ: $n = s/\t/\|/g # tabs to pipes, saving the countĨ: # Add the formatting line above the second line.ĩ: printf "|". The script is saved in ~/Dropbox/Application Support/BBEdit/Text Filters/Tabs to Markdown Īnd is assigned a keyboard shortcut of ⌃⌥⌘⇥ (that last one is the Tab key). Not sure why I didn’t put that in the TextMate version in the first place. Even though I have to add them by hand, that’s still faster than adding the whole line by hand.
![bbedit bbedit](https://cdn.osxdaily.com/wp-content/uploads/2017/12/install-sf-mono-fonts-mac.jpg)
![bbedit bbedit](https://tidbits.com/uploads/2020/10/BBEdit-13.5-rescue-untitled.jpg)
You’ll note that the formatting line doesn’t have any colons to indicate alignment. I rewrote this script from scratch because I knew it would be short and I wanted to add the formatting line, which the TextMate version didn’t include. Where the triangles represent tab characters, to this |Left align|Right align|Center align| In other words, I wanted to go from this Left align△Right align△Center align The other script I wanted was the one that turns a table with tab-separated columns-what you get when you paste a table from a spreadsheet into a text editor-into the pipe-separated MultiMarkdown table format. I’ve given it a keyboard shortcut of ⌃⌥⌘T, the same shortcut it had in TextMate. The minimum width willħ3: # be 2, because that's the shortest length of a formatting string andħ4: # because that matches an empty column with "bumper" spaces.ħ8: widths = max(len(row), widths)Ĩ0: # Add whitespace to make all the columns the same width andĨ3: formatted.append('|' + '|'.join() + '|')Ĩ5: # Recreate the format line with the appropriate column widths.Ĩ6: formatline = '|' + '|'.join( + '-'*(n-2) + s for (s, n) in zip(justify, widths) ]) + '|'Ĩ8: # Insert the formatline back into the table.Ĩ9: formatted.insert(formatrow, formatline)ĩ5: # Read the input, process, and print. Here’s the script: python:Ħ: "Justify a string to length n according to type."ġ9: "Aligns the vertical bars in a text table."Ģ1: # Start by turning the text into a list of lines.ģ3: # Delete the separator line from the content.ģ6: # Determine how each column is to be justified.ģ8: if formatline = '|': formatline = formatlineģ9: if formatline = '|': formatline = formatlineĥ1: # Assume the number of columns in the separator line is the numberĦ2: # Put exactly one space at each end as "bumpers."Ħ3: linecontent = Ħ6: # Append cells to rows that don't have enough.ħ2: # Get the width of the content in each column. Which put it in BBEdit’s Text▸Apply Text Filter submenu. I just grabbed the script and saved it to ~/Dropbox/Application Support/BBEdit/Text Filters/Normalize Table.py Was, fortunately, written entirely in Python and had no TextMate-specific features. The more complicated of these, the one that reformats a MultiMarkdown-style table that looks like this |Left align|Right align|Center align|Īnd turns it into this | Left align | Right align | Center align | It wasn’t until this past week that I found myself wishing I had a couple of scripts from my old Text Tables bundle. This turned out to be good motivation there’s nothing like having to do a repetitive task by hand to inspire you to automate it the first chance you get. Unsurprisingly, these situations often arose when I was on a deadline and didn’t have time to stop and rewrite an old script. Instead, I’d rewrite them as needed, waiting until I ran into a situation that really called out for one of my old scripts. Not by continuing to use TextMate for some tasks-that’s a recipe for never switching at all-but by refusing to rewrite all my customizations right away. So when I switched to BBEdit a few months ago, I decided to make the transition slowly. The only thing more daunting than the thought of giving them up was the thought of rewriting them for another editor. This is one of the reasons it took me so long to make the move away from TextMate in six years of use, I’d accumulated a passel of commands, snippets, and specialty language definitions. The more you customize your editor, the harder it is to switch to another one. Next post Previous post Markdown table scripts for BBEdit