Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 12-16-2015, 04:28 AM   #1
sbin
Voracious reader
sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.
 
sbin's Avatar
 
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" />
Desidered result:
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.
sbin is offline   Reply With Quote
Old 12-16-2015, 05:19 AM   #2
rubeus
Banned
rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.rubeus ought to be getting tired of karma fortunes by now.
 
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
rubeus is offline   Reply With Quote
Advert
Old 12-16-2015, 06:04 AM   #3
sbin
Voracious reader
sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.
 
sbin's Avatar
 
Posts: 56
Karma: 14644
Join Date: Oct 2009
Device: Kobo Aura One, Sony PRS T2, iPhone 6, Cybook Orizon, Cybook Gen3
Quote:
Originally Posted by rubeus View Post
Doitso has written an AddID plugin as well that might help: https://www.mobileread.com/forums/sho...d.php?t=266120
Thanks, this is what I'm looking for!
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.
sbin is offline   Reply With Quote
Old 12-16-2015, 07:49 AM   #4
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,629
Karma: 5433388
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:
Originally Posted by sbin View Post
Thanks, this is what I'm looking for!
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.
KevinH is offline   Reply With Quote
Old 12-17-2015, 09:27 AM   #5
sbin
Voracious reader
sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.
 
sbin's Avatar
 
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
sbin is offline   Reply With Quote
Advert
Old 12-17-2015, 01:32 PM   #6
sbin
Voracious reader
sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.sbin is less competitive than you.
 
sbin's Avatar
 
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.
sbin is offline   Reply With Quote
Old 12-17-2015, 01:55 PM   #7
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,629
Karma: 5433388
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.
KevinH is offline   Reply With Quote
Old 12-18-2015, 04:43 PM   #8
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,583
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by sbin View Post
A minor glitch: it looks like the plugin added unwanted spaces around some inline tags (like <em>, <strong> and <span>, but not around <a>).
I haven't been able to reproduce this issue with the Windows version of Sigil 0.9.1 even when I selected an external interpreter. It looks like the plugin doesn't find the Sigil version of BS4, because the behavior matches that of Sigil 0.8.6.

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.')
(Make sure to match the indentation of the preceding line or Python will display an annoying error message.)
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:
Originally Posted by KevinH View Post
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.
Theoretically it should use the Sigil BS4 package whenever possible. The relevant code is the above-mentioned import declaration and the following, somewhat ugly code:

Spoiler:
Code:
                # update html if the code was changed
                if str(soup) != orig_soup:
                    if sys.version_info[0] == 2:
                        try:
                            bk.writefile(html_id, str(soup.prettyprint_xhtml(indent_level=0, eventual_encoding="utf-8", formatter="minimal", indent_chars="  ").encode('utf-8')))
                        except:
                            bk.writefile(html_id, str(soup.prettify().encode('utf-8')))
                    else:
                        try:
                            bk.writefile(html_id, str(soup.prettyprint_xhtml(indent_level=0, eventual_encoding="utf-8", formatter="minimal", indent_chars="  ")))
                        except:
                            bk.writefile(html_id, str(soup.prettify()))
                    print(bk.id_to_href(html_id) + ' updated')


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!
Doitsu is offline   Reply With Quote
Old 12-18-2015, 05:40 PM   #9
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,629
Karma: 5433388
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
KevinH is offline   Reply With Quote
Old 12-18-2015, 06:10 PM   #10
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,583
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by KevinH View Post
Or is there a newer version I should be testing with in a later post?
It appears that I ran my tests with a newer version than the one attached to the Incremental IDs topic.
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.
Doitsu is offline   Reply With Quote
Old 12-19-2015, 06:00 AM   #11
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,492
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
I have moved the discussion of empty spans to its own thread over here.
pdurrant is offline   Reply With Quote
Reply

Tags
html ebook, images, regex, regex sigil

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 02:35 PM.


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