Md4qt

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

KDE's Doxygen guidelines are available online.