Md4qt

doc.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022-2025 Igor Mironchik <igor.mironchik@gmail.com>
3 SPDX-License-Identifier: MIT
4*/
5
6#ifndef MD4QT_MD_DOC_H_INCLUDED
7#define MD4QT_MD_DOC_H_INCLUDED
8
9// md4qt include.
10#include "utils.h"
11
12// C++ include.
13#include <memory>
14#include <utility>
15
16namespace MD
17{
18
19//
20// ItemType
21//
22
23//! Enumeration of item types.
24enum class ItemType : int {
25 //! Heading.
27 //! Text.
29 //! Paragraph.
31 //! Line break.
33 //! Blockquote.
35 //! List item.
37 //! List.
39 //! Link.
41 //! Image.
43 //! Code.
45 //! Table cell.
47 //! Table row.
49 //! Table.
51 //! Footnote ref.
53 //! Footnote.
55 //! Document.
57 //! Page break.
59 //! Anchor.
61 //! Horizontal line.
63 //! Raw HTML.
65 //! Math expression.
67 //! Start item for user-defined types.
69}; // enum class ItemType
70
71//
72// WithPosition
73//
74
75//! Base for any thing with start and end position.
77{
78public:
79 WithPosition() = default;
80 virtual ~WithPosition() = default;
81
83 long long int startLine,
84 long long int endColumn,
85 long long int endLine)
86 : m_startColumn(startColumn)
87 , m_startLine(startLine)
88 , m_endColumn(endColumn)
89 , m_endLine(endLine)
90 {
91 }
92
93 //! Apply positions to this from other.
94 void applyPositions(const WithPosition &other)
95 {
96 if (this != &other) {
97 *this = other;
98 }
99 }
100
101 //! \return Start column.
102 long long int startColumn() const
103 {
104 return m_startColumn;
105 }
106
107 //! \return Start line.
108 long long int startLine() const
109 {
110 return m_startLine;
111 }
112
113 //! \return End column.
114 long long int endColumn() const
115 {
116 return m_endColumn;
117 }
118
119 //! \return End line.
120 long long int endLine() const
121 {
122 return m_endLine;
123 }
124
125 //! Set start column.
126 void setStartColumn(long long int c)
127 {
128 m_startColumn = c;
129 }
130
131 //! Set start line.
132 void setStartLine(long long int l)
133 {
134 m_startLine = l;
135 }
136
137 //! Set end column.
138 void setEndColumn(long long int c)
139 {
140 m_endColumn = c;
141 }
142
143 //! Set end line.
144 void setEndLine(long long int l)
145 {
146 m_endLine = l;
147 }
148
149private:
150 //! Start column
151 long long int m_startColumn = -1;
152 //! Start line.
153 long long int m_startLine = -1;
154 //! End column.
155 long long int m_endColumn = -1;
156 //! End line.
157 long long int m_endLine = -1;
158}; // class WithPosition
159
160inline bool operator==(const WithPosition &l, const WithPosition &r)
161{
162 return (l.startColumn() == r.startColumn() &&
163 l.startLine() == r.startLine() &&
164 l.endColumn() == r.endColumn() &&
165 l.endLine() == r.endLine());
166}
167
168template<class Trait>
169class Document;
170
171//
172// Item
173//
174
175//! Base class for item in Markdown document.
176template<class Trait>
177class Item : public WithPosition
178{
179protected:
180 Item() = default;
181
182public:
183 ~Item() override = default;
184
185 //! \return Type of the item.
186 virtual ItemType type() const = 0;
187
188 //! Clone this item.
189 virtual std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const = 0;
190
191private:
193}; // class Item
194
195//
196// TextOption
197//
198
199//! Text option.
201 //! No format.
203 //! Bold text.
205 //! Italic text.
207 //! Strikethrough.
209}; // enum TextOption
210
211//
212// StyleDelim
213//
214
215//! Emphasis in the Markdown document.
216class StyleDelim final : public WithPosition
217{
218public:
220 long long int startColumn,
221 long long int startLine,
222 long long int endColumn,
223 long long int endLine)
225 , m_style(s)
226 {
227 }
228
229 ~StyleDelim() override = default;
230
231 //! \return Style.
232 int style() const
233 {
234 return m_style;
235 }
236
237 //! Set style.
238 void setStyle(int t)
239 {
240 m_style = t;
241 }
242
243private:
244 int m_style = TextWithoutFormat;
245}; // class StyleDelim
246
247inline bool operator==(const StyleDelim &l, const StyleDelim &r)
248{
249 return (static_cast<WithPosition>(l) == static_cast<WithPosition>(r) && l.style() == r.style());
250}
251
252//
253// ItemWithOpts
254//
255
256//! Base class for items that can have style options.
257//! These are all items in Paragraph.
258template<class Trait>
259class ItemWithOpts : public Item<Trait>
260{
261protected:
262 ItemWithOpts() = default;
263
264public:
265 ~ItemWithOpts() override = default;
266
267 //! Apply other item with options to this.
269 {
270 if (this != &other) {
272 m_opts = other.m_opts;
273 m_openStyles = other.m_openStyles;
274 m_closeStyles = other.m_closeStyles;
275 }
276 }
277
278 //! Type of list of emphasis.
279 using Styles = typename Trait::template Vector<StyleDelim>;
280
281 //! \return Style options.
282 int opts() const
283 {
284 return m_opts;
285 }
286
287 //! Set style options.
288 void setOpts(int o)
289 {
290 m_opts = o;
291 }
292
293 //! \return List of all opening emphasises.
294 const Styles &openStyles() const
295 {
296 return m_openStyles;
297 }
298
299 //! \return List of all opening emphasises.
301 {
302 return m_openStyles;
303 }
304
305 //! \return List of all closing emphasises.
306 const Styles &closeStyles() const
307 {
308 return m_closeStyles;
309 }
310
311 //! \return List of all closing emphasises.
313 {
314 return m_closeStyles;
315 }
316
317private:
318 //! Style options.
319 int m_opts = 0;
320 //! List of opening emphasises.
321 Styles m_openStyles;
322 //! List of closing emphasises.
323 Styles m_closeStyles;
324
326}; // class ItemWithOpts
327
328//
329// PageBreak
330//
331
332//! Page break.
333template<class Trait>
334class PageBreak final : public Item<Trait>
335{
336public:
337 PageBreak() = default;
338 ~PageBreak() override = default;
339
340 //! \return Type of the item.
341 ItemType type() const override
342 {
343 return ItemType::PageBreak;
344 }
345
346 //! Clone this page break.
347 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
348 {
349 MD_UNUSED(doc)
350
351 return std::make_shared<PageBreak<Trait>>();
352 }
353
354private:
356}; // class PageBreak
357
358//
359// HorizontalLine
360//
361
362//! Horizontal line.
363template<class Trait>
364class HorizontalLine final : public Item<Trait>
365{
366public:
367 HorizontalLine() = default;
368 ~HorizontalLine() override = default;
369
370 //! \return Type of the item.
371 ItemType type() const override
372 {
374 }
375
376 //! Clone this horizontal line.
377 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
378 {
379 MD_UNUSED(doc)
380
381 auto h = std::make_shared<HorizontalLine<Trait>>();
382 h->applyPositions(*this);
383
384 return h;
385 }
386
387private:
389}; // class HorizontalLine
390
391//
392// Anchor
393//
394
395//! Just an anchor.
396template<class Trait>
397class Anchor final : public Item<Trait>
398{
399public:
400 explicit Anchor(const typename Trait::String &l)
401 : m_label(l)
402 {
403 }
404
405 ~Anchor() override = default;
406
407 //! Clone this anchor.
408 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
409 {
410 MD_UNUSED(doc)
411
412 return std::make_shared<Anchor<Trait>>(m_label);
413 }
414
415 //! \return item type.
416 ItemType type() const override
417 {
418 return ItemType::Anchor;
419 }
420
421 //! \return Label of this anchor.
422 const typename Trait::String &label() const
423 {
424 return m_label;
425 }
426
427private:
429
430 //! Label
431 typename Trait::String m_label;
432}; // class Anchor
433
434//
435// RawHtml
436//
437
438//! Raw HTML.
439template<class Trait>
440class RawHtml final : public ItemWithOpts<Trait>
441{
442public:
443 RawHtml() = default;
444 ~RawHtml() override = default;
445
446 //! Clone this raw HTML.
447 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
448 {
449 MD_UNUSED(doc)
450
451 auto h = std::make_shared<RawHtml<Trait>>();
452 h->applyItemWithOpts(*this);
453 h->setText(m_text);
454 h->setFreeTag(m_isFreeTag);
455
456 return h;
457 }
458
459 //! \return Type of the item.
460 ItemType type() const override
461 {
462 return ItemType::RawHtml;
463 }
464
465 //! \return HTML content.
466 const typename Trait::String &text() const
467 {
468 return m_text;
469 }
470
471 //! Set HTML content.
472 void setText(const typename Trait::String &t)
473 {
474 m_text = t;
475 }
476
477protected:
478 template<class T>
479 friend class Parser;
480
481 template<class T>
483
484 //! \return Is this HTML a free tag, not inline one.
485 //! \note This method is for internal use only.
486 bool isFreeTag() const
487 {
488 return m_isFreeTag;
489 }
490
491 //! Set that this HTML is a free, not inline one.
492 //! \note This method is for internal use only.
493 void setFreeTag(bool on = true)
494 {
495 m_isFreeTag = on;
496 }
497
498private:
499 //! HTML content.
500 typename Trait::String m_text;
501 //! Is this HTML a free tag, not inline one.
502 bool m_isFreeTag = true;
503
505}; // class RawHtml
506
507//
508// Text
509//
510
511//! Text item in Paragraph.
512template<typename Trait>
513class Text : public ItemWithOpts<Trait>
514{
515public:
516 Text() = default;
517 ~Text() override = default;
518
519 //! Apply other text to this.
520 void applyText(const Text<Trait> &t)
521 {
522 if (this != &t) {
524 setText(t.text());
525 }
526 }
527
528 //! Clone this text item.
529 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
530 {
531 MD_UNUSED(doc)
532
533 auto t = std::make_shared<Text<Trait>>();
534 t->applyText(*this);
535
536 return t;
537 }
538
539 //! \return Type of the item.
540 ItemType type() const override
541 {
542 return ItemType::Text;
543 }
544
545 //! \return Text content.
546 const typename Trait::String &text() const
547 {
548 return m_text;
549 }
550
551 //! Set text content.
552 void setText(const typename Trait::String &t)
553 {
554 m_text = t;
555 }
556
557private:
558 //! Text content.
559 typename Trait::String m_text;
560
562}; // class Text
563
564//
565// LineBreak
566//
567
568//! Line break.
569template<class Trait>
570class LineBreak final : public Text<Trait>
571{
572public:
573 LineBreak() = default;
574 ~LineBreak() override = default;
575
576 //! Clone this line break.
577 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
578 {
579 MD_UNUSED(doc)
580
581 auto b = std::make_shared<LineBreak<Trait>>();
582 b->applyText(*this);
583
584 return b;
585 }
586
587 //! \return Type of the item.
588 ItemType type() const override
589 {
590 return ItemType::LineBreak;
591 }
592
593private:
595}; // class LineBreak
596
597//
598// Block
599//
600
601//! Abstract block (storage of child items).
602template<class Trait>
603class Block : public Item<Trait>
604{
605protected:
606 Block() = default;
607
608public:
609 ~Block() override = default;
610
611 //! Type of pointer to child item.
612 using ItemSharedPointer = std::shared_ptr<Item<Trait>>;
613 //! Type of list of children.
614 using Items = typename Trait::template Vector<ItemSharedPointer>;
615
616 //! Apply other block to this.
617 void applyBlock(const Block<Trait> &other, Document<Trait> *doc = nullptr)
618 {
619 if (this != &other) {
621
622 m_items.clear();
623
624 for (const auto &i : other.items())
625 appendItem(i->clone(doc));
626 }
627 }
628
629 //! \return List of child items.
630 const Items &items() const
631 {
632 return m_items;
633 }
634
635 //! Insert child item at give position.
636 void insertItem(long long int idx, ItemSharedPointer i)
637 {
638 m_items.insert(m_items.cbegin() + idx, i);
639 }
640
641 //! Append child item.
643 {
644 m_items.push_back(i);
645 }
646
647 //! Remove child item at the given position.
648 void removeItemAt(long long int idx)
649 {
650 if (idx >= 0 && idx < static_cast<long long int>(m_items.size()))
651 m_items.erase(m_items.cbegin() + idx);
652 }
653
654 //! \return Child item at the given position.
655 ItemSharedPointer getItemAt(long long int idx) const
656 {
657 return m_items.at(idx);
658 }
659
660 //! \return Is there no children.
661 bool isEmpty() const
662 {
663 return m_items.empty();
664 }
665
666private:
667 //! Child items.
668 Items m_items;
669
671}; // class Block
672
673//
674// Paragraph
675//
676
677//! Paragraph.
678template<class Trait>
679class Paragraph final : public Block<Trait>
680{
681public:
682 Paragraph() = default;
683 ~Paragraph() override = default;
684
685 //! Clone this paragraph.
686 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
687 {
688 auto p = std::make_shared<Paragraph<Trait>>();
689 p->applyBlock(*this, doc);
690
691 return p;
692 }
693
694 //! \return Type of the item.
695 ItemType type() const override
696 {
697 return ItemType::Paragraph;
698 }
699
700private:
702}; // class Paragraph
703
704//
705// Heading
706//
707
708//! Heading.
709template<class Trait>
710class Heading final : public Item<Trait>
711{
712public:
714 : m_text(new Paragraph<Trait>)
715 {
716 }
717
718 ~Heading() override = default;
719
720 //! Type of list of service chanracters.
721 using Delims = typename Trait::template Vector<WithPosition>;
722
723 //! Clone this heading.
724 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
725 {
726 auto h = std::make_shared<Heading<Trait>>();
727 h->applyPositions(*this);
728 h->setText(std::static_pointer_cast<Paragraph<Trait>>(m_text->clone(doc)));
729 h->setLevel(m_level);
730 h->setLabel(m_label);
731 h->setDelims(m_delims);
732 h->setLabelPos(m_labelPos);
733 h->setLabelVariants(m_labelVariants);
734
735 if (doc && isLabeled())
736 for (const auto &label : std::as_const(m_labelVariants)) {
737 doc->insertLabeledHeading(label, h);
738 }
739
740 return h;
741 }
742
743 //! \return Type of the item.
744 ItemType type() const override
745 {
746 return ItemType::Heading;
747 }
748
749 //! Type of smart pointer to paragraph.
750 using ParagraphSharedPointer = std::shared_ptr<Paragraph<Trait>>;
751
752 //! \return Content of the heading.
754 {
755 return m_text;
756 }
757
758 //! Set content of the heading.
760 {
761 m_text = t;
762 }
763
764 //! \return Level of the heading.
765 int level() const
766 {
767 return m_level;
768 }
769
770 //! Set level of the heading.
771 void setLevel(int l)
772 {
773 m_level = l;
774 }
775
776 //! \return Is this heading has label?
777 bool isLabeled() const
778 {
779 return m_label.size() > 0;
780 }
781
782 //! \return Label of the heading.
783 const typename Trait::String &label() const
784 {
785 return m_label;
786 }
787
788 //! Set label of the heading.
789 void setLabel(const typename Trait::String &l)
790 {
791 m_label = l;
792 }
793
794 //! \return List of service characters.
795 const Delims &delims() const
796 {
797 return m_delims;
798 }
799
800 //! Set list of service characters.
801 void setDelims(const Delims &d)
802 {
803 m_delims = d;
804 }
805
806 //! \return Position of a label in the heading.
807 const WithPosition &labelPos() const
808 {
809 return m_labelPos;
810 }
811
812 //! Set position of a label in the heading.
814 {
815 m_labelPos = p;
816 }
817
818 //! Type of a vector of labels.
819 using LabelsVector = typename Trait::template Vector<typename Trait::String>;
820
821 //! \return Label variants.
823 {
824 return m_labelVariants;
825 }
826
827 //! \return Label variants.
829 {
830 return m_labelVariants;
831 }
832
833 //! Set label variants.
835 {
836 m_labelVariants = vars;
837 }
838
839private:
840 //! Content of the heading.
842 //! Level of the heading.
843 int m_level = 0;
844 //! Label of the heading.
845 typename Trait::String m_label;
846 //! List of service characters.
847 Delims m_delims;
848 //! Position of the label.
849 WithPosition m_labelPos;
850 //! Label variants.
851 LabelsVector m_labelVariants;
852
854}; // class Heading
855
856//
857// Blockquote
858//
859
860//! Blockquote.
861template<class Trait>
862class Blockquote final : public Block<Trait>
863{
864public:
865 Blockquote() = default;
866 ~Blockquote() override = default;
867
868 //! Clone this blockquote.
869 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
870 {
871 auto b = std::make_shared<Blockquote<Trait>>();
872 b->applyBlock(*this, doc);
873 b->delims() = m_delims;
874
875 return b;
876 }
877
878 //! \return Type of the item.
879 ItemType type() const override
880 {
882 }
883
884 //! Type of a list of service characters.
885 using Delims = typename Trait::template Vector<WithPosition>;
886
887 //! \return List of service characters.
888 const Delims &delims() const
889 {
890 return m_delims;
891 }
892
893 //! \return List of service characters.
895 {
896 return m_delims;
897 }
898
899private:
900 //! List of service characters.
901 Delims m_delims;
902
904}; // class Blockquote
905
906//
907// ListItem
908//
909
910//! List item in a list.
911template<class Trait>
912class ListItem final : public Block<Trait>
913{
914public:
915 ListItem() = default;
916 ~ListItem() override = default;
917
918 //! Clone this list item.
919 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
920 {
921 auto l = std::make_shared<ListItem<Trait>>();
922 l->applyBlock(*this, doc);
923 l->setListType(m_listType);
924 l->setOrderedListPreState(m_orderedListState);
925 l->setStartNumber(m_startNumber);
926 l->setTaskList(m_isTaskList);
927 l->setChecked(m_isChecked);
928 l->setDelim(m_delim);
929 l->setTaskDelim(m_taskDelim);
930
931 return l;
932 }
933
934 //! \return Type of the item.
935 ItemType type() const override
936 {
937 return ItemType::ListItem;
938 }
939
940 //! Type of the list.
941 enum ListType {
942 //! Ordered.
944 //! Unordered
946 }; // enum ListType
947
948 //! Preliminary state of the ordered list.
950 //! Start item.
952 //! Continue of the list
954 }; // enum OrderedListPreState
955
956 //! \return Type of the list.
958 {
959 return m_listType;
960 }
961
962 //! Set type of the list.
964 {
965 m_listType = t;
966 }
967
968 //! \return Preliminary state of the ordered list.
970 {
971 return m_orderedListState;
972 }
973
974 //! Set preliminary state of the ordered list.
976 {
977 m_orderedListState = s;
978 }
979
980 //! \return Start number of the ordered list
981 int startNumber() const
982 {
983 return m_startNumber;
984 }
985
986 //! Set start number of the ordered list.
987 void setStartNumber(int n)
988 {
989 m_startNumber = n;
990 }
991
992 //! \return Is this list item a task list item?
993 bool isTaskList() const
994 {
995 return m_isTaskList;
996 }
997
998 //! Set this list item to be a tsk list item.
999 void setTaskList(bool on = true)
1000 {
1001 m_isTaskList = on;
1002 }
1003
1004 //! \return Is this task list item checked?
1005 bool isChecked() const
1006 {
1007 return m_isChecked;
1008 }
1009
1010 //! Set this task list item to be checked.
1011 void setChecked(bool on = true)
1012 {
1013 m_isChecked = on;
1014 }
1015
1016 //! \return Service character position.
1017 const WithPosition &delim() const
1018 {
1019 return m_delim;
1020 }
1021
1022 //! Set service character position.
1023 void setDelim(const WithPosition &d)
1024 {
1025 m_delim = d;
1026 }
1027
1028 //! \return Position of the task list "checkbox" in Markdown.
1030 {
1031 return m_taskDelim;
1032 }
1033
1034 //! Set position of the task list "checkbox" in Markdown.
1036 {
1037 m_taskDelim = d;
1038 }
1039
1040private:
1041 //! Type of the list.
1042 ListType m_listType = Unordered;
1043 //! Preliminary state of the ordered list.
1044 OrderedListPreState m_orderedListState = Start;
1045 //! Start number of the ordered list.
1046 int m_startNumber = 1;
1047 //! Is this list item a task list item?
1048 bool m_isTaskList = false;
1049 //! Is this task list item checked?
1050 bool m_isChecked = false;
1051 //! Service character position.
1052 WithPosition m_delim = {};
1053 //! Task list "checkbox" position.
1054 WithPosition m_taskDelim = {};
1055
1057}; // class ListItem
1058
1059//
1060// List
1061//
1062
1063//! List.
1064template<class Trait>
1065class List final : public Block<Trait>
1066{
1067public:
1068 List() = default;
1069 ~List() override = default;
1070
1071 //! Clone this list.
1072 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1073 {
1074 auto l = std::make_shared<List<Trait>>();
1075 l->applyBlock(*this, doc);
1076
1077 return l;
1078 }
1079
1080 //! \return Type of the item.
1081 ItemType type() const override
1082 {
1083 return ItemType::List;
1084 }
1085
1086private:
1088}; // class List
1089
1090//
1091// LinkBase
1092//
1093
1094//! Base class for links.
1095template<class Trait>
1096class LinkBase : public ItemWithOpts<Trait>
1097{
1098public:
1100 : m_p(new Paragraph<Trait>)
1101 {
1102 }
1103
1104 ~LinkBase() override = default;
1105
1106 //! Apply other base of link to this.
1107 void applyLinkBase(const LinkBase<Trait> &other, Document<Trait> *doc = nullptr)
1108 {
1109 if (this != &other) {
1111 setUrl(other.url());
1112 setText(other.text());
1113 setP(std::static_pointer_cast<Paragraph<Trait>>(other.p()->clone(doc)));
1114 setTextPos(other.textPos());
1115 setUrlPos(other.urlPos());
1116 }
1117 }
1118
1119 //! Type of a smart pointer to link's description.
1120 using ParagraphSharedPointer = std::shared_ptr<Paragraph<Trait>>;
1121
1122 //! \return URL of the link.
1123 const typename Trait::String &url() const
1124 {
1125 return m_url;
1126 }
1127
1128 //! Set URL of the link.
1129 void setUrl(const typename Trait::String &u)
1130 {
1131 m_url = u;
1132 }
1133
1134 //! Not parsed text of link's description.
1135 const typename Trait::String &text() const
1136 {
1137 return m_text;
1138 }
1139
1140 //! Set not parsed text of link's description.
1141 void setText(const typename Trait::String &t)
1142 {
1143 m_text = t;
1144 }
1145
1146 //! \return Is this link empty?
1147 bool isEmpty() const
1148 {
1149 return m_url.size() <= 0;
1150 }
1151
1152 //! \return Pointer to parsed text of link's description.
1154 {
1155 return m_p;
1156 }
1157
1158 //! Set pointer to parsed text of link's description.
1160 {
1161 m_p = v;
1162 }
1163
1164 //! \return Position of link's desciption.
1165 const WithPosition &textPos() const
1166 {
1167 return m_textPos;
1168 }
1169
1170 //! Set position of link's description.
1171 void setTextPos(const WithPosition &pos)
1172 {
1173 m_textPos = pos;
1174 }
1175
1176 //! \return Position of URL.
1177 const WithPosition &urlPos() const
1178 {
1179 return m_urlPos;
1180 }
1181
1182 //! Set position of URL.
1183 void setUrlPos(const WithPosition &pos)
1184 {
1185 m_urlPos = pos;
1186 }
1187
1188private:
1189 //! URL.
1190 typename Trait::String m_url;
1191 //! Not parsed content of link's description.
1192 typename Trait::String m_text;
1193 //! Parsed content of link's description.
1195 //! Position of link's description.
1196 WithPosition m_textPos = {};
1197 //! URL position.
1198 WithPosition m_urlPos = {};
1199
1201}; // class LinkBase
1202
1203//
1204// Image
1205//
1206
1207//! Image.
1208template<class Trait>
1209class Image final : public LinkBase<Trait>
1210{
1211public:
1212 Image() = default;
1213 ~Image() override = default;
1214
1215 //! Clone this image.
1216 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1217 {
1218 auto i = std::make_shared<Image<Trait>>();
1219 i->applyLinkBase(*this, doc);
1220
1221 return i;
1222 }
1223
1224 //! \return Type of the item.
1225 ItemType type() const override
1226 {
1227 return ItemType::Image;
1228 }
1229
1230private:
1232}; // class Image
1233
1234//
1235// Link
1236//
1237
1238//! Link.
1239template<class Trait>
1240class Link final : public LinkBase<Trait>
1241{
1242public:
1244 : LinkBase<Trait>()
1245 , m_img(new Image<Trait>)
1246 {
1247 }
1248
1249 //! Clone this link.
1250 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1251 {
1252 auto l = std::make_shared<Link<Trait>>();
1253 l->applyLinkBase(*this, doc);
1254 l->setImg(std::static_pointer_cast<Image<Trait>>(m_img->clone(doc)));
1255
1256 return l;
1257 }
1258
1259 ~Link() override = default;
1260
1261 //! \return Type of the item.
1262 ItemType type() const override
1263 {
1264 return ItemType::Link;
1265 }
1266
1267 //! Type of a smart pointer to image.
1268 using ImageSharedPointer = std::shared_ptr<Image<Trait>>;
1269
1270 //! \return Image of the link.
1272 {
1273 return m_img;
1274 }
1275
1276 //! Set image of the link.
1278 {
1279 m_img = i;
1280 }
1281
1282private:
1283 //! Image of the link.
1284 ImageSharedPointer m_img;
1285
1287}; // class Link
1288
1289//
1290// Code
1291//
1292
1293//! Code.
1294template<class Trait>
1295class Code : public ItemWithOpts<Trait>
1296{
1297public:
1298 explicit Code(const typename Trait::String &t, bool fensedCode, bool inl)
1299 : ItemWithOpts<Trait>()
1300 , m_text(t)
1301 , m_inlined(inl)
1302 , m_fensed(fensedCode)
1303 {
1304 }
1305
1306 ~Code() override = default;
1307
1308 //! Apply other code to this.
1309 void applyCode(const Code<Trait> &other)
1310 {
1311 if (this != &other) {
1313 setText(other.text());
1314 setInline(other.isInline());
1315 setSyntax(other.syntax());
1316 setSyntaxPos(other.syntaxPos());
1317 setStartDelim(other.startDelim());
1318 setEndDelim(other.endDelim());
1319 setFensedCode(other.isFensedCode());
1320 }
1321 }
1322
1323 //! Clone this code.
1324 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1325 {
1326 MD_UNUSED(doc)
1327
1328 auto c = std::make_shared<Code<Trait>>(m_text, m_fensed, m_inlined);
1329 c->applyCode(*this);
1330
1331 return c;
1332 }
1333
1334 //! \return Type of the item.
1335 ItemType type() const override
1336 {
1337 return ItemType::Code;
1338 }
1339
1340 //! \return Content of the code.
1341 const typename Trait::String &text() const
1342 {
1343 return m_text;
1344 }
1345
1346 //! Set content of the code.
1347 void setText(const typename Trait::String &t)
1348 {
1349 m_text = t;
1350 }
1351
1352 //! \return Is this code inline?
1353 bool isInline() const
1354 {
1355 return m_inlined;
1356 }
1357
1358 //! Set this code to be inline.
1359 void setInline(bool on = true)
1360 {
1361 m_inlined = on;
1362 }
1363
1364 //! \return Syntax of the fensed code block.
1365 const typename Trait::String &syntax() const
1366 {
1367 return m_syntax;
1368 }
1369
1370 //! Set syntax of the fensed code block.
1371 void setSyntax(const typename Trait::String &s)
1372 {
1373 m_syntax = s;
1374 }
1375
1376 //! \return Position of the syntax of the fensed code block.
1378 {
1379 return m_syntaxPos;
1380 }
1381
1382 //! Set position of the syntax of the fensed code block.
1384 {
1385 m_syntaxPos = p;
1386 }
1387
1388 //! \return Position of the start service characters.
1390 {
1391 return m_startDelim;
1392 }
1393
1394 //! Set position of the start service characters.
1396 {
1397 m_startDelim = d;
1398 }
1399
1400 //! \return Position of the ending service characters.
1401 const WithPosition &endDelim() const
1402 {
1403 return m_endDelim;
1404 }
1405
1406 //! Set position of the ending service characters.
1408 {
1409 m_endDelim = d;
1410 }
1411
1412 //! \return Is this a fensed code block?
1413 bool isFensedCode() const
1414 {
1415 return m_fensed;
1416 }
1417
1418 //! Set this code block to be a fensed code block.
1419 void setFensedCode(bool on = true)
1420 {
1421 m_fensed = on;
1422 }
1423
1424private:
1425 //! Content of the code.
1426 typename Trait::String m_text;
1427 //! Is this code inline?
1428 bool m_inlined = true;
1429 //! Is this code a fensed code block.
1430 bool m_fensed = false;
1431 //! Syntax of the fensed code lock.
1432 typename Trait::String m_syntax;
1433 //! Position of start service characters.
1434 WithPosition m_startDelim = {};
1435 //! Position of ending service characters.
1436 WithPosition m_endDelim = {};
1437 //! Position of syntax of fensed code block.
1438 WithPosition m_syntaxPos = {};
1439
1441}; // class Code
1442
1443//
1444// Math
1445//
1446
1447//! LaTeX math expression.
1448template<class Trait>
1449class Math final : public Code<Trait>
1450{
1451public:
1453 : Code<Trait>(typename Trait::String(), false, true)
1454 {
1455 }
1456
1457 ~Math() override = default;
1458
1459 //! Clone this LaTeX math expression.
1460 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1461 {
1462 MD_UNUSED(doc)
1463
1464 auto m = std::make_shared<Math<Trait>>();
1465 m->applyCode(*this);
1466
1467 return m;
1468 }
1469
1470 //! \return Type of the item.
1471 ItemType type() const override
1472 {
1473 return ItemType::Math;
1474 }
1475
1476 //! \return Content.
1477 const typename Trait::String &expr() const
1478 {
1479 return Code<Trait>::text();
1480 }
1481
1482 //! Set content.
1483 void setExpr(const typename Trait::String &e)
1484 {
1486 }
1487
1488private:
1490}; // class Math
1491
1492//
1493// TableCell
1494//
1495
1496//! Table cell.
1497template<class Trait>
1498class TableCell final : public Block<Trait>
1499{
1500public:
1501 TableCell() = default;
1502 ~TableCell() override = default;
1503
1504 //! Clone this table cell.
1505 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1506 {
1507 auto c = std::make_shared<TableCell<Trait>>();
1508 c->applyBlock(*this, doc);
1509
1510 return c;
1511 }
1512
1513 //! \return Type of the item.
1514 ItemType type() const override
1515 {
1516 return ItemType::TableCell;
1517 }
1518
1519private:
1521}; // class TableCell
1522
1523//
1524// TableRow
1525//
1526
1527//! Table row.
1528template<class Trait>
1529class TableRow final : public Item<Trait>
1530{
1531public:
1532 TableRow() = default;
1533 ~TableRow() override = default;
1534
1535 //! Clone this table row.
1536 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1537 {
1538 auto t = std::make_shared<TableRow<Trait>>();
1539 t->applyPositions(*this);
1540
1541 for (const auto &c : cells()) {
1542 t->appendCell(std::static_pointer_cast<TableCell<Trait>>(c->clone(doc)));
1543 }
1544
1545 return t;
1546 }
1547
1548 //! \return Type of the item.
1549 ItemType type() const override
1550 {
1551 return ItemType::TableRow;
1552 }
1553
1554 //! Type of a smart pointer to table cell.
1555 using TableCellSharedPointer = std::shared_ptr<TableCell<Trait>>;
1556 //! Type of a list of table cells.
1557 using Cells = typename Trait::template Vector<TableCellSharedPointer>;
1558
1559 //! \return List of cells.
1560 const Cells &cells() const
1561 {
1562 return m_cells;
1563 }
1564
1565 //! Append cell.
1567 {
1568 m_cells.push_back(c);
1569 }
1570
1571 //! \return Is this row empty?
1572 bool isEmpty() const
1573 {
1574 return m_cells.empty();
1575 }
1576
1577private:
1578 //! List of cells.
1579 Cells m_cells;
1580
1582}; // class TableRow
1583
1584//
1585// Table
1586//
1587
1588//! Table.
1589template<class Trait>
1590class Table final : public Item<Trait>
1591{
1592public:
1593 Table() = default;
1594 ~Table() override = default;
1595
1596 //! Clone this table.
1597 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1598 {
1599 auto t = std::make_shared<Table<Trait>>();
1600 t->applyPositions(*this);
1601
1602 for (const auto &r : rows()) {
1603 t->appendRow(std::static_pointer_cast<TableRow<Trait>>(r->clone(doc)));
1604 }
1605
1606 for (int i = 0; i < columnsCount(); ++i) {
1607 t->setColumnAlignment(i, columnAlignment(i));
1608 }
1609
1610 return t;
1611 }
1612
1613 //! \return Type of the item.
1614 ItemType type() const override
1615 {
1616 return ItemType::Table;
1617 }
1618
1619 //! Type of a smart pointer to table row.
1620 using TableRowSharedPointer = std::shared_ptr<TableRow<Trait>>;
1621 //! Type of list of rows.
1622 using Rows = typename Trait::template Vector<TableRowSharedPointer>;
1623
1624 //! \return List of rows.
1625 const Rows &rows() const
1626 {
1627 return m_rows;
1628 }
1629
1630 //! Append row.
1632 {
1633 m_rows.push_back(r);
1634 }
1635
1636 //! Alignment.
1638 //! Left.
1640 //! Right.
1642 //! Center.
1644 }; // enum Alignmnet.
1645
1646 //! Type of list alignments.
1647 using ColumnsAlignments = typename Trait::template Vector<Alignment>;
1648
1649 //! \return Alignment of the given column.
1651 {
1652 return m_aligns.at(idx);
1653 }
1654
1655 //! Set alignment of the given column.
1657 {
1658 if (idx + 1 > columnsCount()) {
1659 m_aligns.push_back(a);
1660 } else {
1661 m_aligns[idx] = a;
1662 }
1663 }
1664
1665 //! \return Count of columns.
1666 int columnsCount() const
1667 {
1668 return m_aligns.size();
1669 }
1670
1671 //! \return Is this table empty?
1672 bool isEmpty() const
1673 {
1674 return (m_aligns.empty() || m_rows.empty());
1675 }
1676
1677private:
1678 //! Rows.
1679 Rows m_rows;
1680 //! Columns' alignments.
1681 ColumnsAlignments m_aligns;
1682
1684}; // class Table
1685
1686//
1687// FootnoteRef
1688//
1689
1690//! Footnote reference.
1691template<class Trait>
1692class FootnoteRef final : public Text<Trait>
1693{
1694public:
1695 explicit FootnoteRef(const typename Trait::String &i)
1696 : m_id(i)
1697 {
1698 }
1699
1700 ~FootnoteRef() override = default;
1701
1702 //! Clone this footnote reference.
1703 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1704 {
1705 MD_UNUSED(doc)
1706
1707 auto f = std::make_shared<FootnoteRef<Trait>>(m_id);
1708 f->applyText(*this);
1709 f->setIdPos(m_idPos);
1710
1711 return f;
1712 }
1713
1714 //! \return Type of the item.
1715 ItemType type() const override
1716 {
1717 return ItemType::FootnoteRef;
1718 }
1719
1720 //! \return ID of footnote reference.
1721 const typename Trait::String &id() const
1722 {
1723 return m_id;
1724 }
1725
1726 //! \return Position of ID.
1727 const WithPosition &idPos() const
1728 {
1729 return m_idPos;
1730 }
1731
1732 //! Set position of ID.
1733 void setIdPos(const WithPosition &pos)
1734 {
1735 m_idPos = pos;
1736 }
1737
1738private:
1739 //! ID.
1740 typename Trait::String m_id;
1741 //! Position of ID.
1742 WithPosition m_idPos;
1743
1745}; // class FootnoteRef
1746
1747//
1748// Footnote
1749//
1750
1751//! Footnote.
1752template<class Trait>
1753class Footnote final : public Block<Trait>
1754{
1755public:
1756 Footnote() = default;
1757 ~Footnote() override = default;
1758
1759 //! Clone this footnote.
1760 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1761 {
1762 auto f = std::make_shared<Footnote<Trait>>();
1763 f->applyBlock(*this, doc);
1764 f->setIdPos(m_idPos);
1765
1766 return f;
1767 }
1768
1769 //! \return Type of the item.
1770 ItemType type() const override
1771 {
1772 return ItemType::Footnote;
1773 }
1774
1775 //! \return Position of ID.
1776 const WithPosition &idPos() const
1777 {
1778 return m_idPos;
1779 }
1780
1781 //! Set position of ID.
1782 void setIdPos(const WithPosition &pos)
1783 {
1784 m_idPos = pos;
1785 }
1786
1787private:
1788 //! Position of ID.
1789 WithPosition m_idPos = {};
1790
1792}; // class Footnote
1793
1794//
1795// Document
1796//
1797
1798//! Document.
1799template<class Trait>
1800class Document final : public Block<Trait>
1801{
1802public:
1803 Document() = default;
1804 ~Document() override = default;
1805
1806 //! \return Type of the item.
1807 ItemType type() const override
1808 {
1809 return ItemType::Document;
1810 }
1811
1812 //! Clone this document.
1813 std::shared_ptr<Item<Trait>> clone(Document<Trait> *doc = nullptr) const override
1814 {
1815 MD_UNUSED(doc)
1816
1817 auto d = std::make_shared<Document<Trait>>();
1818 d->applyBlock(*this, d.get());
1819
1820 for (auto it = m_footnotes.cbegin(), last = m_footnotes.cend(); it != last; ++it) {
1821 d->insertFootnote(it->first,
1822 std::static_pointer_cast<Footnote<Trait>>(it->second->clone(d.get())));
1823 }
1824
1825 for (auto it = m_labeledLinks.cbegin(), last = m_labeledLinks.cend(); it != last; ++it) {
1826 d->insertLabeledLink(it->first,
1827 std::static_pointer_cast<Link<Trait>>(it->second->clone(d.get())));
1828 }
1829
1830 return d;
1831 }
1832
1833 //! Type of a smart pointer to footnote.
1834 using FootnoteSharedPointer = std::shared_ptr<Footnote<Trait>>;
1835 //! Type of a map of footnotes.
1836 using Footnotes = typename Trait::template Map<typename Trait::String, FootnoteSharedPointer>;
1837
1838 //! \return Map of footnotes.
1840 {
1841 return m_footnotes;
1842 }
1843
1844 //! Insert footnote with the give ID.
1845 void insertFootnote(const typename Trait::String &id, FootnoteSharedPointer fn)
1846 {
1847 m_footnotes.insert({id, fn});
1848 }
1849
1850 //! Type of a smart pointer to link.
1851 using LinkSharedPointer = std::shared_ptr<Link<Trait>>;
1852 //! Type of a map of shortcut links.
1853 using LabeledLinks = typename Trait::template Map<typename Trait::String, LinkSharedPointer>;
1854
1855 //! \return Map of shortcut links.
1857 {
1858 return m_labeledLinks;
1859 }
1860
1861 //! Insert shortcut link with the given label.
1862 void insertLabeledLink(const typename Trait::String &label, LinkSharedPointer lnk)
1863 {
1864 m_labeledLinks.insert({label, lnk});
1865 }
1866
1867 //! Type of a smart pointer to heading.
1868 using HeadingSharedPointer = std::shared_ptr<Heading<Trait>>;
1869 //! Type of a map of headings.
1870 using LabeledHeadings = typename Trait::template Map<typename Trait::String, HeadingSharedPointer>;
1871
1872 //! \return Map of headings.
1874 {
1875 return m_labeledHeadings;
1876 }
1877
1878 //! Insert heading with the given label.
1879 void insertLabeledHeading(const typename Trait::String &label, HeadingSharedPointer h)
1880 {
1881 m_labeledHeadings.insert({label, h});
1882 }
1883
1884private:
1885 //! Map of footnotes.
1886 Footnotes m_footnotes;
1887 //! Map of shortcut links.
1888 LabeledLinks m_labeledLinks;
1889 //! Map of headings.
1890 LabeledHeadings m_labeledHeadings;
1891
1893}; // class Document;
1894
1895} /* namespace MD */
1896
1897#endif // MD4QT_MD_DOC_H_INCLUDED
Just an anchor.
Definition doc.h:398
const Trait::String & label() const
Definition doc.h:422
Anchor(const typename Trait::String &l)
Definition doc.h:400
~Anchor() override=default
ItemType type() const override
Definition doc.h:416
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this anchor.
Definition doc.h:408
Abstract block (storage of child items).
Definition doc.h:604
void removeItemAt(long long int idx)
Remove child item at the given position.
Definition doc.h:648
typename Trait::template Vector< ItemSharedPointer > Items
Type of list of children.
Definition doc.h:614
ItemSharedPointer getItemAt(long long int idx) const
Definition doc.h:655
bool isEmpty() const
Definition doc.h:661
void appendItem(ItemSharedPointer i)
Append child item.
Definition doc.h:642
void insertItem(long long int idx, ItemSharedPointer i)
Insert child item at give position.
Definition doc.h:636
Block()=default
std::shared_ptr< Item< Trait > > ItemSharedPointer
Type of pointer to child item.
Definition doc.h:612
~Block() override=default
void applyBlock(const Block< Trait > &other, Document< Trait > *doc=nullptr)
Apply other block to this.
Definition doc.h:617
const Items & items() const
Definition doc.h:630
Blockquote.
Definition doc.h:863
const Delims & delims() const
Definition doc.h:888
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this blockquote.
Definition doc.h:869
~Blockquote() override=default
Delims & delims()
Definition doc.h:894
Blockquote()=default
typename Trait::template Vector< WithPosition > Delims
Type of a list of service characters.
Definition doc.h:885
ItemType type() const override
Definition doc.h:879
Code.
Definition doc.h:1296
void applyCode(const Code< Trait > &other)
Apply other code to this.
Definition doc.h:1309
const WithPosition & startDelim() const
Definition doc.h:1389
Code(const typename Trait::String &t, bool fensedCode, bool inl)
Definition doc.h:1298
const WithPosition & endDelim() const
Definition doc.h:1401
const WithPosition & syntaxPos() const
Definition doc.h:1377
void setSyntaxPos(const WithPosition &p)
Set position of the syntax of the fensed code block.
Definition doc.h:1383
void setText(const typename Trait::String &t)
Set content of the code.
Definition doc.h:1347
~Code() override=default
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this code.
Definition doc.h:1324
const Trait::String & syntax() const
Definition doc.h:1365
bool isFensedCode() const
Definition doc.h:1413
void setFensedCode(bool on=true)
Set this code block to be a fensed code block.
Definition doc.h:1419
void setInline(bool on=true)
Set this code to be inline.
Definition doc.h:1359
const Trait::String & text() const
Definition doc.h:1341
void setEndDelim(const WithPosition &d)
Set position of the ending service characters.
Definition doc.h:1407
void setStartDelim(const WithPosition &d)
Set position of the start service characters.
Definition doc.h:1395
bool isInline() const
Definition doc.h:1353
ItemType type() const override
Definition doc.h:1335
void setSyntax(const typename Trait::String &s)
Set syntax of the fensed code block.
Definition doc.h:1371
Document.
Definition doc.h:1801
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this document.
Definition doc.h:1813
std::shared_ptr< Heading< Trait > > HeadingSharedPointer
Type of a smart pointer to heading.
Definition doc.h:1868
std::shared_ptr< Link< Trait > > LinkSharedPointer
Type of a smart pointer to link.
Definition doc.h:1851
const LabeledLinks & labeledLinks() const
Definition doc.h:1856
void insertFootnote(const typename Trait::String &id, FootnoteSharedPointer fn)
Insert footnote with the give ID.
Definition doc.h:1845
typename Trait::template Map< typename Trait::String, HeadingSharedPointer > LabeledHeadings
Type of a map of headings.
Definition doc.h:1870
~Document() override=default
void insertLabeledHeading(const typename Trait::String &label, HeadingSharedPointer h)
Insert heading with the given label.
Definition doc.h:1879
const Footnotes & footnotesMap() const
Definition doc.h:1839
void insertLabeledLink(const typename Trait::String &label, LinkSharedPointer lnk)
Insert shortcut link with the given label.
Definition doc.h:1862
Document()=default
std::shared_ptr< Footnote< Trait > > FootnoteSharedPointer
Type of a smart pointer to footnote.
Definition doc.h:1834
const LabeledHeadings & labeledHeadings() const
Definition doc.h:1873
typename Trait::template Map< typename Trait::String, FootnoteSharedPointer > Footnotes
Type of a map of footnotes.
Definition doc.h:1836
typename Trait::template Map< typename Trait::String, LinkSharedPointer > LabeledLinks
Type of a map of shortcut links.
Definition doc.h:1853
ItemType type() const override
Definition doc.h:1807
Footnote reference.
Definition doc.h:1693
~FootnoteRef() override=default
void setIdPos(const WithPosition &pos)
Set position of ID.
Definition doc.h:1733
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this footnote reference.
Definition doc.h:1703
const Trait::String & id() const
Definition doc.h:1721
ItemType type() const override
Definition doc.h:1715
const WithPosition & idPos() const
Definition doc.h:1727
FootnoteRef(const typename Trait::String &i)
Definition doc.h:1695
Footnote.
Definition doc.h:1754
ItemType type() const override
Definition doc.h:1770
~Footnote() override=default
const WithPosition & idPos() const
Definition doc.h:1776
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this footnote.
Definition doc.h:1760
Footnote()=default
void setIdPos(const WithPosition &pos)
Set position of ID.
Definition doc.h:1782
Heading.
Definition doc.h:711
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this heading.
Definition doc.h:724
void setLabelVariants(const LabelsVector &vars)
Set label variants.
Definition doc.h:834
Heading()
Definition doc.h:713
void setLabel(const typename Trait::String &l)
Set label of the heading.
Definition doc.h:789
typename Trait::template Vector< WithPosition > Delims
Type of list of service chanracters.
Definition doc.h:721
const Delims & delims() const
Definition doc.h:795
void setDelims(const Delims &d)
Set list of service characters.
Definition doc.h:801
void setLevel(int l)
Set level of the heading.
Definition doc.h:771
typename Trait::template Vector< typename Trait::String > LabelsVector
Type of a vector of labels.
Definition doc.h:819
std::shared_ptr< Paragraph< Trait > > ParagraphSharedPointer
Type of smart pointer to paragraph.
Definition doc.h:750
ParagraphSharedPointer text() const
Definition doc.h:753
bool isLabeled() const
Definition doc.h:777
const WithPosition & labelPos() const
Definition doc.h:807
void setText(ParagraphSharedPointer t)
Set content of the heading.
Definition doc.h:759
void setLabelPos(const WithPosition &p)
Set position of a label in the heading.
Definition doc.h:813
int level() const
Definition doc.h:765
const LabelsVector & labelVariants() const
Definition doc.h:822
~Heading() override=default
LabelsVector & labelVariants()
Definition doc.h:828
ItemType type() const override
Definition doc.h:744
const Trait::String & label() const
Definition doc.h:783
Horizontal line.
Definition doc.h:365
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this horizontal line.
Definition doc.h:377
~HorizontalLine() override=default
HorizontalLine()=default
ItemType type() const override
Definition doc.h:371
Image.
Definition doc.h:1210
ItemType type() const override
Definition doc.h:1225
Image()=default
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this image.
Definition doc.h:1216
~Image() override=default
Base class for items that can have style options.
Definition doc.h:260
void setOpts(int o)
Set style options.
Definition doc.h:288
ItemWithOpts()=default
void applyItemWithOpts(const ItemWithOpts< Trait > &other)
Apply other item with options to this.
Definition doc.h:268
const Styles & closeStyles() const
Definition doc.h:306
Styles & closeStyles()
Definition doc.h:312
const Styles & openStyles() const
Definition doc.h:294
int opts() const
Definition doc.h:282
typename Trait::template Vector< StyleDelim > Styles
Type of list of emphasis.
Definition doc.h:279
Styles & openStyles()
Definition doc.h:300
~ItemWithOpts() override=default
Item()=default
virtual std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const =0
Clone this item.
virtual ItemType type() const =0
~Item() override=default
Line break.
Definition doc.h:571
ItemType type() const override
Definition doc.h:588
~LineBreak() override=default
LineBreak()=default
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this line break.
Definition doc.h:577
void setP(ParagraphSharedPointer v)
Set pointer to parsed text of link's description.
Definition doc.h:1159
std::shared_ptr< Paragraph< Trait > > ParagraphSharedPointer
Type of a smart pointer to link's description.
Definition doc.h:1120
void setUrlPos(const WithPosition &pos)
Set position of URL.
Definition doc.h:1183
void setTextPos(const WithPosition &pos)
Set position of link's description.
Definition doc.h:1171
~LinkBase() override=default
void setText(const typename Trait::String &t)
Set not parsed text of link's description.
Definition doc.h:1141
void applyLinkBase(const LinkBase< Trait > &other, Document< Trait > *doc=nullptr)
Apply other base of link to this.
Definition doc.h:1107
void setUrl(const typename Trait::String &u)
Set URL of the link.
Definition doc.h:1129
const WithPosition & textPos() const
Definition doc.h:1165
bool isEmpty() const
Definition doc.h:1147
const Trait::String & text() const
Not parsed text of link's description.
Definition doc.h:1135
const WithPosition & urlPos() const
Definition doc.h:1177
ParagraphSharedPointer p() const
Definition doc.h:1153
const Trait::String & url() const
Definition doc.h:1123
List item in a list.
Definition doc.h:913
OrderedListPreState
Preliminary state of the ordered list.
Definition doc.h:949
@ Start
Start item.
Definition doc.h:951
@ Continue
Continue of the list.
Definition doc.h:953
void setDelim(const WithPosition &d)
Set service character position.
Definition doc.h:1023
void setStartNumber(int n)
Set start number of the ordered list.
Definition doc.h:987
ItemType type() const override
Definition doc.h:935
ListType listType() const
Definition doc.h:957
~ListItem() override=default
const WithPosition & delim() const
Definition doc.h:1017
void setTaskDelim(const WithPosition &d)
Set position of the task list "checkbox" in Markdown.
Definition doc.h:1035
bool isChecked() const
Definition doc.h:1005
int startNumber() const
Definition doc.h:981
ListItem()=default
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this list item.
Definition doc.h:919
void setTaskList(bool on=true)
Set this list item to be a tsk list item.
Definition doc.h:999
void setChecked(bool on=true)
Set this task list item to be checked.
Definition doc.h:1011
OrderedListPreState orderedListPreState() const
Definition doc.h:969
bool isTaskList() const
Definition doc.h:993
void setListType(ListType t)
Set type of the list.
Definition doc.h:963
ListType
Type of the list.
Definition doc.h:941
@ Ordered
Ordered.
Definition doc.h:943
@ Unordered
Unordered.
Definition doc.h:945
const WithPosition & taskDelim() const
Definition doc.h:1029
void setOrderedListPreState(OrderedListPreState s)
Set preliminary state of the ordered list.
Definition doc.h:975
List.
Definition doc.h:1066
List()=default
~List() override=default
ItemType type() const override
Definition doc.h:1081
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this list.
Definition doc.h:1072
LaTeX math expression.
Definition doc.h:1450
ItemType type() const override
Definition doc.h:1471
~Math() override=default
const Trait::String & expr() const
Definition doc.h:1477
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this LaTeX math expression.
Definition doc.h:1460
Math()
Definition doc.h:1452
void setExpr(const typename Trait::String &e)
Set content.
Definition doc.h:1483
Page break.
Definition doc.h:335
ItemType type() const override
Definition doc.h:341
PageBreak()=default
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this page break.
Definition doc.h:347
~PageBreak() override=default
Paragraph.
Definition doc.h:680
ItemType type() const override
Definition doc.h:695
Paragraph()=default
~Paragraph() override=default
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this paragraph.
Definition doc.h:686
Raw HTML.
Definition doc.h:441
ItemType type() const override
Definition doc.h:460
~RawHtml() override=default
void setText(const typename Trait::String &t)
Set HTML content.
Definition doc.h:472
RawHtml()=default
friend class Parser
Definition doc.h:479
void setFreeTag(bool on=true)
Set that this HTML is a free, not inline one.
Definition doc.h:493
const Trait::String & text() const
Definition doc.h:466
friend struct UnprotectedDocsMethods
Definition doc.h:482
bool isFreeTag() const
Definition doc.h:486
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this raw HTML.
Definition doc.h:447
Emphasis in the Markdown document.
Definition doc.h:217
~StyleDelim() override=default
void setStyle(int t)
Set style.
Definition doc.h:238
StyleDelim(int s, long long int startColumn, long long int startLine, long long int endColumn, long long int endLine)
Definition doc.h:219
int style() const
Definition doc.h:232
Table cell.
Definition doc.h:1499
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this table cell.
Definition doc.h:1505
~TableCell() override=default
ItemType type() const override
Definition doc.h:1514
TableCell()=default
Table row.
Definition doc.h:1530
ItemType type() const override
Definition doc.h:1549
typename Trait::template Vector< TableCellSharedPointer > Cells
Type of a list of table cells.
Definition doc.h:1557
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this table row.
Definition doc.h:1536
~TableRow() override=default
const Cells & cells() const
Definition doc.h:1560
bool isEmpty() const
Definition doc.h:1572
void appendCell(TableCellSharedPointer c)
Append cell.
Definition doc.h:1566
std::shared_ptr< TableCell< Trait > > TableCellSharedPointer
Type of a smart pointer to table cell.
Definition doc.h:1555
TableRow()=default
Table.
Definition doc.h:1591
~Table() override=default
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this table.
Definition doc.h:1597
void setColumnAlignment(int idx, Alignment a)
Set alignment of the given column.
Definition doc.h:1656
std::shared_ptr< TableRow< Trait > > TableRowSharedPointer
Type of a smart pointer to table row.
Definition doc.h:1620
typename Trait::template Vector< TableRowSharedPointer > Rows
Type of list of rows.
Definition doc.h:1622
bool isEmpty() const
Definition doc.h:1672
Table()=default
ItemType type() const override
Definition doc.h:1614
Alignment
Alignment.
Definition doc.h:1637
@ AlignCenter
Center.
Definition doc.h:1643
@ AlignLeft
Left.
Definition doc.h:1639
@ AlignRight
Right.
Definition doc.h:1641
const Rows & rows() const
Definition doc.h:1625
void appendRow(TableRowSharedPointer r)
Append row.
Definition doc.h:1631
Alignment columnAlignment(int idx) const
Definition doc.h:1650
int columnsCount() const
Definition doc.h:1666
typename Trait::template Vector< Alignment > ColumnsAlignments
Type of list alignments.
Definition doc.h:1647
Text item in Paragraph.
Definition doc.h:514
std::shared_ptr< Item< Trait > > clone(Document< Trait > *doc=nullptr) const override
Clone this text item.
Definition doc.h:529
Text()=default
~Text() override=default
void setText(const typename Trait::String &t)
Set text content.
Definition doc.h:552
ItemType type() const override
Definition doc.h:540
void applyText(const Text< Trait > &t)
Apply other text to this.
Definition doc.h:520
const Trait::String & text() const
Definition doc.h:546
Base for any thing with start and end position.
Definition doc.h:77
WithPosition(long long int startColumn, long long int startLine, long long int endColumn, long long int endLine)
Definition doc.h:82
virtual ~WithPosition()=default
void setEndLine(long long int l)
Set end line.
Definition doc.h:144
WithPosition()=default
void setStartLine(long long int l)
Set start line.
Definition doc.h:132
void setEndColumn(long long int c)
Set end column.
Definition doc.h:138
long long int startColumn() const
Definition doc.h:102
void setStartColumn(long long int c)
Set start column.
Definition doc.h:126
long long int startLine() const
Definition doc.h:108
void applyPositions(const WithPosition &other)
Apply positions to this from other.
Definition doc.h:94
long long int endColumn() const
Definition doc.h:114
long long int endLine() const
Definition doc.h:120
Definition algo.h:17
TextOption
Text option.
Definition doc.h:200
@ ItalicText
Italic text.
Definition doc.h:206
@ StrikethroughText
Strikethrough.
Definition doc.h:208
@ TextWithoutFormat
No format.
Definition doc.h:202
@ BoldText
Bold text.
Definition doc.h:204
ItemType
Enumeration of item types.
Definition doc.h:24
@ Heading
Heading.
Definition doc.h:26
@ Document
Document.
Definition doc.h:56
@ Blockquote
Blockquote.
Definition doc.h:34
@ FootnoteRef
Footnote ref.
Definition doc.h:52
@ List
List.
Definition doc.h:38
@ Table
Table.
Definition doc.h:50
@ PageBreak
Page break.
Definition doc.h:58
@ Footnote
Footnote.
Definition doc.h:54
@ Link
Link.
Definition doc.h:40
@ Text
Text.
Definition doc.h:28
@ Anchor
Anchor.
Definition doc.h:60
@ Math
Math expression.
Definition doc.h:66
@ ListItem
List item.
Definition doc.h:36
@ Image
Image.
Definition doc.h:42
@ TableRow
Table row.
Definition doc.h:48
@ UserDefined
Start item for user-defined types.
Definition doc.h:68
@ Code
Code.
Definition doc.h:44
@ RawHtml
Raw HTML.
Definition doc.h:64
@ TableCell
Table cell.
Definition doc.h:46
@ HorizontalLine
Horizontal line.
Definition doc.h:62
@ LineBreak
Line break.
Definition doc.h:32
@ Paragraph
Paragraph.
Definition doc.h:30
bool operator==(const WithPosition &l, const WithPosition &r)
Definition doc.h:160
#define MD_DISABLE_COPY(Class)
Macro for disabling copy.
Definition utils.h:17
#define MD_UNUSED(x)
Avoid "unused parameter" warnings.
Definition utils.h:26
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:48:49 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.