View Single Post
Old 12-04-2015, 01:21 PM   #36
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: 8,893
Karma: 6120478
Join Date: Nov 2009
Device: many
Hi rubeus,

FYI, there are quite a few parsers available to you in a plugin. QuickParser, lxml, sigil_bs4 with html5lib, sigil_bs4 with lxml, sigil_bs4 with gumbo, etc. So simply have it walk all xhtml docs and parse them and get the image tag, and add the right attributes if needed, serialize it and continue.

Parsing with QuickParser is quite easy and using sigil_bs4 (html5lib, gumbo, lxml) to do the modifications and then serialize is easy too.

There really is no reason to do any of that manually when this is perfect for a plugin.

KevinH



Quote:
Originally Posted by rubeus View Post
The plugin runner window shows up clearly the break between Sigil itself and the plugins: A plugin isnt working on the data directly but on a copy which can be send back. If this wouldnt be so clear more peoplewill ask for a plugin working more integrated in Sigil (for example paste imagesa dn the workaround by doits works, but isnt really smoothly integrated,)

The only thing i miss a little bit is the possibility to insert code having some special attributes.

For example inserting images. I dont want them to blow up on hires screens over the "natural" size so i have a common code snippet and to make it individual to each image i'm applaying the with via inline stylesheet:

Code:
<div...>
<img ... style="max-width=xxxpx;" />
</div>
would be extremly helpful when this could be more automated. Currently i have a plugin creating an allpic html file containing the code snippets go each picture so i can copy & paste the code.

But when i remember the 034 and what was possible in former times...

ps. I see Doitsu has already beaten me to the punch with his solution. If you decide to use BS4, I would recommend the serialize_xhtml call in sigil_bs4 over the prettyprint_xhtml call since the serialize call will make fewer changes to the source code (ie. is less likely to introduce errors from incorrect pretty-printing).

Last edited by KevinH; 12-04-2015 at 01:25 PM.
KevinH is offline   Reply With Quote