MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / convertOlToParagraph

Function convertOlToParagraph

src/plugins/chat/widgets/messagecomponent.cpp:43–68  ·  view source on GitHub ↗

Due to the use of multiple DLabels to display text in this module, the ordered list is always parsed starting from 1. To avoid this issue, we have implemented some circumvention measures. */

Source from the content-addressed store, hash-verified

41 To avoid this issue, we have implemented some circumvention measures.
42 */
43QString convertOlToParagraph(const QString &input)
44{
45 QString result = input;
46
47 static QRegularExpression olRegex(
48 R"(<ol(?:\s+start="(\d+)\")?\s*>\s*<li>(.*?)</li>\s*</ol>)",
49 QRegularExpression::DotMatchesEverythingOption
50 );
51
52 QRegularExpressionMatch match = olRegex.match(input);
53 if (match.hasMatch()) {
54 QString startNum = match.captured(1);
55 QString content = match.captured(2);
56
57 QString replacement;
58 if (startNum.isEmpty()) {
59 replacement = QString("<p>1. %1</p>").arg(content);
60 } else {
61 replacement = QString("<p>%1. %2</p>").arg(startNum).arg(content);
62 }
63
64 result = result.replace(match.captured(0), replacement);
65 }
66
67 return result;
68}
69
70void MessageComponent::updateMessage(const MessageData &msgData)
71{

Callers 1

updateMessageMethod · 0.85

Calls 4

QStringClass · 0.50
matchMethod · 0.45
isEmptyMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected