iasilikon.blogg.se

Bbedit pretty json
Bbedit pretty json








bbedit pretty json bbedit pretty json

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










Bbedit pretty json