Details
-
Task
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
Description
I investigated how CSS styling works for HTML. QTextHtmlParser::parseTag() calls QTextHtmlParserNode::applyCssDeclarations() and the result is that QTextHtmlParserNode::charFormat and blockFormat will be modified. QTextHtmlImporter::import() will then apply those changes while calling QTextHtmlImporter::appendBlock() etc. The result is the documented limitation in QTextDocument::setDefaultStyleSheet(): "Changing the default style sheet does not have any effect to the existing content of the document."
In order to support CSS for formatting both HTML and Markdown with reusable code, and also to remove that limitation, we probably need to refactor it to iterate all document nodes and apply CSS styles to them. But this is difficult because of the way that QTextDocument is not a DOM: it mostly doesn't remember which types of HTML tags go with which QTextBlocks etc. In 310daae53926628f80c08e4415b94b90ad525c8f for example I made it remember the <Hx> heading that was declared, in addition to setting default font sizes for headings. Next, markdown rewriting support depends on remembering <blockquote>s and <code> blocks in a similar way (by adding more attributes to the QTextBlock). But there are probably a few more cases like that, that need to be done before we will be able to apply a CSS stylesheet later on, after the parsing is already done and we only have a QTextDocument.
Otherwise, maybe we should make it into a DOM. I suppose Konqueror must have done something like that early on, when they first got started and ran into the same problem.
Attachments
Issue Links
- is required for
-
QTBUG-112384 QGraphicsTextItem: Markdown formatting reduces multiple newlines to one
- Closed
-
QTBUG-30634 Indent of a quote in QTextDocument is very small
- Closed
- relates to
-
QTBUG-68671 Qt Stylesheet Qt6 refactoring
- Reported
-
QTBUG-97530 render vertical bars alongside blockquotes
- Reported
-
QTBUG-115253 Request for MarkdownSyntaxHighlighter QML type
- Reported
-
QTBUG-100218 Add Interface to QTextDocument to add Undo Commands to previous stack
- Reported
- resulted from
-
QTBUG-72349 QTextDocument markdown parsing
- Closed
Gerrit Reviews
For Gerrit Dashboard: QTBUG-75662 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
262305,7 | WIP teach QTextDocument::setDefaultStyleSheet() to restyle at runtime | dev | qt/qtbase | Status: NEW | -2 | 0 |