diff options
author | Shawn Rutledge <[email protected]> | 2022-05-20 23:49:04 +0200 |
---|---|---|
committer | Shawn Rutledge <[email protected]> | 2022-06-11 14:18:35 +0000 |
commit | eee9d252028c4b3b743c77a406cd6939eda3962f (patch) | |
tree | badceeddc8a36c645faa0e6e9444dae764a0400e /src | |
parent | 88f5955cb750f2fe3468fe13fef4a11b887315c1 (diff) |
Use CSS classes on html list items for checkbox support
If we replace the bullet character with a UC checkbox character, it
looks ok in a browser, and the HTML parser can recover the BlockMarker
attribute from the css class.
[ChangeLog][QtGui][Text] Checkbox list items can now be read and written
in both HTML and Markdown, including conversions.
Task-number: QTBUG-103714
Change-Id: Ic6b74512075cd4ac16d6f80fdf55b221447491a9
Reviewed-by: Qt CI Bot <[email protected]>
Reviewed-by: Allan Sandfeld Jensen <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 16 | ||||
-rw-r--r-- | src/gui/text/qtexthtmlparser.cpp | 8 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 71511257f51..463026ed238 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2372,6 +2372,8 @@ QString QTextHtmlExporter::toHtml(ExportMode mode) html += "<style type=\"text/css\">\n"_L1; html += "p, li { white-space: pre-wrap; }\n"_L1; html += "hr { height: 1px; border-width: 0; }\n"_L1; + html += "li.unchecked::marker { content: \"\\2610\"; }\n"_L1; + html += "li.checked::marker { content: \"\\2612\"; }\n"_L1; html += "</style>"_L1; html += "</head><body"_L1; @@ -3038,7 +3040,7 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) html += " style=\""_L1; html += styleString; - html += "\">"_L1; + html += "\">\n"_L1; } html += "<li"_L1; @@ -3051,6 +3053,18 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) defaultCharFormat.merge(block.charFormat()); } + if (block.blockFormat().hasProperty(QTextFormat::BlockMarker)) { + switch (block.blockFormat().marker()) { + case QTextBlockFormat::MarkerType::Checked: + html += " class=\"checked\""_L1; + break; + case QTextBlockFormat::MarkerType::Unchecked: + html += " class=\"unchecked\""_L1; + break; + case QTextBlockFormat::MarkerType::NoMarker: + break; + } + } } const QTextBlockFormat blockFormat = block.blockFormat(); diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index a10b8808862..ded2dd185a5 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1636,6 +1636,14 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) } } break; + case Html_li: + if (key == "class"_L1) { + if (value == "unchecked"_L1) + node->blockFormat.setMarker(QTextBlockFormat::MarkerType::Unchecked); + else if (value == "checked"_L1) + node->blockFormat.setMarker(QTextBlockFormat::MarkerType::Checked); + } + break; case Html_a: if (key == "href"_L1) node->charFormat.setAnchorHref(value); |