![]() |
#1 |
Enthusiast
![]() 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?
|
![]() |
![]() |
![]() |
#2 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
#5 |
Enthusiast
![]() 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?
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
#7 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#8 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#9 |
Enthusiast
![]() 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.
|
![]() |
![]() |
![]() |
Tags |
code, formating, sigil |
|
![]() |
||||
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 |