DocumentSearchText.h header

#include <ew/app/DocumentSearchText.h>

Namespace ew::app

Functions

QString ew::app::search::documentSearchText(const ew::core::document::Document &document)

The text of document a project-wide search should run over, decided by the document's BodyFormat tag.

A Markdown body is searched as stored, with its ![[…]] / [^id] markers collapsed to one character each so a project search's match order lines up with the editor. A legacy Html body is reduced to its visible prose first, so a search does not match attribute names and class values.

The tag, not a guess at the text. Qt::mightBeRichText is true for an ordinary Markdown body that merely opens with an HTML block – <div class="epigraph"> is legitimate Markdown – and treating that as rich text made the search report matches at offsets in stripped markup rather than in the prose the replace then edits (F-0086).

ReplaceOutcome ew::app::search::replaceInDocumentBody(const ew::core::document::Document &document, const QRegularExpression &regex, const QString &replacement)

Replaces every match of regex in document's body with replacement, in the body's own storage form, and reports the new body and the number of replacements.

A Markdown body is rewritten as text, so the markers and the diff-friendly store survive. A legacy Html body is edited through a QTextDocument, so run formatting survives and the replaced text inherits the match's format.

Which branch runs is decided by the document's tag. Guessing from the text converted a Markdown body into a full HTML document – DOCTYPE, <style> block and all – while leaving it tagged Markdown, so every export then shipped that boilerplate as visible prose and the chapter's on-disk file stopped being diff-friendly text (F-0086). The tag is never changed here: a Markdown body stays Markdown and an Html body stays Html, because a replacement does not change what kind of text a body is.