Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old Yesterday, 07:37 PM   #31
byword
Enthusiast
byword began at the beginning.
 
Posts: 42
Karma: 10
Join Date: Apr 2022
Device: Onyx Leaf 3
How about improving the Text search feature in the search options?

The Text search option is a feature that "does not search tags." When this option is enabled, it ignores the tags themselves and only searches the text content inside them. However, it cannot properly search for text that is split by tags.


<p>Sigil <b>Text Search</b></p>

With markup like this, it cannot find "Sigil Text Search".
I think this option would be much more useful if checking the Text search option ignored tags completely, allowing it to find "Sigil Text Search".
byword is offline   Reply With Quote
Old Yesterday, 07:53 PM   #32
byword
Enthusiast
byword began at the beginning.
 
Posts: 42
Karma: 10
Join Date: Apr 2022
Device: Onyx Leaf 3
Could you please add the 'Rebase OPF Manifest IDs on Current filenames' feature to the Add Automate tool? I run this before delivering the final file, but I often forget to do it. I'd like to add it to my final check automation list.
byword is offline   Reply With Quote
Old Yesterday, 08:50 PM   #33
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: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
@BeckyEbook,

Okay, I will look into what changes that would take. If we add a DOCTYPE and or xml header, we would still want to mark that Book as modified just so that people know they need a save or save-as even if they make no changes themselves.

Last edited by KevinH; Yesterday at 08:54 PM.
KevinH is online now   Reply With Quote
Old Yesterday, 09:00 PM   #34
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: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by byword View Post
Could you please add the 'Rebase OPF Manifest IDs on Current filenames' feature to the Add Automate tool? I run this before delivering the final file, but I often forget to do it. I'd like to add it to my final check automation list.
Yes, as others may be interested in that as well, and it is a very minor change.
KevinH is online now   Reply With Quote
Old Yesterday, 10:48 PM   #35
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: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by byword View Post
How about improving the Text search feature in the search options?

The Text search option is a feature that "does not search tags." When this option is enabled, it ignores the tags themselves and only searches the text content inside them. However, it cannot properly search for text that is split by tags.


<p>Sigil <b>Text Search</b></p>

With markup like this, it cannot find "Sigil Text Search".
I think this option would be much more useful if checking the Text search option ignored tags completely, allowing it to find "Sigil Text Search".
No, that text does not exist in that sequence in the file. You misunderstand, that Text search checkbox was added to prevent inadvertent text replacements from changing things **inside** tags (such as tag names, attribute names, attribute values, etc).

If you want a pure text search, strip out all tags first and search but you can then forget getting any accurate positional information.

That is not something for Sigil.

Last edited by KevinH; Yesterday at 10:55 PM.
KevinH is online now   Reply With Quote
Old Today, 12:30 AM   #36
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 22,964
Karma: 34252880
Join Date: Mar 2012
Location: Sydney Australia
Device: none
PageEdit will find 'Sigil Text Search' in

Code:
<p>Sigil <b>Text Search</b></p>
Click image for larger version

Name:	pageedit.jpg
Views:	22
Size:	248.6 KB
ID:	227849

The calibre book editor has a simple Find feature for its Preview window which finds it too, never used it before now.

Click image for larger version

Name:	calibre preview.jpg
Views:	20
Size:	223.4 KB
ID:	227850

