14using namespace Qt::Literals::StringLiterals;
18 static const QRegularExpression tag(u"</?@[^>]*>"_s);
19 QString t = markedCode;
20 t.replace(tag, QString());
21 t.replace(u"""_s, u"\""_s);
22 t.replace(u">"_s, u">"_s);
23 t.replace(u"<"_s, u"<"_s);
24 t.replace(u"&"_s, u"&"_s);
31 case Genus::CPP:
return u"cpp"_s;
32 case Genus::QML:
return u"qml"_s;
33 case Genus::DOC:
return u"doc"_s;
34 case Genus::API:
return u"api"_s;
35 case Genus::DontCare:
return {};
47 const QStringList &args = atom->strings();
48 const QString directive = args.size() > 1 ? args.at(1) : QString();
49 return Sorting::parseSortOrder(directive) == Qt::DescendingOrder
50 ? u"descending"_s : u"ascending"_s;
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
133
134
135
136
137
138
139
140
141
142
143
144
145
147 DiagnosticHandler diagnosticHandler)
148 : m_briefHandling(briefHandling), m_headingOffset(headingOffset),
173
174
175
176
177
178
179
180
185 m_inlinePath.clear();
186 m_inlineBaseDepths.clear();
193 processAtoms(firstAtom);
197 while (!m_blockPath.isEmpty())
199 m_inlinePath.clear();
200 m_inlineBaseDepths.clear();
208
209
210
211
212
217 atom = skipFormatIfBlock(atom);
224 atom = dispatchAtom(atom);
232
233
234
235
236
237
238
239
240
241
242
243
249 while (atom && depth > 0) {
260
261
262
263
272 if (m_briefHandling == BriefHandling::Include)
273 openBlock(BlockType::Paragraph);
288 openBlock(BlockType::Paragraph);
296 addLeafInline(InlineType::Text, atom->string());
300 addLeafInline(InlineType::Code, stripCodeMarkerTags(atom->string()));
308 attrs[
"language"_L1] = u"qml"_s;
310 attrs[
"language"_L1] = u"text"_s;
311 attrs[
"bad"_L1] =
true;
312 }
else if (atom->count() >= 2 && !atom->string(1).isEmpty()) {
313 attrs[
"language"_L1] = atom->string(1);
315 attrs[
"language"_L1] = u"cpp"_s;
318 openBlock(BlockType::CodeBlock, attrs);
319 addLeafInline(InlineType::Text, stripCodeMarkerTags(atom->string()));
333 link.href = atom->string();
336 const auto *linkAtom =
static_cast<
const LinkAtom *>(atom);
338 linkAtom->location.filePath(),
339 linkAtom->location.lineNo()
342 link.children.append({
InlineType::Text, atom->string(), {}, {}, {}, {}, {} });
343 addInline(
std::move(link));
349 if (m_blockPath.isEmpty())
350 openBlock(BlockType::Paragraph);
356 link.href = atom->string();
362 auto *mutableAtom =
const_cast<
Atom *>(atom);
364 QString genusStr = genusToString(genus);
365 if (!genusStr.isEmpty())
366 link.attributes[
"linkGenus"_L1] = genusStr;
367 if (Tree *domain = mutableAtom->domain())
368 link.attributes[
"linkModule"_L1] = domain->physicalModuleName();
369 if (
int flags = mutableAtom->flags())
370 link.attributes[
"linkFlags"_L1] = flags;
372 const auto *linkAtom =
static_cast<
const LinkAtom *>(mutableAtom);
374 linkAtom->location.filePath(),
375 linkAtom->location.lineNo()
379 pushInlineContainer(
std::move(link));
391 const QString &fmt = atom->string();
405 pushInlineContainer(
std::move(bold));
409 InlineType type = formattingToInlineType(fmt);
414 container
.type = type;
415 pushInlineContainer(
std::move(container));
420 const QString &fmt = atom->string();
424 const qsizetype base = m_inlineBaseDepths.isEmpty() ? 0 : m_inlineBaseDepths.last();
425 if (m_inlinePath.size() > base) {
427 m_inlinePath.removeLast();
439 const qsizetype base = m_inlineBaseDepths.isEmpty() ? 0 : m_inlineBaseDepths.last();
440 if (m_inlinePath.size() > base)
441 m_inlinePath.removeLast();
445 case Atom::SectionLeft:
446 openBlock(BlockType::Section);
455 attrs[
"level"_L1] = atom->string().toInt() + m_headingOffset;
459 if (atom->count() >= 2)
460 attrs[
"sectionRef"_L1] = atom->string(1);
461 openBlock(BlockType::SectionHeading, attrs);
471 const QString &listType = atom->string();
472 attrs[
"listType"_L1] = listType;
474 openBlock(BlockType::DefinitionList, attrs);
476 openBlock(BlockType::List, attrs);
486 if (parent->type == BlockType::DefinitionList)
487 openBlock(BlockType::DefinitionDescription);
489 openBlock(BlockType::ListItem);
502 openBlock(BlockType::Note);
509 case Atom::WarningLeft:
510 openBlock(BlockType::Warning);
517 case Atom::ImportantLeft:
518 openBlock(BlockType::Important);
526 addLeafInline(InlineType::LineBreak, {});
530 openBlock(BlockType::HorizontalRule);
536 attrs[
"variant"_L1] = toString(ListPlaceholderVariant::AnnotatedGroup);
537 attrs[
"argument"_L1] = atom->string();
538 attrs[
"sort"_L1] = placeholderSortAttribute(atom);
539 openBlock(BlockType::ListPlaceholder, attrs);
545 const QString arg = atom->string();
547 attrs[
"argument"_L1] = arg;
548 attrs[
"sort"_L1] = placeholderSortAttribute(atom);
550 static constexpr auto classesPrefix =
"classes "_L1;
551 if (arg ==
"annotatedexamples"_L1) {
552 attrs[
"variant"_L1] = toString(ListPlaceholderVariant::AnnotatedExamples);
553 }
else if (arg ==
"annotatedclasses"_L1) {
554 attrs[
"variant"_L1] = toString(ListPlaceholderVariant::AnnotatedClasses);
555 }
else if (arg ==
"classes"_L1 || arg.startsWith(classesPrefix)) {
556 attrs[
"variant"_L1] = toString(ListPlaceholderVariant::CompactClasses);
557 if (arg.startsWith(classesPrefix)) {
558 const QString rootName = arg.sliced(classesPrefix.size()).trimmed();
559 if (!rootName.isEmpty())
560 attrs[
"rootName"_L1] = rootName;
567 QJsonObject fallback;
568 fallback[
"generatedList"_L1] = arg;
569 openBlock(BlockType::Div, fallback);
574 openBlock(BlockType::ListPlaceholder, attrs);
581 QString tableStyle = u"generic"_s;
584 for (
int i = 0; i < atom->count(); ++i) {
585 const QString &arg = atom->string(i);
586 if (arg ==
"borderless"_L1)
588 else if (arg.contains(
'%'_L1))
594 if (width ==
"%"_L1) {
596 int pct = atom->string(0).toInt(&ok);
597 width = ok ? QString::number(pct) +
'%'_L1 : QString();
600 attrs[
"style"_L1] = tableStyle;
601 if (!width.isEmpty())
602 attrs[
"width"_L1] = width;
603 openBlock(BlockType::Table, attrs);
611 case Atom::TableHeaderLeft:
612 openBlock(BlockType::TableHeaderRow);
619 case Atom::TableRowLeft:
620 openBlock(BlockType::TableRow);
629 const QString &spec = atom->string();
630 if (!spec.isEmpty()) {
631 const auto parts = QStringView{spec}.split(u',');
632 if (parts.size() >= 2) {
633 int colspan = qMax(1, parts[0].toInt());
634 int rowspan = qMax(1, parts[1].toInt());
636 attrs[
"colspan"_L1] = colspan;
638 attrs[
"rowspan"_L1] = rowspan;
641 openBlock(BlockType::TableCell, attrs);
649 case Atom::ListTagLeft:
650 openBlock(BlockType::DefinitionTerm);
659 attrs[
"class"_L1] = u"centerAlign"_s;
660 openBlock(BlockType::Paragraph, attrs);
664 img.href = atom->string();
667 addInline(
std::move(img));
677 if (Q_UNLIKELY(m_blockPath.isEmpty()))
682 img.href = atom->string();
685 addInline(
std::move(img));
697 attrs[
"class"_L1] = u"figCaption"_s;
698 openBlock(BlockType::Paragraph, attrs);
721
722
723
724
725
726
731 block.attributes =
std::move(attrs);
733 m_inlineBaseDepths.append(m_inlinePath.size());
735 if (m_blockPath.isEmpty()) {
736 m_result.append(std::move(block));
737 m_blockPath.append(m_result.size() - 1);
739 auto *parent = resolveBlock();
740 parent->children.append(
std::move(block));
741 m_blockPath.append(parent->children.size() - 1);
746
747
748
749
750
751
752
755 if (!m_blockPath.isEmpty()) {
756 if (Q_UNLIKELY(m_inlineBaseDepths.isEmpty())) {
757 m_inlinePath.clear();
759 m_inlineBaseDepths.clear();
763 const qsizetype expectedDepth = m_inlineBaseDepths.last();
764 if (m_inLink && m_inlinePath.size() > expectedDepth)
766 m_inlinePath.resize(expectedDepth);
767 m_inlinePath.resize(expectedDepth);
768 m_inlineBaseDepths.removeLast();
769 m_blockPath.removeLast();
774
775
776
777
778
779
780
781
782
783
786 if (!m_inlinePath.isEmpty()) {
787 resolveInline()->children.append(
std::move(inline_));
788 }
else if (!m_blockPath.isEmpty()) {
789 resolveBlock()->inlineContent.append(
std::move(inline_));
792 m_diagnose(QtWarningMsg, u"Dropping inline content outside any block"_s);
797
798
799
805 addInline(
std::move(ic));
809
810
811
812
813
814
815
816
817
820 if (!m_inlinePath.isEmpty()) {
821 auto *parent = resolveInline();
822 parent->children.append(
std::move(container));
823 m_inlinePath.append(parent->children.size() - 1);
824 }
else if (!m_blockPath.isEmpty()) {
825 auto *block = resolveBlock();
826 block->inlineContent.append(
std::move(container));
827 m_inlinePath.append(block->inlineContent.size() - 1);
832
833
834
835
836
837
840 Q_ASSERT(!m_blockPath.isEmpty());
841 Q_ASSERT(m_blockPath[0] >= 0 && m_blockPath[0] < m_result.size());
843 for (qsizetype i = 1; i < m_blockPath.size(); ++i) {
844 Q_ASSERT(m_blockPath[i] >= 0 && m_blockPath[i] < block->children.size());
845 block = &block->children[m_blockPath[i]];
851
852
853
854
855
856
860 Q_ASSERT(!m_inlinePath.isEmpty());
861 Q_ASSERT(m_inlinePath[0] >= 0 && m_inlinePath[0] < block->inlineContent.size());
863 for (qsizetype i = 1; i < m_inlinePath.size(); ++i) {
864 Q_ASSERT(m_inlinePath[i] >= 0 && m_inlinePath[i] < ic->children.size());
865 ic = &ic->children[m_inlinePath[i]];
#define ATOM_FORMATTING_TELETYPE
#define ATOM_FORMATTING_UNDERLINE
#define ATOM_FORMATTING_NOTRANSLATE
#define ATOM_FORMATTING_SUBSCRIPT
#define ATOM_FORMATTING_BOLD
#define ATOM_FORMATTING_TRADEMARK
#define ATOM_FORMATTING_ITALIC
#define ATOM_FORMATTING_LINK
#define ATOM_FORMATTING_SUPERSCRIPT
#define ATOM_FORMATTING_INDEX
#define ATOM_FORMATTING_UICONTROL
#define ATOM_FORMATTING_PARAMETER
The Atom class is the fundamental unit for representing documents internally.
AtomType type() const
Return the type of this atom.
virtual bool isLinkAtom() const
const Atom * next() const
Return the next atom in the atom list.
Converts Atom chains to QList<IR::ContentBlock> trees.
QList< ContentBlock > build(const Atom *firstAtom)
Walks the atom chain starting at firstAtom and returns a list of ContentBlock trees representing the ...
ContentBuilder(BriefHandling briefHandling=BriefHandling::Skip, int headingOffset=0, DiagnosticHandler diagnosticHandler={})
Constructs a ContentBuilder.
static QString genusToString(Genus genus)
static QString stripCodeMarkerTags(const QString &markedCode)
static QString placeholderSortAttribute(const Atom *atom)
static InlineType formattingToInlineType(const QString &formatting)
Combined button and popup list for selecting options.
Represents a structural block element in documentation.
LinkData(LinkOrigin o, LinkState s, std::optional< SourceLocation > loc=std::nullopt)
Represents inline content within a documentation block.