Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 05-09-2025, 06:21 PM   #1
iMilazzo
Junior Member
iMilazzo began at the beginning.
 
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
iMilazzo is offline   Reply With Quote
Old 05-09-2025, 06:42 PM   #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,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.
KevinH is online now   Reply With Quote
Old 05-09-2025, 11:17 PM   #3
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
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>
I'd place a copy of the clips group here for you, but my hard drive recently crashed and I lost everything..."Where's my backup?" you ask.... Great question...apparently one of my grandkids thought it was fun to play frisby with the standalone drives in my desk drawer... Anyway, I haven't gotten around to rebuilding that particular group.

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.
Turtle91 is offline   Reply With Quote
Old 05-09-2025, 11:42 PM   #4
iMilazzo
Junior Member
iMilazzo began at the beginning.
 
Posts: 2
Karma: 10
Join Date: May 2025
Device: Apple iPad Pro
Quote:
Originally Posted by Turtle91 View Post
I built a group of CLIPS 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>
Yeah, this is exactly what I need !!!
iMilazzo is offline   Reply With Quote
Old 05-10-2025, 04:20 PM   #5
BeckyEbook
Guru
BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.
 
BeckyEbook's Avatar
 
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:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
</head>

<body>
  <h1>Chapter</h1>

  <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>
</body>
</html>


Sample XHTML file after:
Spoiler:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
</head>
<body>
  <h1>Chapter</h1>
  <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>
</body>
</html>


Only for those interested in my changes (it can be optimized, but I leave it that way for code readability):
Spoiler:
Code:
    // Handle the general case
    std::string results;
    std::string starttag = "<" + tagname +  atts + ">";
    std::string closetag = "</" + tagname + ">";

    if (is_structural) {
        if (tagname == "td" || tagname == "th") {
            results = starttag;
        } else {
            results = indent_space + starttag;
        }
        if (!contents.empty()) {
            if (tagname == "td" || tagname == "th") {
                ltrim(contents);
                results.append(contents);
            } else if (tagname == "tr") {
                replace_all(contents, "\n\n", "");
                results.append(contents);
            } else {
                results.append("\n" + contents + "\n" + indent_space);
            }
        }
        if (tagname == "td" || tagname == "th") {
            results.append(closetag);
        } else {
            results.append(closetag + "\n");
        }
        // if (!in_head && (tagname != "html")) results.append("\n");
    } else if (is_inline) {
        results = starttag;
        results.append(contents);
        results.append(closetag);
    } else /** all others */ {
        results = indent_space + starttag;
        if (!keep_whitespace) {
            ltrim(contents);
        }
        results.append(contents);
        results.append(closetag + "\n");
        // if (!in_head && (tagname != "html")) results.append("\n");
    }
    return results;
BeckyEbook is offline   Reply With Quote
Old 05-10-2025, 04:42 PM   #6
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,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.
KevinH is online now   Reply With Quote
Old 05-10-2025, 05:52 PM   #7
ElMiko
Addict
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
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>
instead of

Code:
<p>Chapter<br />One</p>
ElMiko is offline   Reply With Quote
Old 05-10-2025, 06:01 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,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?
KevinH is online now   Reply With Quote
Old 05-10-2025, 06:12 PM   #9
ElMiko
Addict
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
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...
ElMiko is offline   Reply With Quote
Old 05-10-2025, 06:16 PM   #10
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,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.
KevinH is online now   Reply With Quote
Old 05-10-2025, 06:26 PM   #11
ElMiko
Addict
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
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?
ElMiko is offline   Reply With Quote
Old 05-10-2025, 07:02 PM   #12
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,037
Karma: 168808719
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by ElMiko View Post
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?
For me, I would collect those search/replace operations into a saved search group and run them by clicking on the group name. I don't think you could add a search to an automation list since the add to automation list only shows Sigil builtin tools and plugins.

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.
DNSB is offline   Reply With Quote
Old 05-10-2025, 07:04 PM   #13
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,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 ...
KevinH is online now   Reply With Quote
Old 05-10-2025, 09:14 PM   #14
ElMiko
Addict
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
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.
ElMiko is offline   Reply With Quote
Old 05-11-2025, 06:22 AM   #15
ElMiko
Addict
ElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileReadElMiko has read every ebook posted at MobileRead
 
ElMiko's Avatar
 
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.
ElMiko is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 05:27 PM.


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