|
|
#31 |
|
Enthusiast
![]() 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". |
|
|
|
|
|
#32 |
|
Enthusiast
![]() 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.
|
|
|
|
|
|
#33 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
|
|
|
|
|
#34 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
|
Yes, as others may be interested in that as well, and it is a very minor change.
|
|
|
|
|
|
#35 | |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
|
Quote:
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. |
|
|
|
|
|
|
#36 |
|
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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> The calibre book editor has a simple Find feature for its Preview window which finds it too, never used it before now. BR |
|
|
|
|
|
#37 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,945
Karma: 24444443
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
|
|
|
|
|
|
|
#38 | |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
|
Quote:
|
|
|
|
|
|
|
#39 | |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
|
Quote:
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. |
|
|
|
|
|
|
#40 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
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 :) |
|
|
|
|
|
#41 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,945
Karma: 24444443
Join Date: Dec 2010
Device: Kindle PW2
|
|
|
|
|
|
|
#42 | |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,337
Karma: 7640672
Join Date: Nov 2009
Device: many
|
Quote:
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. |
|
|
|
|
|
|
#43 | |
|
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 56,116
Karma: 183211710
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Quote:
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. |
|
|
|
|
|
|
#44 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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;
}
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. |
|
|
|
![]() |
|
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 |