![]() |
#1 |
Bookish
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,017
Karma: 2003162
Join Date: Jun 2011
Device: PC, t1, t2, t3, Clara BW, Clara HD, Libra 2, Libra Color, Nxtpaper 11
|
regex question
The new regex-function works great, the section numbering was just something what I needed. However, I stumbled onto some expressions which were not handled properly:
Code:
<h1 class="center"><a href="chapter001.xhtml#start">Test</a></h1> <h1 class="center" id="" ><span class="something">Test</span></h1> <h1 class="center" id="" ><b><span class="something">Test</span></b></h1> Code:
(<h1[^<>]*>)([^<>]+</h1>) ![]() Can somebody teach me how to select "just enough"? |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,339
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
(<h1[^<>]*>)(.+?</h1>)
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Bookish
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,017
Karma: 2003162
Join Date: Jun 2011
Device: PC, t1, t2, t3, Clara BW, Clara HD, Libra 2, Libra Color, Nxtpaper 11
|
I was sooo close ...
![]() Anyway, thanks Kovid ![]() Humble suggestion: Update the manual with this version as I'm afraid the examples I provided will likely to be encountered by many more users. |
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,339
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Well, this expression will not match if the heading tag is split over multiple lines, for that you need:
(?s)(<h2[^<>]*>)(.+?</h2>) |
![]() |
![]() |
![]() |
#5 |
Bookish
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,017
Karma: 2003162
Join Date: Jun 2011
Device: PC, t1, t2, t3, Clara BW, Clara HD, Libra 2, Libra Color, Nxtpaper 11
|
Indeed! Although not very common, constructs like this do happen:
Code:
<h1 class="center"><a href="Section003.xhtml#start">Test</a><br/> Some sub header</h1> |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,046
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
![]() I use a similar one a Lot when I want the Chapter Title to appear in the TOC Code:
<h2 class="CN">- 1 - <br /><span class="CT">A New Year</span></h2> |
|
![]() |
![]() |
![]() |
#7 | |
Connoisseur
![]() Posts: 67
Karma: 10
Join Date: Apr 2011
Device: Kindle 3, Samsung Tab 4
|
Quote:
I'm not saying it doesn't have it's place but using it for spacing is not recommended. That's what margins/padding are for. This Code:
<h1 class="center"><a href="Section003.xhtml#start">Test</a><br/> Some sub header</h1> Code:
<h1 class="center"><a href="Section003.xhtml#start">Test</a></h1> <h2 class="center">Some sub header</h2> Whether this has an specific relevance to e-publishing is perhaps questionable but 'poor' code is something to be noted even if we choose to use it for own own reasons. Understand I'm not running anyone down for it...just expressing one man's opinion. |
|
![]() |
![]() |
![]() |
#8 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,046
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Test Some Sub header (both are essentially the same location)is not what is desired in a TOC, especially on a smaller screen |
|
![]() |
![]() |
![]() |
#9 | |
Connoisseur
![]() Posts: 67
Karma: 10
Join Date: Apr 2011
Device: Kindle 3, Samsung Tab 4
|
Quote:
That said, couldn't a function be written to combine two distinct elements into a single TOC item? Dunno, just asking..I'm still a novice at regex. Regardless, the TOC 'link' would still be the same point (the H1) so you'd still arrive at the same place wouldn't you? |
|
![]() |
![]() |
![]() |
#10 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,561
Karma: 204127028
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
In this case, the br tag is not being used to achieve any kind of spacing or padding. It's being used as it was intended--to simply make sure the text that follows starts on a new line.
|
![]() |
![]() |
![]() |
#11 |
Bookish
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,017
Karma: 2003162
Join Date: Jun 2011
Device: PC, t1, t2, t3, Clara BW, Clara HD, Libra 2, Libra Color, Nxtpaper 11
|
@Paulie_D: It is what I see in epubs, not what I have created myself. Sometimes you have to deal with what you have, and that is almost never what you really want. But I mostly can live with it given it just appears acceptable enough on my trusted e-reader
![]() (And if not, then there is always calibre ... ![]() |
![]() |
![]() |
![]() |
#12 |
Connoisseur
![]() Posts: 67
Karma: 10
Join Date: Apr 2011
Device: Kindle 3, Samsung Tab 4
|
Please...I wasn't suggesting anyone here was doing anything wrong here just trying to make a general point.
Guess I did it badly. ![]() |
![]() |
![]() |
![]() |
#13 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 119
Karma: 64428
Join Date: Aug 2011
Device: none
|
Regarding multi-line titles and auto TOC:
My preference is to have smaller-sized subtitles, to clearly point them out as subordinate to the main title. So, a typical set of headings would look like: Code:
<h2>Main heading</h2> <h3>Subtitle</h3> Code:
<h2 title="Main heading: Subtitle">Main heading</h2> <h3 class="sigil_not_in_toc">Subtitle</h3> |
![]() |
![]() |
![]() |
#14 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,561
Karma: 204127028
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
Yes, using br tags to create spacing between paragraphs or different sections is considered bad form. But surely, using the br tag to force a line break is why the br tag exists in the first place, no? ![]() |
|
![]() |
![]() |
![]() |
#15 | |
Connoisseur
![]() Posts: 67
Karma: 10
Join Date: Apr 2011
Device: Kindle 3, Samsung Tab 4
|
Quote:
So in your example, it's correct because the number and title are intended to be a single item but for visual purposes it needs to look like two lines. In the other example a major heading and sub-heading would not be intended to be a single item and so "should" be two items. |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
RegEx question (again) | phossler | Sigil | 12 | 01-20-2013 02:37 PM |
A regex question | PatNY | Sigil | 30 | 06-03-2012 02:03 PM |
Yet another regex question | Jabby | Sigil | 8 | 01-30-2012 08:41 PM |
Regex question and maybe some help | crutledge | Sigil | 9 | 03-10-2011 04:37 PM |
Regex Question | Archon | Conversion | 11 | 02-05-2011 10:13 AM |