Created
March 15, 2012 22:54
-
-
Save jshell/2047480 to your computer and use it in GitHub Desktop.
Underline Titles (Markdown, reStructuredText) in BBEdit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
To this:
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.