Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 09-30-2020, 12:55 PM   #1
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,095
Karma: 18727053
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Keyboard Shortcut in Regex?

I'm still trying to figure out a way to convert text to Title Case without having to manually select the text each time....short of writing a plugin to include formulaic regex like Calibre uses.

I have TitleCase assigned as a keyboard shortcut (Ctrl+Space) and wondered if there was a way to use that shortcut in the 'replace' section of the regex...resulting in something like:

find: (?<=\<h2\>)(.*?)(?=\</h2\>)
replace: Ctrl+Space
Turtle91 is offline   Reply With Quote
Old 09-30-2020, 02:17 PM   #2
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
What's so special about the keyboard shortcut? I use the following saved search:

find: <h([\d]+)>(.)(.*)</h[\d]+>
replace: <h\1>\2\L\3</h\1>
hobnail is offline   Reply With Quote
Old 09-30-2020, 02:21 PM   #3
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
I'm certainly no regexp wizard; what's the ?<= at the beginning of the h2 match doing? And why do you have backslashes in front of the < and >?
hobnail is offline   Reply With Quote
Old 09-30-2020, 02:23 PM   #4
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
I'm so used to typing [\d]+ and I just noticed that I used it here; probably could remove the square brackets as well as the plus sign.

find: <h(\d)>(.)(.*)</h\d>

But at least I'm ready for when the HTML standard adds an h10 tag.

Last edited by hobnail; 09-30-2020 at 02:25 PM.
hobnail is offline   Reply With Quote
Old 09-30-2020, 02:29 PM   #5
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,552
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by hobnail View Post
I'm certainly no regexp wizard; what's the ?<= at the beginning of the h2 match doing? And why do you have backslashes in front of the < and >?
That's a regex lookbehind.
He's just escaping the the angle brackets with the backslash--though there's no real reason to since they aren't regex metacharacters to begin with.

How does your regex deal with more than one word between the h tags?

Last edited by DiapDealer; 09-30-2020 at 02:42 PM.
DiapDealer is online now   Reply With Quote
Old 09-30-2020, 02:45 PM   #6
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
Quote:
Originally Posted by DiapDealer View Post
That's a regex lookbehind.
He's just escaping the the angle brackets with the backslash--though there's no real reason to since they aren't regex metacharacters to begin with.

How does your regex deal with more than one word between the h tags?
Duh, I missed that. I always do sentence case, never title case unless it's a proper name of someone/something.

Even though I was born and raised in the US I was taught that sentence case is better. E.g., see https://atmosol.com/resource-post/he...sentence-case/. Ease of regex construction for it is now another argument in its favor.

Last edited by hobnail; 09-30-2020 at 03:04 PM.
hobnail is offline   Reply With Quote
Old 09-30-2020, 03:22 PM   #7
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,095
Karma: 18727053
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Quote:
Originally Posted by DiapDealer View Post
That's a regex lookbehind.
He's just escaping the the angle brackets with the backslash--though there's no real reason to since they aren't regex metacharacters to begin with.

How does your regex deal with more than one word between the h tags?
lol - I actually was trying to get the lookarounds to work and forgot to remove the escapes after I found the actual problem

Yes, I am trying to get Title Case rather than Sentence case. This would be the first step, followed by a pass to change ' Of ', ' And ', ' The ', etc. to 'of, and, the. I'm sure there are plenty of other exceptions that I haven't come across yet...
Turtle91 is offline   Reply With Quote
Old 09-30-2020, 03:50 PM   #8
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,552
Karma: 14325282
Join Date: Nov 2019
Device: none
Quote:
Originally Posted by Turtle91 View Post
I'm sure there are plenty of other exceptions that I haven't come across yet...
Mine doesn't handle the occasional quoted phrase that is sometimes in a header.
hobnail is offline   Reply With Quote
Old 09-30-2020, 07:42 PM   #9
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,552
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
And to officially answer the original question: no. I'm afraid you can't fire off a keyboard shortcut with regex. I'd love to be able to say differently, but I can't.

And even a straight-up capitalize the first letter of every word (making sure everything else is lower-case) between two tags is going to very difficult to pull off with S&R regex alone.
DiapDealer is online now   Reply With Quote
Old 09-30-2020, 09:16 PM   #10
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by Turtle91 View Post
I have TitleCase assigned as a keyboard shortcut (Ctrl+Space) and wondered if there was a way to use that shortcut in the 'replace' section of the regex...resulting in something like:
There are a few solutions I see here.

1. Use Calibre's Functions. An example is even given in the manual:

"Automatically fixing the case of headings in the document"

2. AutoHotKey. If I want to "speed up" annoying shortcuts, I sometimes assign one of the extra buttons on my mouse.

For example, this AutoHotKey line:

Code:
XButton2::^q
assigns Ctrl+q to one of my side mouse buttons.

Then a (previously annoying) click+shortcut combo becomes a simple:

1. Left-Click
2. Side-Click
3. Left-Click
4. [...]

If you want to get fancy, you could even have AutoHotKey click the "Find" button for you too! Then all you have to do is keep pressing the side button!

Quote:
Originally Posted by hobnail View Post
Even though I was born and raised in the US I was taught that sentence case is better. E.g., see https://atmosol.com/resource-post/he...sentence-case/. Ease of regex construction for it is now another argument in its favor.
Don't know if you missed it, but there was quite a bit of Title Casing discussion in this topic a few months ago:

"Add title="" to h* based on existing TOC -- suggestion for new feature (or plugin?)"

Especially see my Posts #11, #13, and #15.

(I even spent a day writing up the ultimate "Title Casing: Everything You Didn't Know You Ever Wanted to Know" post... yet to be released though.*)

Quote:
Originally Posted by Turtle91 View Post
Yes, I am trying to get Title Case rather than Sentence case. This would be the first step, followed by a pass to change ' Of ', ' And ', ' The ', etc. to 'of, and, the. I'm sure there are plenty of other exceptions that I haven't come across yet...
Yes, lots of exceptions, especially in Chicago's rules.

But even with "easy" Sentence Case, you have to take into account things like:
  • Proper Names
  • Roman Numerals
  • Acronyms
  • Previous Punctuation
  • etc.

... It's all mentioned in my ultimate guide.*

- - - - -

(* If anyone's interested, I could send you the rough draft via PM... or you could wait until my blog gets rolling! )

Last edited by Tex2002ans; 10-01-2020 at 12:52 AM.
Tex2002ans is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
keyboard shortcut request rjwse@aol.com Calibre 3 10-17-2019 04:31 PM
keyboard shortcut request rjwse@aol.com Calibre 0 10-16-2019 12:05 PM
Keyboard Shortcut Fbone Calibre 4 11-03-2015 08:15 PM
Keyboard Shortcut for <li>? Rand Brittain Editor 7 02-25-2015 09:15 AM
Keyboard Shortcut: Rename CRB_Clive General Discussions 1 04-01-2014 01:32 PM


All times are GMT -4. The time now is 06:27 PM.


MobileRead.com is a privately owned, operated and funded community.