DocumentText.h header
#include <ew/app/DocumentText.h>
Namespace ew::app
Functions
QString ew::app::document::documentPlainText(const QString &body)
Reduces a stored document body to the plain prose text used for word/character/readability/ dialogue analytics. The desktop editor stores a body as a full HTML document (QTextDocument::toHtml()), while importers and programmatic documents store plain Markdown; counting either directly would count the markup – tags, the <head>/<style> block, entities – as words. This detects an editor-authored HTML body (by the leading <!DOCTYPE that toHtml() always emits) and reduces it to visible text – dropping the head/style/script blocks, stripping tags, decoding the common entities, and collapsing whitespace – while returning a plain (non-HTML) body unchanged, so a literal "<x>" in Markdown prose is never stripped.
QString ew::app::document::documentPlainText(const ew::core::document::Document &document)
The same reduction, with document's BodyFormat tag consulted FIRST: a body is rich text because it is TAGGED Html, and one that does not happen to begin with a DOCTYPE would otherwise be returned with its markup intact. A body not tagged Html still goes through the string overload's own check, so this is a superset of it rather than an alternative – a body holding editor-authored HTML while tagged Markdown is a state that has occurred, and markup in front of a model or an analytics count helps nobody.
QString ew::app::document::documentPlainText(const QString &body, ew::core::document::BodyFormat format)
The same reduction for a body whose tag is held separately from any Document – a version snapshot or a variant draft, each of which carries its own BodyFormat because it can outlive the format of the document holding it.
QString ew::app::document::documentProseText(const ew::core::document::Document &document)
document's prose as a reader sees it – one step further than documentPlainText, which strips a legacy HTML body's markup but returns a Markdown body as stored, markers and all. A Markdown body is rendered and then reduced, so a link contributes its label and not its URL, a heading contributes its words and not its #, and emphasis contributes the word and not its asterisks.
Use this wherever the text is being judged as writing – a style pass, a readability score – because a crutch word inside a URL is not a crutch word a writer can fix, and a stylesheet is not a sentence. Word and character counts deliberately keep using documentPlainText: they answer "how much have I written", where a body's own markup is at least the writer's own typing.