![]() |
#1 |
Member
![]() Posts: 19
Karma: 10
Join Date: Apr 2015
Device: Kobo Aura H2O 2ed
|
![]()
Hallo, my friends.
I would like a regex to insert images automatically in my epub. I mean: having "Fig. 1.1" and similiar "Fig. 1.2" (and so on until "Fig. 99.99") I would like to "translate" in: "<a href="../Images/Fig 1.1.jpg">Fig. 1.1</a> " and so on.... could you help me? Thanks in advance! ![]() |
![]() |
![]() |
![]() |
#2 | |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 44,836
Karma: 168802811
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Quote:
Code:
Find: <b>Fig\. (.*?)</b> Replace: <b><img alt="Fig. \1" class="whatever" src="../Images/Fig \1.jpg"/>Fig. \1</b> Code:
<p><b>Fig. 1.1</b></p> <p><b>Fig. 1.2</b></p> <p><b>Fig. 2.1</b></p> <p><b>Fig. 2.4</b></p> <p><b>Fig. 49.3</b></p> <p><b>Fig. 99.72</b></p> Code:
<p><b><img alt="Fig. 1.1" class="whatever" src="../Images/Fig 1.1.jpg"/>Fig. 1.1</b> </p> <p><b><img alt="Fig. 1.2" class="whatever" src="../Images/Fig 1.2.jpg"/>Fig. 1.2</b> </p> <p><b><img alt="Fig. 2.1" class="whatever" src="../Images/Fig 2.1.jpg"/>Fig. 2.1</b> </p> <p><b><img alt="Fig. 2.4" class="whatever" src="../Images/Fig 2.4.jpg"/>Fig. 2.4</b> </p> <p><b><img alt="Fig. 49.3" class="whatever" src="../Images/Fig 49.3.jpg"/>Fig. 49.3</b> </p> <p><b><img alt="Fig. 99.72" class="whatever" src="../Images/Fig 99.72.jpg"/>Fig. 99.72</b> </p> Last edited by DNSB; 05-21-2020 at 01:30 PM. |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Also, just to warn: spaces in filenames aren't a good idea.
So if you adjust DNSB's to: Replace: <img alt="Fig. \1" class="whatever" src="../Images/Fig\1.jpg"/> that would get you: Code:
<img alt="Fig. 2.4" class="whatever" src="../Images/Fig2.4.jpg"/> I would then recommend using Sigil's mass renaming to fix the filenames. Follow steps 3 and 4 in this little tutorial I wrote back in 2019. |
![]() |
![]() |
![]() |
#4 |
Member
![]() Posts: 19
Karma: 10
Join Date: Apr 2015
Device: Kobo Aura H2O 2ed
|
after applying also suggestions about blanks in file names, I tried but the result is not what I'm trying to do.
I need to translate code as: <div> <p>vedi Fig._3.1 e Fig._10.6), allora si può. </p> </div> into <div>vedi Fig._3.1) <p> <img alt="Fig_3.1" src="../Images/Fig_3.1.jpg" style="font-size: 1em;"/>e Fig._10.6), <img alt="Fig_10.6" src="../Images/Fig_10.6.jpg" style="font-size: 1em;"/>allora si può. </p> </div> This is an extract (complete) from the original epub: https://mega.nz/file/MP5WSSzZ#VL6BKb...Qf8WUsz3yfcB0U ![]() |
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Oh, I see. I was reading DNSB's post and thinking you wanted to insert an actual image.
Now that I'm taking a closer look at Post #1: Search: Fig\._([\d\.]+) Replace: <a href="../Images/Fig_\1.jpg">Fig._\1</a> That will get you what you "want". BUT!!! Linking directly to an image file won't work on an actual ereader (it doesn't even work in ADE). You will want to point to the figure's location within the book, for example: Chapter01.xhtml: Code:
<p class="figuretitle">Figure 3.1</p> <div class="image"> <img alt="Figure 3.1" id="Fig3.1" src="../Images/Fig_3.1.jpg"/> </div> Code:
<p>As you can see in <a href="../Text/Chapter01.xhtml#Fig3.1">Fig 3.1</a>, the cat is brown.</p> Last edited by Tex2002ans; 05-23-2020 at 03:02 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,312
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
Edit - DOH - Ninja'd again...
Try - Code:
search: <div>\s*<p>(.*?) Fig._(.*?) e Fig._(.*?)\), (.*?).</p>\s*</div> replace: <div class="images">\n<p>\1 Fig._\2)<img alt="Fig_\1" src="../Images/Fig_\1.jpg" /></p>\n<p>e Fig._\3),<img alt="Fig_\3" src="../Images/Fig_\3.jpg" />\4.</p>\n</div> Code:
<div class="images"> <p>vedi Fig._3.1)<img alt="Fig_3.1" src="../Images/Fig_3.1.jpg"/></p> <p>e Fig._10.6),<img alt="Fig_10.6" src="../Images/Fig_10.6.jpg"/>allora si può.</p> </div> You should avoid inline styling whenever possible (don't put 'style="..." ' in your tags). Instead, put the styling in a CSS file and refer to it with class names like: CSS: Code:
.images p {text-align:center; font-size:1em; margin:0} .images img {display:block; margin:0 auto; width:90%; max-width:600px} |
![]() |
![]() |
![]() |
#7 |
Member
![]() Posts: 19
Karma: 10
Join Date: Apr 2015
Device: Kobo Aura H2O 2ed
|
Sorry, I'm really a donkey newbie and maybe I was non clear...
I want to insert directly the image, not the link to it and regex I'm looking for is one to translate: Code:
Fig._3.1 Code:
Fig._3.1 <img alt="Fig_3.1" src="../Images/Fig_3.1.jpg"/> Code:
Fig._10.6 Code:
Fig._10.6 <img alt="Fig_10.6" src="../Images/Fig_10.6.jpg"/> ![]() Last edited by Pippo53s03; 05-24-2020 at 09:55 AM. |
![]() |
![]() |
![]() |
#8 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,312
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
The <img alt="" src="..."/> tag IS the actual image...it is not a link. A link tag looks like <a href="">
Try it in Sigil and you will see the image magically appear in the Preview window. |
![]() |
![]() |
![]() |
#9 | |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,312
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
Quote:
That is a little different than what you had originally. Try: Code:
search: Fig._(.*?) replace: Fig._\1<img alt="Fig_\1" src="../Images/Fig_\1.jpg"/> Cheers! |
|
![]() |
![]() |
![]() |
#10 | |||
Member
![]() Posts: 19
Karma: 10
Join Date: Apr 2015
Device: Kobo Aura H2O 2ed
|
I tried this:
Quote:
Quote:
Quote:
Please, help! |
|||
![]() |
![]() |
![]() |
#11 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,908
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
you do NOT use the search term in the replace.
You use what was captured inside the ( ) by using \1 for the first No time for further but DO search MR for REGEX tutorials ( ![]() |
![]() |
![]() |
![]() |
#12 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,312
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
|
![]() |
![]() |
![]() |
#13 |
Member
![]() Posts: 19
Karma: 10
Join Date: Apr 2015
Device: Kobo Aura H2O 2ed
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to insert automatically valid id's in ToC headings? | chaot | Editor | 18 | 02-01-2017 06:55 AM |
How can insert a citation automatically? | calven | Calibre | 3 | 01-21-2016 05:30 AM |
How can insert a footnote automatically? | calven | Editor | 0 | 12-29-2015 07:52 PM |
Regex to insert word at beginning of a line | macnab69 | Library Management | 1 | 05-20-2013 02:56 AM |
Insert new line with regex | deckoff | Sigil | 6 | 08-08-2010 11:24 AM |