Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 12-15-2024, 10:01 AM   #1
perkin5
Enthusiast
perkin5 began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Sep 2014
Device: Kindle
Code Formatter

I am surprised that there is no plugin to automatically format/prettify code for Sigil like for Vscode. At least I can't find one. Do others want that functionality available?
perkin5 is offline   Reply With Quote
Old 12-15-2024, 10:26 AM   #2
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,733
Karma: 5703586
Join Date: Nov 2009
Device: many
It is built into Sigil. Just use Sigil's Mend and Prettify.

Our sigil_bs4 also has a code prettifier for plugins to use.

Code:
def prettyprint_xhtml(self, indent_level=0, eventual_encoding=DEFAULT_OUTPUT_ENCODING,
                          formatter="minimal", indent_chars="  "):

Last edited by KevinH; 12-15-2024 at 10:30 AM.
KevinH is offline   Reply With Quote
Advert
Old 12-15-2024, 10:33 AM   #3
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,733
Karma: 5703586
Join Date: Nov 2009
Device: many
Of course you can easily create your own code prettifier in python if these are not flexible or suitable. Be careful of which tags you can compress space in and which you can not to be 100% safe.

Just check out the routines we added in our sigil_bs4 code and extract and change them as desired.

Last edited by KevinH; 12-15-2024 at 10:38 AM.
KevinH is offline   Reply With Quote
Old 12-15-2024, 08:13 PM   #4
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,542
Karma: 204127028
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Also please note that Sigil is not -- nor is it intended to be -- a fully featured, multi-language code editor like VSCode. That's why the Open With feature exists. So that those who need/want such code editing features can use their favorite editor to manipulate the code in their epubs.
DiapDealer is offline   Reply With Quote
Old 12-20-2024, 04:29 AM   #5
perkin5
Enthusiast
perkin5 began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Sep 2014
Device: Kindle
Hi KevinH, I've never heard of Sigil_bs4. Can you tell me about it?
perkin5 is offline   Reply With Quote
Advert
Old 12-20-2024, 12:09 PM   #6
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 45,895
Karma: 168959602
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Take a look at Beautiful Soup for the documentation on what Beautiful Soup is.
DNSB is offline   Reply With Quote
Old 12-20-2024, 12:11 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: 8,733
Karma: 5703586
Join Date: Nov 2009
Device: many
It is part of Sigil's standard python library. Back when plugin support was first added, it was clear that plugins would need xhtml/html5 parsing support. So we forked the original bs4 that was still python 2 only, and created our own version that would support both python2 and python3 and we added in routines to support xhtml parsing and pretty printing among other things.

It lives inside the Sigil tree here:

https://github.com/Sigil-Ebook/Sigil...thon/sigil_bs4

And it is available for every plugin to use by just importing sigil_bs4 just like the remainder of the built-in tools and modules we make available for plugins in every version of Sigil:
pip3 install six
pip3 install html5lib
pip3 install lxml
pip3 install Pillow
pip3 install regex
pip3 install css-parser
pip3 install cssselect
pip3 install chardet
pip3 install certifi
pip3 install urllib3
pip3 install dulwich

There is also support for hunspll spellchecking for plugins, a version of our fast forked gumbo parser, quickparser, opf parser, etc. And of course all of the Qt Gui elements from PySide6 (including a full QtWebEngine).

All of these should be available to every Sigil plugin, but some silly linux distributions call them "extras" and do not include them but they have no concept about what Sigil really is and how plugin support is done. We really wish they would stop doing that (breaking our standard toolset for installed plugins).

Last edited by KevinH; 12-20-2024 at 03:54 PM.
KevinH is offline   Reply With Quote
Old 12-20-2024, 12:15 PM   #8
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,733
Karma: 5703586
Join Date: Nov 2009
Device: many
FYI - Real bs4 has added some things our sigil_bs4 does not support but the overlap is over 90%. Most bs4 code will run unchanged under sigil_bs4.

So many people who use BeautifulSoup4 in their plugins will use:

import sigil_bs4 as bs4
KevinH is offline   Reply With Quote
Old 12-27-2024, 03:30 AM   #9
perkin5
Enthusiast
perkin5 began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Sep 2014
Device: Kindle
Hi Kevin H, Thanks so much for a very helpful rundown on sigil_bs4. Quite remarkable how much good work has been done. I will pursue.
perkin5 is offline   Reply With Quote
Reply

Tags
code, formating, sigil


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
EPUB3 Footnote Fixer-Formatter WiseGuru ePub 21 02-11-2024 04:19 PM
Any Interest in Formatter for Catalog CSV? Gary_M_Mugford Library Management 0 08-21-2013 11:38 AM
Mobi formatter wanted AlexBell Kindle Formats 4 04-19-2011 05:34 AM
Antenna House Formatter canes816 Calibre 1 04-01-2010 12:46 AM
iLiad RFCToiLiad formatter application scotty1024 iRex Developer's Corner 0 10-16-2006 12:56 PM


All times are GMT -4. The time now is 01:50 PM.


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