BR
BetterRed is online now   Reply With Quote
Old Today, 03:52 AM   #37
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,945
Karma: 24444443
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by BeckyEbook View Post
@KevinH, thanks for looking into this. IMHO (and I think that's what Doitsu meant too) the issue was never the DOCTYPE itself – I'm always for a correct file, so let it be added automatically. It's only about the warning on load: I knowingly want the DOCTYPE, I just don't need to be told about it every time
You read my mind. I just find the warning annoying. Since most commercial epubs still don't have a DOCTYPE, it's an extra message box that I need to click each time I open those books.
Doitsu is offline   Reply With Quote
Old Today, 08:34 AM   #38
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: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by BetterRed View Post
PageEdit will find 'Sigil Text Search' in

Code:
<p>Sigil <b>Text Search</b></p>
Attachment 227849

The calibre book editor has a simple Find feature for its Preview window which finds it too, never used it before now.

Attachment 227850

BR
Yes that is a DOM node search not a file based search. It is built into QtWebEngine.
KevinH is online now   Reply With Quote
Old Today, 08:45 AM   #39
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: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by Doitsu View Post
You read my mind. I just find the warning annoying. Since most commercial epubs still don't have a DOCTYPE, it's an extra message box that I need to click each time I open those books.
But like Becky you do not want the fix to be gumbo based right?

The slight complication is the xml header must come absolutely first in an xhtml file but multiple xhtml comments are legal *before* any DOCTYPE. So regular expressions would have to be used to search for any xml header and DOCTYPE and the correct sequence used to put back only what is missing and in the correct order without losing any xhtml comments.

This is trivial with gumbo and reserializing the parsed tree and gumbo is completely thread safe so it can be parallelized.
KevinH is online now   Reply With Quote
Old Today, 10:32 AM   #40
BeckyEbook
Wizard
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: 1,104
Karma: 4000789
Join Date: Jan 2017
Location: Poland
Device: Various
@KevinH, right, I'd prefer a plain text insertion over gumbo, simply because it's the smallest possible change: a Checkpoint Compare would show just the added line(s) and nothing else.

I don't think the comments make it complicated though. The XML prolog allows comments both before and after the doctypedecl, so nothing needs to be found or reordered:
  • xml header missing -> prepend it (it must be first anyway, so nothing can precede it)
  • DOCTYPE missing -> insert it right after the xml header; any comments simply end up after the DOCTYPE, which is still valid

The QXmlStreamReader pass in WellFormedErrorForSource already tells us which of the two is missing, so the only regex needed is one anchored at the start for the xml header. And it's a pure QString function, so it parallelizes just as well.

If you think this approach is worth a try, I could give it a go this evening and put together a patch for you to look at. I can't promise it'll be ready today though, as each Sigil build takes about 10 minutes on my machine, and I'd like to test it properly with both epub2 and epub3 first. But if you'd rather go with gumbo, that's absolutely fine with me too: the important part for me is just no warning :)
BeckyEbook is offline   Reply With Quote
Old Today, 10:41 AM   #41
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,945
Karma: 24444443
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by KevinH View Post
But like Becky you do not want the fix to be gumbo based right?
Yes, I don't want you to modify gumbo at all; I just want to be able to suppress the annoying missing DOCTYPE warning.
Doitsu is offline   Reply With Quote
Old Today, 12:22 PM   #42
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: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by BeckyEbook View Post
@KevinH, right, I'd prefer a plain text insertion over gumbo, simply because it's the smallest possible change: a Checkpoint Compare would show just the added line(s) and nothing else.

I don't think the comments make it complicated though. The XML prolog allows comments both before and after the doctypedecl, so nothing needs to be found or reordered:
  • xml header missing -> prepend it (it must be first anyway, so nothing can precede it)
  • DOCTYPE missing -> insert it right after the xml header; any comments simply end up after the DOCTYPE, which is still valid

The QXmlStreamReader pass in WellFormedErrorForSource already tells us which of the two is missing, so the only regex needed is one anchored at the start for the xml header. And it's a pure QString function, so it parallelizes just as well.

If you think this approach is worth a try, I could give it a go this evening and put together a patch for you to look at. I can't promise it'll be ready today though, as each Sigil build takes about 10 minutes on my machine, and I'd like to test it properly with both epub2 and epub3 first. But if you'd rather go with gumbo, that's absolutely fine with me too: the important part for me is just no warning
My idea was a new CleanSource routine to pre-process the source file before going to the well formed check (assuming Mend on Open is enabled). Then checking for xmlheader and doctype can work as is.

I will try to put something together today to handle this in CleanSource that takes care of it using QRegularExpressions limited to the source code before the opening html (to prevent spurious matches after the html tag (as in a commented out doctype, etc).

I will push something for testing when I have something.
KevinH is online now   Reply With Quote
Old Today, 02:03 PM   #43
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: 56,116
Karma: 183211710
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by Doitsu View Post
You read my mind. I just find the warning annoying. Since most commercial epubs still don't have a DOCTYPE, it's an extra message box that I need to click each time I open those books.
Oddly, I've found the opposite. A majority of the commercial ePubs I open in an editor either from a major publisher or a independent have a DOCTYPE and ?xml line as part of the header. Possibly due to targeting ePub2 and ePub3 renderers?

I am tempted by the idea of having this automagically fixed but then my paranoia about not knowing what changes were made says don't do it.
DNSB is online now   Reply With Quote
Old Today, 02:19 PM   #44
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: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
Hi All,

For testing only by those who build their own, I have pushed a change to master that if Mend On Open is enabled (checked), the xml header and or the doctype if missing will be fixed via regular expressions (no full parse and serialization).

The only thing this change can do is fill in those two missing pieces.

The key code can be found in CleanSource::FixPreamble in Sigil/src/BookManipulation/CleanSource.cpp.

It is applied in a QtConcurrent initial load of each html file for speed but only if Mend On Open is checked.

I have attached the critical piece of code here in case people are interested.
It should be understandable by anyone familiar with regular expressions. Note, before searching a copy of the source is made and all comments are replaced by an equal number of spaces so that later searches can not be confused by html tags or doctypes inside comments.

This is just for searching, no comments are removed from the actual xhtml.

Code:
static const QString XML_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
static const QString EPUB3_DOCTYPE = "<!DOCTYPE html>\n\n";
static const QString EPUB2_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n  \"http://www.w3.org/TR/xhtml11/DTD\
/xhtml11.dtd\">\n\n";
static const QString XML_HEADER_RE = "^\\s*<\\?xml\\b[^>]*\\?>\\s*";
static const QString HTML_TAG_RE = "<\\s*html[\\s/]+";
static const QString DOCTYPE_TAG_RE = "<!DOCTYPE\\s*";



// use regular expressions to add xml header and doctype to xhtml source code                                          
QString CleanSource::FixPreamble(const QString& source, const QString& version)
{
    const QRegularExpression html_tag_search(HTML_TAG_RE, QRegularExpression::CaseInsensitiveOption);
    const QRegularExpression xml_header_search(XML_HEADER_RE, QRegularExpression::CaseInsensitiveOption);
    const QRegularExpression doctype_tag_search(DOCTYPE_TAG_RE, QRegularExpression::CaseInsensitiveOption);
    const QRegularExpression comment_search("<!--.*\?-->", QRegularExpression::DotMatchesEverythingOption);

    // start by masking all comments with spaces                                                                       
    QString masked_source = source;
    QRegularExpressionMatchIterator it = comment_search.globalMatch(source);
    QList<QRegularExpressionMatch> matches;
    while (it.hasNext()) {
        matches.append(it.next());
    }
    for (auto i = matches.crbegin(); i != matches.crend(); ++i) {
        masked_source.replace(i->capturedStart(), i->capturedLength(), QString(i->capturedLength(), QLatin1Char(' ')))\
;
    }

    // search for start location of first html tag in source to limit spurious results                                 
    int html_start = -1;
    QRegularExpressionMatch html_mo = html_tag_search.match(masked_source, 0);
    if (!html_mo.hasMatch()) return source;
    html_start = (int)html_mo.capturedStart(0);

    // check for xml header and if present remember end                                                                
    int xmlheader_end = -1;
    bool has_xml_header = false;
    QRegularExpressionMatch xml_mo = xml_header_search.match(masked_source, 0);
    if (xml_mo.hasMatch()) {
        xmlheader_end = xml_mo.capturedEnd(0);
        has_xml_header = true;
    }

    // check for doctype                                                                                               
    QRegularExpressionMatch dtd_mo = doctype_tag_search.match(masked_source, 0);
    bool has_doctype = false;
    if (dtd_mo.hasMatch()) {
        if (html_start > (int) dtd_mo.capturedStart(0)) {
            has_doctype = true;
        }
    }

    QString DOCTYPE_TAG;
    if (version.startsWith("3")) {
        DOCTYPE_TAG = EPUB3_DOCTYPE;
    } else {
        DOCTYPE_TAG = EPUB2_DOCTYPE;
    }

    QString nsource;
    if (has_xml_header && has_doctype) {
        nsource = source;
    }
    if (has_xml_header && !has_doctype) {
        // inject doctype immediately after xml_header                                                                 
        nsource = source.left(xmlheader_end) + DOCTYPE_TAG + source.mid(xmlheader_end, -1);
    }
    if (!has_xml_header && has_doctype) {
        // prepend the xml header                                                                                      
        nsource = XML_HEADER + source;
    }
    if (!has_xml_header && !has_doctype) {
        // prepend the xml header and doctype                                                                          
        nsource = XML_HEADER + DOCTYPE_TAG + source;
    }
    return nsource;
}
Update: The Book is not yet marked as modified if FixPreamble actually makes a change, so that is still on my To-Do list if we decide to go this direction.

The code is fresh and only tested a few times so there may still be a few nits in it.

All feedback welcome.

Last edited by KevinH; Today at 02:23 PM.
KevinH is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Features or Improvements post Sigil 2.8.1 KevinH Sigil 155 10-03-2026 07:16 PM
Improvements? New Features? post sigil 2.7.6 KevinH Sigil 315 05-23-2026 11:40 AM
Suggestions for Sigil Improvements or New Features KevinH Sigil 241 03-02-2026 02:09 PM
Suggestions for Sigil Improvements or New Features KevinH Sigil 168 11-18-2025 01:23 PM
Hello. Where do I make suggestions for future improvements? spelunker Sigil 19 02-28-2022 12:46 PM


All times are GMT -4. The time now is 02:47 PM.


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