Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75662

handle CSS styling for markdown format in QTextDocument / QTextBrowser

    XMLWordPrintable

Details

    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

          For Gerrit Dashboard: QTBUG-75662
          # Subject Branch Project Status CR V

          Activity

            People

              srutledg Shawn Rutledge
              srutledg Shawn Rutledge
              Votes:
              3 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change