MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   Incremental IDs plugin (https://www.mobileread.com/forums/showthread.php?t=266120)

Doitsu 10-08-2015 09:35 AM

Incremental IDs plugin
 
3 Attachment(s)
[Plugin] AddIDs - Generates incremental ids

Updated: April 17, 2021
Current Version: "0.4.5"

Note: Starting with version 0.3, the plugin will no longer automatically process all files. You'll need to select the file(s) to be processed in the Book View browser or click the Text folder to process all .xhtml files.

This very simple beautifulsoup4 based plugin can be used to add incremental ids to specific tags. You can either select all tags of a specific type or only tags with specific attributes and values. (If you specify an attribute, you'll also need to specify a value.)

For example, if you only enter p in the Tag box and click OK, the plugin will add incremental IDs to all paragraph tags in the .xhtml file currently selected in the Book Browser window (or all .xhtml files, if the Text folder is selected).
If you enter span, class and footnote, the plugin will add incremental IDs only to span tags that have a footnote class attribute.

For example,

Code:

<span class="footnote">...</span>
<span class="footnote">...</span>

will be changed to:

Code:

<span class="footnote" id="id1">...</span>
<span class="footnote" id="id2">...</span>

If you also select the Use Roman numerals option, the plugin will convert the counter value to upper-case Roman numerals. Since the Roman numerals converter can only handle numbers from 1 to 3999, this option should only be used for heading tags, page numbers etc. You also may want to clear the ID: value, since Roman numerals are by default valid IDs without a letter prefix. (Regular IDs need to be prefixed by at least one letter.)

Version 0.4.4 also allows you to add title attributes with consecutive numbers. For example, if you enter h1 as the tag, Chapter as the title prefix and check both check-boxes, h1 tags will be changed from:

Code:

<h1>How it all began</h1>
to:
Code:

<h1 id="idI" title="Chapter I">How it all began</h1>
(This feature allows you to update the TOC without changing the actual chapter headings since h1-h6 title attributes take precedence over h1-h6 tag contents when the TOC is generated.)

Installation:

If you're using Sigil 0.8.7 (or an older version), you'll need to install either Python 2.7 or Python 3.4 and beautifulsoup4. (Otherwise select the Use Bundled Python option.)

To install the plugin open Sigil and select:

Plugins > Manage Plugins > Add Plugin > AddIDs_0.4.5.zip > OK.

Version 0.4.4 requires Sigil 0.9.8 or higher. If you have an older Sigil version, you'll need to download version 0.3.0.

Usage:

To run the plugin select:

Plugins > Edit > AddIDs.

License: GNU General Public License v3 (GPL-3)

KevinH 10-08-2015 11:19 AM

Hi Doitsu,

Added this to the Sigil Plugin Index Thread.

Thanks!

KevinH

sbin 12-16-2015 07:00 AM

Hi Doitsu,
thanks for your plugin. I've tried using it, but I get a different dialog than yours:
http://s12.postimg.org/m0nq8lr2h/Sch...e_11_25_52.jpg

If I click on "start" (I can't do anything else), I get this error:
Code:

Status: failed

Traceback (most recent call last):
  File "/Applications/Sigil.app/Contents/plugin_launchers/python/launcher.py", line 134, in launch
    target_script = __import__(script_module)
  File "/Users/Sabrina/Library/Application Support/sigil-ebook/sigil/plugins/AddIDs/plugin.py", line 15, in <module>
    from tkinter import Tk, BOTH, StringVar, IntVar, BooleanVar
  File "/Applications/Sigil.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 38, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: dlopen(/Applications/Sigil.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload/_tkinter.so, 2): Library not loaded: /Library/Frameworks/Tcl.framework/Versions/8.6/Tcl
  Referenced from: /Applications/Sigil.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload/_tkinter.so
  Reason: image not found
Error: dlopen(/Applications/Sigil.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload/_tkinter.so, 2): Library not loaded: /Library/Frameworks/Tcl.framework/Versions/8.6/Tcl
  Referenced from: /Applications/Sigil.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload/_tkinter.so
  Reason: image not found

What am I doing wrong?


(I'm using Sigil 0.9.1 on OSX 10.11.1 and I have installed Python 3.5 and beautifulsoup 4.4.1)

Doitsu 12-16-2015 07:48 AM

Quote:

Originally Posted by sbin (Post 3224711)
Hi Doitsu,
thanks for your plugin. I've tried using it, but I get a different dialog than yours:

That's the default plugin runner dialog box.

It looks like you're missing the tkinter library or parts thereof. If the OSX Sigil version has a Use Bundled Python option in the Manage Plugins dialog box, please activate it. That should take care of all library issues.

If that doesn't work either, you'll probably have to install the tkinter Python library. However, before you do this, please wait for KevinH's reply; he has a Mac and will most likely be able to give you a better answer.

(To exclude plugin-specific bugs, please also install another tkinter-based plugin, e.g. the epub3 output plugin. If that plugin doesn't work either, it's definitely a tkinter issue.)

KevinH 12-16-2015 08:45 AM

Hi,
Yes, it seems your Mac OSX python is missing pieces. If you go to the Sigil Release page you will see a Note for Mac OS users to download and install the ActiveState's ActiveTCL free community edition. Once you have that installed, please use the Manage Plugins menu and check the UseBundled Python box. That will allow Sigil to load and use tk properly.
Please let me know if you run into any difficulties.

KevinH

sbin 12-17-2015 10:26 AM

I've installed ActiveTCL and now it's working properly. Thanks :)

KevinH 12-17-2015 02:58 PM

Hi Doitsu,

FYI soup.prettify() will insert newlines around all tags even inline tags which can mess things up. That is why we added serialize_xhtml and prettyprint_xhtml to our own sigil_bs4.

Thanks!

KevinH

Doitsu 12-17-2015 07:30 PM

Quote:

Originally Posted by KevinH (Post 3225619)
FYI soup.prettify() will insert newlines around all tags even inline tags which can mess things up. That is why we added serialize_xhtml and prettyprint_xhtml to our own sigil_bs4.

Thanks for the information. If the bundled interpreter is selected, the plugin will actually use the following soup.prettyprint_xhtml() command:

Code:

bk.writefile(html_id, str(soup.prettyprint_xhtml(indent_level=0, eventual_encoding="utf-8", formatter="minimal", indent_chars="  ")))
Based on the output this seems to pretty much mimic the pretty printing that Sigil does.

KevinH 12-17-2015 07:39 PM

Hi Doitsu,
By checking the launcher version dates to make sure it is at least Sigil 0.8.900 you could have it use sigil_bs4 for even for an external python 2.7 or 3.4 interpreter.

Version AddIDs v0.2 does not include this code change yet, right?

Doitsu 12-18-2015 04:03 AM

Quote:

Originally Posted by KevinH (Post 3225751)
Version AddIDs v0.2 does not include this code change yet, right?

No, it doesn't. I'll look into this the next time I update the plugin.

roger64 01-18-2016 08:36 AM

Hi

I did try your plugin on an Sigil 9.2 archlinux 64 bits. As advised, I installed python-beautifulsoup4.

It works nicely and is pretty useful. :thanks:

I have two proposals:

1. - It worked with paragraphs. It did not work with a link tags. Could you add them to your plugin? They all have an id...

2. - Another suggestion: Would it be possible to target only one file within the EPUB (a chapter, whatever)? The same as for any regex that can be used on current file and all text files.

Doitsu 01-18-2016 08:50 AM

Quote:

Originally Posted by roger64 (Post 3242333)
1. - It worked with paragraphs. It did not work with a link tags. Could you add them to your plugin? They all have an id...

It works for me. If you start the plugin and enter a in the Tag box, leave everything else empty and click OK, ids will be added to all <a> tags.

Quote:

Originally Posted by roger64 (Post 3242333)
2. - Another suggestion: Would it be possible to target only one file within the EPUB (a chapter, whatever)

This feature will be added in the next version. It'll only process files selected in the Book Browser window.

roger64 01-18-2016 10:52 AM

Good to know. My a tags had also a class. Thanks. :thumbsup:

Doitsu 02-02-2016 04:30 PM

The plugin has been updated to use sigil_bs4 for pretty printing and will only process the file(s) currently selected in the Book Browser window.

Note that the plugin UI hasn't been updated, i.e., you'll need to select the file(s) that you want to process in the Book Browser window, before running the plugin. (Click the Text folder in the Book Browser window to process all files.)

exaltedwombat 08-27-2017 11:38 AM

Not a snarky question at all - but why would I want to do this?


All times are GMT -4. The time now is 07:09 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.