In bbedit there is a feature where you select the text, choose text->change case->make title case from the menu and it will act accordingly.
Is there a way to select multiple strings of text across files in your project then apply the same text formatting?
I know you can do some regex stuff and change it, but none of that is the true title case where it ignores the words like "of" "and" "the" etc. The title case works great, I just need to do it on many items.
For example 5 html files have <h2>THIS IS THE TITLE</h2>
-so now I go to each file select the text and do the above menu item. That is fine if there are 5, but if there are 2500 that I want to make <h2>This is the Title</h2>
- then I need to be able to select more than one at a time....
Thanks in advance!
------edits
So if you were searching across multiple files for all your <h2>
tags and you get back several across different files.....
<h2>MY TITLE</h2>
<h2>this is a title</h2>
<h2>Another title</h2>
The title case would change each of them accordingly to:
<h2>My Title</h2>
<h2>This is a Title</h2>
<h2>Another Title</h2>
Currently you select each one individually to do so via the menu. We'd like to do this with a find-all and change case if that makes sense....
F:<h2>(.*?)</h2>
R: <h2>\1</h2>
[make this a certain case]
Thanks.
Almost any operation which involves repetition in BBEdit can be automated using AppleScript. :-)
Here's the text of an AppleScript script which will perform the operation you describe. You can copy and paste this into the AppleScript editor, and save it in BBEdit's "Scripts" folder for future use as needed.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "BBEdit"
-- make sure we start at the top, because searches will (by default) proceed from the end of the selection range.
tell text of document 1 to select insertion point before first character
repeat
tell text of document 1
-- Find matches for a string inside of heading tags (any level)
-- NOTE extra backslashes in the search pattern to keep AppleScript happy
set aSearchResult to find "(<(h\\d)>)(.+?)(</\\2>)" options {search mode:grep}
end tell
if (not found of aSearchResult) then
exit repeat -- we're done
end if
-- the opening tag is the first capture group. We'll use this below
set openingTagText to grep substitution of "\\1"
-- the title is the third capture group
set titleText to grep substitution of "\\3"
-- use "change case" to titlecase the title
set changedTitleText to change case (titleText as string) making title case
-- select the range of text containing the title, so that we can replace it
set rangeStart to (characterOffset of found object of aSearchResult) + (length of openingTagText)
set rangeEnd to (rangeStart + (length of changedTitleText) - 1)
select (characters rangeStart through rangeEnd of text of document 1)
-- replace the range
set text of selection to changedTitleText
-- select found object of aSearchResult
end repeat
-- put the insertion point back at the top, because it's a nice thing to do
tell text of document 1 to select insertion point before first character
end tell