View Single Post
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