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

QTextHtmlExporter invalid HTML attribute on <pre> tag

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P5: Not important
    • None
    • 4.8.1
    • GUI: Text handling
    • None

    Description

      If you have a QTextDocument that includes a QTextBlockFormat which sets non-breakable lines:

      QTextBlockFormat   fooBlockFormat;
      fooBlockFormat.setNonBreakableLines( true );
      

      ...then QTextHtmlExporter will generate HTML like this for the block:

         <pre align="center" style="...
      

      which is invalid HTML since the <pre> tag doesn't define an align attribute. While this actually works correctly in some browsers (Chrome) it doesn't work in others (Firefox), so text alignment is incorrect.

      This is set in QTextHtmlExporter::emitAlignment() which simply adds the align attribute to the current element:

      void QTextHtmlExporter::emitAlignment(Qt::Alignment align)
      {
          if (align & Qt::AlignLeft)
              return;
          else if (align & Qt::AlignRight)
              html += QLatin1String(" align=\"right\"");
          else if (align & Qt::AlignHCenter)
              html += QLatin1String(" align=\"center\"");
          else if (align & Qt::AlignJustify)
              html += QLatin1String(" align=\"justify\"");
      }
      

      Possible fix: this could just be changed to use style="text-align:XXX", but I'm not sure if there are other elements which require the actual align attribute.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            asm Andy M
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes