![]() |
#1 |
Voracious reader
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 56
Karma: 14644
Join Date: Oct 2009
Device: Kobo Aura One, Sony PRS T2, iPhone 6, Cybook Orizon, Cybook Gen3
|
how to assign an ID to every image
Hi guys,
to get my colophon data in order, I'm in need to assign an unique ID to every image in my ePub. Is there a quick way to do this either in Sigil or with a regular expression (I could unzip my ePub and then use Textwrangler or Oxygen)? Situation: Code:
<img src="somePath/random_filename.jpg" class="someClass" alt="someText" /> <img src="somePath/someother_filename.jpg" class="someClass" alt="someText" /> … <img src="somePath/another_filename.jpg" class="someClass" alt="someText" /> Code:
<img src="somePath/random_filename.jpg" class="someClass" alt="someText" id="image001" /> <img src="somePath/someother_filename.jpg" class="someClass" alt="someText" id="image002" /> … <img src="somePath/another_filename.jpg" class="someClass" alt="someText" id="image634" /> (Since I switched to mac, I had to renounce to Powergrep, that would be able to do this in a second. How I miss it ![]() Last edited by sbin; 12-16-2015 at 04:31 AM. |
![]() |
![]() |
![]() |
#2 |
Banned
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 272
Karma: 1224588
Join Date: Sep 2014
Device: Sony PRS 650
|
Hi,
regex do not have a counter so you cant use them here. I've written a AddMaxWidth Plugin which can be modfied to add an ID instead of adding a max-width style to an image. But this wil take the one or other day. Doitso has written an AddID plugin as well that might help: https://www.mobileread.com/forums/sho...d.php?t=266120 //Rubeus |
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Voracious reader
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 56
Karma: 14644
Join Date: Oct 2009
Device: Kobo Aura One, Sony PRS T2, iPhone 6, Cybook Orizon, Cybook Gen3
|
Quote:
Too bad it doesn't work for me as it's supposed to be. I've posted my issues in that same thread. In the meantime, I'm looking for other solutions. |
|
![]() |
![]() |
![]() |
#4 | |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,491
Karma: 5703586
Join Date: Nov 2009
Device: many
|
See my reply in that thread. You seem to be missing a version of ActiveState ActiveTCL free community edition. The version that comes with MacOS X is too old and buggy. The link to it is provided on the Sigil Release page. Then make sure you have checked the UseBundled Interpreter box in the Sigil Plugin Preferences.
Quote:
|
|
![]() |
![]() |
![]() |
#5 |
Voracious reader
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 56
Karma: 14644
Join Date: Oct 2009
Device: Kobo Aura One, Sony PRS T2, iPhone 6, Cybook Orizon, Cybook Gen3
|
I've installed ActiveTCL and now it works. Thank you
![]() |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Voracious reader
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 56
Karma: 14644
Join Date: Oct 2009
Device: Kobo Aura One, Sony PRS T2, iPhone 6, Cybook Orizon, Cybook Gen3
|
A minor glitch: it looks like the plugin added unwanted spaces around some inline tags (like <em>, <strong> and <span>, but not around <a>).
After adding an ID to every paragraph, I got: Code:
<h2><span>MACCHINE A VAPORE</span></h2> Code:
<h2> <span>MACCHINE A VAPORE</span> </h2> Code:
… che chiamò “<strong>astri medicei</strong>”, in onore di <strong>Cosimo II de’ Medici</strong>.</p> Code:
… che chiamò “ <strong>astri medicei</strong> ”, in onore di <strong>Cosimo II de’ Medici</strong> .</p> The code is easily fixable, and I spent less time struggling with the plugin than manually adding the IDs anyway ![]() Last edited by sbin; 12-17-2015 at 03:03 PM. |
![]() |
![]() |
![]() |
#7 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,491
Karma: 5703586
Join Date: Nov 2009
Device: many
|
Hi,
That is actually a bug in BeautifulSoup4's prettify() which inserts line breaks after every tag even if they are inline tags that impacts this plugin. If it instead used Sigil's own version of BeautifulSoup, sigil_bs4, it could use serialize_xhtml() or prettyprint_xhtml() which would prevent the introduction of newlines after inline tags. I will mention this to Doitsu and ask him if he would like to update the plugin. Thanks for your bug report. Kevin Last edited by KevinH; 12-17-2015 at 01:59 PM. |
![]() |
![]() |
![]() |
#8 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,687
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Did you tick the Use Bundled Python check box? If so, can you please open the AddIDs plugin.py file and add the lines marked in Magenta with TextWrangler or a similar programmer's editor. Code:
try: from sigil_bs4 import BeautifulSoup print('Sigil BS4 imported.') except: from bs4 import BeautifulSoup print('regular BS4 imported.') Then re-run your test. You should get a message telling you which BS4 library was imported. (You can find the plugin.py location via Edit > Preferences > Open Preferences Location > plugins > AddIDs.) Quote:
Spoiler:
Could you please test on your Mac which library is actually imported and whether selecting an external interpreter, e.g. Python 2.7, will cause the issues that the OP reported? Thanks! |
||
![]() |
![]() |
![]() |
#9 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,491
Karma: 5703586
Join Date: Nov 2009
Device: many
|
Hi,
I can recreate it with the forthcoming Sigil 0.9.2 on MacOSX with your AddIDs v0.2, as it only includes a call to prettyfy. There is no call to prettyprint_xhtml in AddIds v0.2 plugin.py. Perhaps you are using a newer version of the AddIds plugin than what is posted here in your thread in MR in the first post. Or is there a newer version I should be testing with in a later post? Thanks, KevinH Kevin |
![]() |
![]() |
![]() |
#10 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,687
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
I've attached a new version (0.3), that should use prettyprint_xhtml() where available. (To be on the safe side, I've also removed the regular BS4 prettyprint() function.) @sbin: Please download and test the updated version. It shouldn't insert unwanted spaces. |
|
![]() |
![]() |
![]() |
#11 |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73,678
Karma: 315126578
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Oasis
|
I have moved the discussion of empty spans to its own thread over here.
|
![]() |
![]() |
![]() |
Tags |
html ebook, images, regex, regex sigil |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Bulk assign of books to Collection | theant | Library Management | 0 | 04-03-2015 03:37 AM |
Assign KB shortcuts | phossler | Editor | 3 | 08-24-2014 09:42 AM |
How do I assign different colors to different sections of text? | krausj | ePub | 6 | 06-13-2013 11:42 AM |
Assign multiple books to a collection | NLight95 | Library Management | 1 | 03-31-2011 09:20 PM |
How do you assign categories?? | mrsp | Fictionwise eBookwise | 5 | 12-20-2007 12:20 PM |