Skip to content

Instantly share code, notes, and snippets.

@jshell
Created March 15, 2012 22:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jshell/2047480 to your computer and use it in GitHub Desktop.
Save jshell/2047480 to your computer and use it in GitHub Desktop.
Underline Titles (Markdown, reStructuredText) in BBEdit
tell application "BBEdit"
set x to startLine of selection
tell text 1 of window 1
if x = 1 then return
set myline to line x
set title_line to line (x - 1)
set underline_char to contents of first character of myline
set underline_str to ""
repeat (length of title_line) times
set underline_str to underline_str & underline_char
end repeat
make line at line x with data underline_str
delete line x
select insertion point after line x
end tell
end tell
@jshell
Copy link
Author

jshell commented Mar 15, 2012

I missed 'underline title' in the reStructuredText bundle for TextMate when I moved to BBEdit. With this script (I have it bound to 'control-shift-T'), the first character on the current line is made as an underline for the previous line, turning this:

Example Title Line
=

To this:

Example Title Line
==================

Any other characters on the 'underline line' are removed. This can be used to re-sync the underline to the length of the title if it changes (either longer or shorter).

This is the most AppleScript that I've ever written that does something real. It's a bit ugly, but it works, and makes writing lots of documentation in reStructuredText easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment