![]() |
#1 |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: May 2025
Device: Apple iPad Pro
|
Sigil Prettify Code
Hi!
I want to know how do I change the way Prettify Code works, like no empty lines, <td> and </td> on the same line and stuffs like this. Anyone can teach me how to do it? Is there a plugin that does that? Thanks Ivan |
![]() |
![]() |
![]() |
#2 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,506
Karma: 5703586
Join Date: Nov 2009
Device: many
|
Sorry but, Sigil's built in Prettify has no user settable options. It does what it says.
You could of course write your own in python to create a plugin, but it is really tricky to cover all of the possible corner cases. |
![]() |
![]() |
![]() |
#3 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,321
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
I built a group of CLIPS Saved Searches that got almost all of the table elements organized how I liked.
I would highlight and mark the text (ctrl-shift-m) and then run the group. I called the group "Compress Table" and it put each <tr> on its own line with all of the <td>s in the same line. Looked something like this: Code:
<table> <thead> <tr><th>....</th><th>....</th><th>....</th><th>....</th></tr> </thead> <tbody> <tr><td>....</td><td>....</td><td>....</td><td>....</td></tr> <tr><td>....</td><td>....</td><td>....</td><td>....</td></tr> <tr><td>....</td><td>....</td><td>....</td><td>....</td></tr> <tr><td>....</td><td>....</td><td>....</td><td>....</td></tr> </tbody> <tfoot> <tr><td colspan="4">.....</td></tr> </tfoot> </table> ![]() EDIT: Sorry, I had clips on my brain… I should have said a group of saved searches. Last edited by Turtle91; 05-10-2025 at 10:31 PM. |
![]() |
![]() |
![]() |
#4 | |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: May 2025
Device: Apple iPad Pro
|
Quote:
|
|
![]() |
![]() |
![]() |
#5 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 810
Karma: 2416112
Join Date: Jan 2017
Location: Poland
Device: Various
|
The user indeed does not have access to customize the Prettify option, but if you would like to prepare your own version of Sigil and you have a lot of time then you can fight and modify this option or even create a new one to suit your needs.
However, if someone would like to play around, the relevant functions can be found in this file. Sample XHTML file before: Spoiler:
Sample XHTML file after: Spoiler:
Only for those interested in my changes (it can be optimized, but I leave it that way for code readability): Spoiler:
|
![]() |
![]() |
![]() |
#6 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,506
Karma: 5703586
Join Date: Nov 2009
Device: many
|
Nicely done! Effectively treating th, and td, as non-structural nodes only for layout.
Extra credit is available for designing a set of user settable options stored in a prettify.ini file (or xml file or json file or whatever is easier to access from C++) if found at the root of Sigil Preferences directory for this table modification and line spacing control. If it works and people are interested, I will add it. But note, speed with the GumboInterface is essential and critical as it is heavily used for updating any url when files are renamed. So looking for the prettify.ini file should be done only once at Sigil startup and somehow made readily available to gumbo without having to directly access any ini/json/xml file. It must also be multi-thread safe as Gumbo itself is run concurrently across multiple threads at once. Perhaps a new Singleton class can be created to parse the prettify ini/json/xml file on Sigil launch in main.cpp that Gumbo can call into each time to get variables to control those options on the fly in Gumbo just in that prettify routine so as not to slow things down in other speed critical gumbo routines. Also note that the gumbo prettify routine is re-entrant and is invoked recursively. In the end hard coding your own values in GumboInterface may be alot easier! Last edited by KevinH; 05-10-2025 at 05:02 PM. |
![]() |
![]() |
![]() |
#7 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 399
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Is there a way for a non-software coder to apply the "prettification" modules from older versions of Sigl (e.g. 0.7.2) to the current/future versions of it? Specifically, I'm trying to replicate the <br /> tag being honored in code view, too.
e.g. Code:
<p>Chapter<br /> One</p> Code:
<p>Chapter<br />One</p> |
![]() |
![]() |
![]() |
#8 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,506
Karma: 5703586
Join Date: Nov 2009
Device: many
|
Not really without coding it up and recompiling Sigil.
Easier to use search/replace to add a new line after each <br /> isn't it? |
![]() |
![]() |
![]() |
#9 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 399
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Is this the kind of thing that I could tie to "Run Automate List"? I have read the User's Guide entry and I'm still a little foggy on how it works in the context of running searches...
|
![]() |
![]() |
![]() |
#10 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,506
Karma: 5703586
Join Date: Nov 2009
Device: many
|
Look of Saved Searches and saved search groups. And yes an automate script can run any number of them.
But if all you want is to add a newline after every br tag you can do that with regular expressions or normal find and replace. A new line's unicode value is 10 decimal, so you can capture the br tag then replace it with a br tag and a new line char format using its hexidecimal representation. This can be done to insert any special character you want. Last edited by KevinH; 05-10-2025 at 06:57 PM. |
![]() |
![]() |
![]() |
#11 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 399
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Yeah, I'm thinking about other potential "prettification" operations. If there are several, it seems like tying them all to one of the Automations and assigning a shortcut might be most efficient.
Is that something that would work, or am I misunderstanding the use cases for the "Run Automate List" function? |
![]() |
![]() |
![]() |
#12 | |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,037
Karma: 168808719
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Quote:
For instance, I really dislike items in the ToC such as Chapter Thirty-Three. I also prefer to have the ToC built from a title="" rather than directly from the text in the header. I ended up with a saved search group that first adds the chapter header number to a title="Chapter ..." and then converts title="Chapter text number" to title="Chapter numeric number". I beat my head against the second part for a while and finally just brute-forced it by generating the search list outside Sigil and then importing it. So <h3>Thirty-Three</h3> ends up as <h3 title="Chapter 33">Thirty-Three</h3> giving me what I want in to ToC. Last edited by DNSB; 05-10-2025 at 07:05 PM. |
|
![]() |
![]() |
![]() |
#13 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,506
Karma: 5703586
Join Date: Nov 2009
Device: many
|
You do understand that Prettifying is not to make code that you "like" but to better make the underlying structure of the xhtml more apparent so further editing is easier to do (ie all structural tags properly indented on their own line with double spacing (much like a manuscript for manual proof reading. No e-reader user sees any of this. Spending time to modify code that makes no change in how users actually see the page is probably not very useful thing as long as it does not make the structure any more apparent or editing easier to do.
My 2 cents ... |
![]() |
![]() |
![]() |
#14 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 399
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Yes, I do understand that. In the case of the <br /> being followed by an actual break, that makes it easier for me to identify components of a particular element. Likewise, separating each table element into its own nested "paragraph" is also easier for me to parse and edit (although I can completely understand why the OP and Turtle91 might find a different nesting format easier to engage with).
I perfectly understand that how the code looks is not for the benefit of the consumer; it's for mine. |
![]() |
![]() |
![]() |
#15 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 399
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Incidentally, I just noticed that line-height css isn't reflected in either preview or PageEdit when applied to a <br> tag.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Code Hints in Sigil? | oston | Sigil | 3 | 04-09-2024 03:27 PM |
source code of sigil | Aymen Boss | Sigil | 6 | 07-18-2018 11:51 PM |
Collapse and expand code in Sigil | samirahmed007 | Sigil | 9 | 07-06-2017 09:44 AM |
Sigil code hints | kakkalla | Sigil | 12 | 05-13-2013 03:31 PM |
Are the SGC_# a sigil code? | JaneFancher | Sigil | 14 | 09-06-2010 04:08 AM |