bbedit - 如何将多个字符串更改为标题大小写?
bbedit - how to change multiple strings to title case?
在 bbedit 中,您可以 select 文本,从菜单中选择文本->更改大小写->制作标题大小写,它会相应地执行操作。
有没有办法 select 跨项目文件的多个文本字符串然后应用相同的文本格式?
我知道你可以做一些正则表达式的东西并改变它,但是 none 是真正的标题大小写,它忽略了像 "of" "and" [=41= 这样的词] 等等。title case 效果很好,我只需要在很多项目上做。
例如 5 html 个文件有 <h2>THIS IS THE TITLE</h2>
- 所以现在我转到每个文件 select 的文本并执行上面的菜单项。如果有 5 个就好了,但是如果我想制作 2500 个 <h2>This is the Title</h2>
- 那么我需要能够一次 select 不止一个....
提前致谢!
------编辑
因此,如果您在多个文件中搜索所有 <h2>
标签,并且您在不同的文件中找到了几个......
<h2>MY TITLE</h2>
<h2>this is a title</h2>
<h2>Another title</h2>
标题大小写将相应地更改为:
<h2>My Title</h2>
<h2>This is a Title</h2>
<h2>Another Title</h2>
目前,您 select 每个人都可以通过菜单单独执行此操作。我们想用 find-all 来做到这一点,如果有意义的话改变大小写....
F:<h2>(.*?)</h2>
R: <h2></h2>
[使这个成为某种情况]
谢谢。
几乎所有涉及 BBEdit 重复的操作都可以使用 AppleScript 自动执行。 :-)
这是将执行您描述的操作的 AppleScript 脚本的文本。您可以将其复制并粘贴到 AppleScript 编辑器中,并将其保存在 BBEdit 的 "Scripts" 文件夹中以备将来需要时使用。
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
在 bbedit 中,您可以 select 文本,从菜单中选择文本->更改大小写->制作标题大小写,它会相应地执行操作。
有没有办法 select 跨项目文件的多个文本字符串然后应用相同的文本格式?
我知道你可以做一些正则表达式的东西并改变它,但是 none 是真正的标题大小写,它忽略了像 "of" "and" [=41= 这样的词] 等等。title case 效果很好,我只需要在很多项目上做。
例如 5 html 个文件有 <h2>THIS IS THE TITLE</h2>
- 所以现在我转到每个文件 select 的文本并执行上面的菜单项。如果有 5 个就好了,但是如果我想制作 2500 个 <h2>This is the Title</h2>
- 那么我需要能够一次 select 不止一个....
提前致谢!
------编辑
因此,如果您在多个文件中搜索所有 <h2>
标签,并且您在不同的文件中找到了几个......
<h2>MY TITLE</h2>
<h2>this is a title</h2>
<h2>Another title</h2>
标题大小写将相应地更改为:
<h2>My Title</h2>
<h2>This is a Title</h2>
<h2>Another Title</h2>
目前,您 select 每个人都可以通过菜单单独执行此操作。我们想用 find-all 来做到这一点,如果有意义的话改变大小写....
F:<h2>(.*?)</h2>
R: <h2></h2>
[使这个成为某种情况]
谢谢。
几乎所有涉及 BBEdit 重复的操作都可以使用 AppleScript 自动执行。 :-)
这是将执行您描述的操作的 AppleScript 脚本的文本。您可以将其复制并粘贴到 AppleScript 编辑器中,并将其保存在 BBEdit 的 "Scripts" 文件夹中以备将来需要时使用。
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