Md4qt

html.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_HTML_HPP_INCLUDED
7#define MD4QT_MD_HTML_HPP_INCLUDED
8
9// md4qt include.
10#include "doc.h"
11#include "visitor.h"
12
13// C++ include.
14#include <algorithm>
15#include <string>
16#include <utility>
17
18namespace MD
19{
20
21namespace details
22{
23
24//
25// HtmlVisitor
26//
27
28//! HTML visitor interface to walk through Document.
29template<class Trait>
30class HtmlVisitor : public Visitor<Trait>
31{
32public:
33 HtmlVisitor() = default;
34 ~HtmlVisitor() override = default;
35
36 //! Walk through the document.
37 virtual typename Trait::String toHtml(std::shared_ptr<Document<Trait>> doc,
38 const typename Trait::String &hrefForRefBackImage,
39 bool wrappedInArticle = true)
40 {
41 m_isWrappedInArticle = wrappedInArticle;
42
43 m_html.clear();
44 m_fns.clear();
45
46 this->process(doc);
47
48 onFootnotes(hrefForRefBackImage);
49
50 return m_html;
51 }
52
53protected:
54 //! Insert into HTML tags for opening styles.
55 virtual void openStyle(const typename ItemWithOpts<Trait>::Styles &styles)
56 {
57 for (const auto &s : styles) {
58 switch (s.style()) {
60 m_html.push_back(Trait::latin1ToString("<strong>"));
61 break;
62
64 m_html.push_back(Trait::latin1ToString("<em>"));
65 break;
66
68 m_html.push_back(Trait::latin1ToString("<del>"));
69 break;
70
71 default:
72 break;
73 }
74 }
75 }
76
77 //! Insert into HTML tags for closing styles.
78 virtual void closeStyle(const typename ItemWithOpts<Trait>::Styles &styles)
79 {
80 for (const auto &s : styles) {
81 switch (s.style()) {
83 m_html.push_back(Trait::latin1ToString("</strong>"));
84 break;
85
87 m_html.push_back(Trait::latin1ToString("</em>"));
88 break;
89
91 m_html.push_back(Trait::latin1ToString("</del>"));
92 break;
93
94 default:
95 break;
96 }
97 }
98 }
99
100 //! Handle new line in HTML.
101 void onAddLineEnding() override
102 {
104 m_html.push_back(Trait::latin1ToString("\n"));
105 }
106
107 //! Handle text item.
108 void onText(
109 //! Text.
110 Text<Trait> *t) override
111 {
113 openStyle(t->openStyles());
114
115 m_html.push_back(prepareTextForHtml(t->text()));
116
118 }
119 }
120
121 //! Handle LaTeX math expression.
122 void onMath(
123 //! Math.
124 Math<Trait> *m) override
125 {
127 openStyle(m->openStyles());
128
129 m_html.push_back(m->isInline() ? Trait::latin1ToString("$") : Trait::latin1ToString("$$"));
130 m_html.push_back(prepareTextForHtml(m->expr()));
131 m_html.push_back(m->isInline() ? Trait::latin1ToString("$") : Trait::latin1ToString("$$"));
132
134 }
135 }
136
137 //! Handle line break.
139 //! Linebreak.
140 LineBreak<Trait> *) override
141 {
143 m_html.push_back(Trait::latin1ToString("<br />"));
144 }
145 }
146
147 //! Handle paragraph.
149 //! Paragraph.
151 //! Wrap this paragraph with something or no? It's useful to not wrap standalone
152 //! paragraph in list item, for example.
153 bool wrap) override
154 {
155 if (wrap && !m_justCollectFootnoteRefs) {
156 m_html.push_back(Trait::latin1ToString("<p dir=\"auto\">"));
157 }
158
160
161 if (wrap && !m_justCollectFootnoteRefs) {
162 m_html.push_back(Trait::latin1ToString("</p>"));
163 }
164 }
165
166 //! Handle heading.
168 //! Heading.
169 Heading<Trait> *h) override
170 {
172 m_html.push_back(Trait::latin1ToString("\n"));
173 }
174
175 switch (h->level()) {
176 case 1:
177 case 2:
178 case 3:
179 case 4:
180 case 5:
181 case 6:
182 onHeading(h, Trait::latin1ToString("h") + Trait::latin1ToString(std::to_string(h->level()).c_str()));
183 break;
184
185 default:
186 break;
187 }
188
190 m_html.push_back(Trait::latin1ToString("\n"));
191 }
192 }
193
194 //! Handle code block.
195 void onCode(
196 //! Code.
197 Code<Trait> *c) override
198 {
200 m_html.push_back(Trait::latin1ToString("\n"));
201 m_html.push_back(Trait::latin1ToString("<pre><code"));
202
203 if (!c->syntax().isEmpty()) {
204 m_html.push_back(Trait::latin1ToString(" class=\"language-"));
205 m_html.push_back(c->syntax());
206 m_html.push_back(Trait::latin1ToString("\""));
207 }
208
209 m_html.push_back(Trait::latin1ToString(">"));
210 m_html.push_back(prepareTextForHtml(c->text()));
211 m_html.push_back(Trait::latin1ToString("</code></pre>"));
212 m_html.push_back(Trait::latin1ToString("\n"));
213 }
214 }
215
216 //! Handle inline code.
218 //! Code.
219 Code<Trait> *c) override
220 {
222 openStyle(c->openStyles());
223
224 m_html.push_back(Trait::latin1ToString("<code>"));
225
226 m_html.push_back(prepareTextForHtml(c->text()));
227
228 m_html.push_back(Trait::latin1ToString("</code>"));
229
231 }
232 }
233
234 //! Handle blockquote.
236 //! Blockquote.
237 Blockquote<Trait> *b) override
238 {
240 m_html.push_back(Trait::latin1ToString("\n<blockquote>"));
241 }
242
244
246 m_html.push_back(Trait::latin1ToString("</blockquote>\n"));
247 }
248 }
249
250 //! Handle list.
251 void onList(
252 //! List.
253 List<Trait> *l) override
254 {
256 m_html.push_back(Trait::latin1ToString("\n"));
257 }
258
260 bool first = true;
261
262 for (auto it = l->items().cbegin(), last = l->items().cend(); it != last; ++it) {
263 if ((*it)->type() == ItemType::ListItem) {
264 auto *item = static_cast<ListItem<Trait> *>(it->get());
265
266 if (first) {
267 type = item->listType();
268
269 if (type == ListItem<Trait>::Ordered) {
271 m_html.push_back(Trait::latin1ToString("<ol"));
272
273 if (item->isTaskList()) {
274 m_html.push_back(Trait::latin1ToString(" class=\"contains-task-list\""));
275 }
276
277 m_html.push_back(Trait::latin1ToString(" dir=\"auto\">\n"));
278 }
279 } else {
281 m_html.push_back(Trait::latin1ToString("<ul"));
282
283 if (item->isTaskList()) {
284 m_html.push_back(Trait::latin1ToString(" class=\"contains-task-list\""));
285 }
286
287 m_html.push_back(Trait::latin1ToString(" dir=\"auto\">\n"));
288 }
289 }
290 }
291
292 onListItem(item, first);
293
294 first = false;
295 }
296 }
297
298 if (!first) {
300 if (type == ListItem<Trait>::Ordered) {
301 m_html.push_back(Trait::latin1ToString("</ol>\n"));
302 } else {
303 m_html.push_back(Trait::latin1ToString("</ul>\n"));
304 }
305 }
306 }
307 }
308
309 //! Handle table.
311 //! Table.
312 Table<Trait> *t) override
313 {
315 m_html.push_back(Trait::latin1ToString("\n"));
316 }
317
318 if (!t->isEmpty()) {
320 m_html.push_back(Trait::latin1ToString("<table><thead><tr>\n"));
321 }
322
323 int columns = 0;
324
325 for (auto th = (*t->rows().cbegin())->cells().cbegin(), last = (*t->rows().cbegin())->cells().cend(); th != last; ++th) {
327 m_html.push_back(Trait::latin1ToString("<th"));
328 m_html.push_back(tableAlignmentToHtml(t->columnAlignment(columns)));
329 m_html.push_back(Trait::latin1ToString(" dir=\"auto\">\n"));
330 }
331
332 this->onTableCell(th->get());
333
335 m_html.push_back(Trait::latin1ToString("\n</th>\n"));
336 }
337
338 ++columns;
339 }
340
342 m_html.push_back(Trait::latin1ToString("</tr></thead><tbody>\n"));
343 }
344
345 for (auto r = std::next(t->rows().cbegin()), rlast = t->rows().cend(); r != rlast; ++r) {
347 m_html.push_back(Trait::latin1ToString("<tr>\n"));
348 }
349
350 int i = 0;
351
352 for (auto c = (*r)->cells().cbegin(), clast = (*r)->cells().cend(); c != clast; ++c) {
354 m_html.push_back(Trait::latin1ToString("\n<td"));
356 m_html.push_back(Trait::latin1ToString(" dir=\"auto\">\n"));
357 }
358
359 this->onTableCell(c->get());
360
362 m_html.push_back(Trait::latin1ToString("\n</td>\n"));
363 }
364
365 ++i;
366
367 if (i == columns) {
368 break;
369 }
370 }
371
373 for (; i < columns; ++i) {
374 m_html.push_back(Trait::latin1ToString("<td dir=\"auto\"></td>"));
375 }
376
377 m_html.push_back(Trait::latin1ToString("\n</tr>\n"));
378 }
379 }
380
382 m_html.push_back(Trait::latin1ToString("</tbody></table>"));
383 }
384 }
385
387 m_html.push_back(Trait::latin1ToString("\n"));
388 }
389 }
390
391 //! Handle anchor.
393 //! Anchor.
394 Anchor<Trait> *a) override
395 {
397 m_html.push_back(Trait::latin1ToString("\n<div id=\""));
398 m_html.push_back(a->label());
399 m_html.push_back(Trait::latin1ToString("\"></div>\n"));
400 }
401 }
402
403 //! Handle raw HTML.
405 //! Raw HTML.
406 RawHtml<Trait> *h) override
407 {
409 openStyle(h->openStyles());
410
411 m_html.push_back(h->text());
412
414 }
415 }
416
417 //! Handle horizontal line.
419 //! Horizontal line.
420 HorizontalLine<Trait> *) override
421 {
423 m_html.push_back(Trait::latin1ToString("<hr />"));
424 }
425 }
426
427 //! Handle link.
428 void onLink(
429 //! Link.
430 Link<Trait> *l) override
431 {
432 typename Trait::String url = l->url();
433
434 const auto lit = this->m_doc->labeledLinks().find(url);
435
436 if (lit != this->m_doc->labeledLinks().cend()) {
437 url = lit->second->url();
438 }
439
440 if (std::find(this->m_anchors.cbegin(), this->m_anchors.cend(), url) != this->m_anchors.cend()) {
441 url = Trait::latin1ToString("#") + url;
442 } else if (url.startsWith(Trait::latin1ToString("#"))) {
443 const auto it = this->m_doc->labeledHeadings().find(url);
444
445 if (it == this->m_doc->labeledHeadings().cend()) {
446 auto path = static_cast<Anchor<Trait> *>(this->m_doc->items().at(0).get())->label();
447 const auto sp = path.lastIndexOf(Trait::latin1ToString("/"));
448 path.remove(sp, path.length() - sp);
449 const auto p = url.indexOf(path) - 1;
450 url.remove(p, url.length() - p);
451 } else {
452 url = it->second->label();
453 }
454 }
455
457 openStyle(l->openStyles());
458
459 m_html.push_back(Trait::latin1ToString("<a href=\""));
460 m_html.push_back(url);
461 m_html.push_back(Trait::latin1ToString("\">"));
462 }
463
464 if (l->p() && !l->p()->isEmpty()) {
465 onParagraph(l->p().get(), false);
466 } else if (!l->img()->isEmpty()) {
468 onImage(l->img().get());
469 }
470 } else if (!l->text().isEmpty()) {
472 m_html.push_back(prepareTextForHtml(l->text()));
473 }
474 } else {
476 m_html.push_back(prepareTextForHtml(l->url()));
477 }
478 }
479
481 m_html.push_back(Trait::latin1ToString("</a>"));
482
484 }
485 }
486
487 //! Handle image.
489 //! Image.
490 Image<Trait> *i) override
491 {
493 openStyle(i->openStyles());
494
495 m_html.push_back(Trait::latin1ToString("<img src=\""));
496 m_html.push_back(i->url());
497 m_html.push_back(Trait::latin1ToString("\" alt=\""));
498 m_html.push_back(prepareTextForHtml(i->text()));
499 m_html.push_back(Trait::latin1ToString("\" style=\"max-width:100%;\" />"));
500
502 }
503 }
504
505 //! Handle footnote reference.
507 //! Footnote reference.
508 FootnoteRef<Trait> *ref) override
509 {
510 const auto fit = this->m_doc->footnotesMap().find(ref->id());
511
512 if (fit != this->m_doc->footnotesMap().cend()) {
513 const auto r = std::find_if(m_fns.begin(), m_fns.end(), [&ref](const auto &stuff) {
514 return ref->id() == stuff.m_id;
515 });
516
518 openStyle(ref->openStyles());
519
520 m_html.push_back(Trait::latin1ToString("<sup>"));
521 m_html.push_back(Trait::latin1ToString("<a href=\"#"));
522 m_html.push_back(ref->id());
523 m_html.push_back(Trait::latin1ToString("\" id=\"ref-"));
524 m_html.push_back(ref->id());
525 m_html.push_back(Trait::latin1ToString("-"));
526 }
527
528 if (r == m_fns.end()) {
530 m_html.push_back(Trait::latin1ToString("1"));
531 }
532 } else {
534 m_html.push_back(Trait::latin1ToString(std::to_string(++(r->m_current)).c_str()));
535 }
536
538 ++(r->m_count);
539 }
540 }
541
543 m_html.push_back(Trait::latin1ToString("\">"));
544 }
545
546 if (r == m_fns.end()) {
548 m_html.push_back(Trait::latin1ToString(std::to_string(m_fns.size() + 1).c_str()));
549 }
550
551 m_fns.push_back({ref->id(), 1, 0});
552 } else if (!m_justCollectFootnoteRefs)
553 m_html.push_back(Trait::latin1ToString(std::to_string(std::distance(m_fns.begin(), r) + 1).c_str()));
554
556 m_html.push_back(Trait::latin1ToString("</a></sup>"));
557
558 closeStyle(ref->closeStyles());
559 }
560 } else
561 onText(static_cast<Text<Trait> *>(ref));
562 }
563
564 //! Handle list item.
566 //! List item.
568 //! Is this item first in the list?
569 bool first) override
570 {
572 m_html.push_back(Trait::latin1ToString("<li"));
573
574 if (i->isTaskList()) {
575 m_html.push_back(
576 Trait::latin1ToString(" class=\"task-list-item\"><input "
577 "type=\"checkbox\" id=\"\" disabled=\"\" class=\"task-list-item-checkbox\""));
578
579 if (i->isChecked()) {
580 m_html.push_back(Trait::latin1ToString(" checked=\"\""));
581 }
582 }
583
584 if (i->listType() == ListItem<Trait>::Ordered && first) {
585 m_html.push_back(Trait::latin1ToString(" value=\""));
586 m_html.push_back(Trait::latin1ToString(std::to_string(i->startNumber()).c_str()));
587 m_html.push_back(Trait::latin1ToString("\""));
588 }
589
590 m_html.push_back(Trait::latin1ToString(">\n"));
591 }
592
594
596 m_html.push_back(Trait::latin1ToString("</li>\n"));
597 }
598 }
599
600 //! Handle heading.
601 virtual void onHeading(
602 //! Heading.
604 //! Heading tag.
605 const typename Trait::String &ht)
606 {
608 m_html.push_back(Trait::latin1ToString("<"));
609 m_html.push_back(ht);
610 m_html.push_back(headingIdToHtml(h));
611 m_html.push_back(Trait::latin1ToString(" dir=\"auto\">"));
612 }
613
614 if (h->text().get()) {
615 onParagraph(h->text().get(), false);
616 }
617
619 m_html.push_back(Trait::latin1ToString("</"));
620 m_html.push_back(ht);
621 m_html.push_back(Trait::latin1ToString(">"));
622 }
623 }
624
625 //! Handle footnotes.
626 virtual void onFootnotes(const typename Trait::String &hrefForRefBackImage)
627 {
628 if (!m_fns.empty()) {
629 m_html.push_back(Trait::latin1ToString("<section class=\"footnotes\"><ol dir=\"auto\">"));
630 }
631
632 int i = 1;
633
634 const auto tmpm_fns = m_fns;
636
637 for (const auto &id : tmpm_fns) {
638 const auto fit = this->m_doc->footnotesMap().find(id.m_id);
639
640 if (fit != this->m_doc->footnotesMap().cend()) {
641 this->onFootnote(fit->second.get());
642 }
643 }
644
647
648 for (const auto &id : m_fns) {
649 m_html.push_back(Trait::latin1ToString("<li id=\""));
650 m_html.push_back(id.m_id);
651 m_html.push_back(Trait::latin1ToString("\">"));
652 ++i;
653
654 const auto fit = this->m_doc->footnotesMap().find(id.m_id);
655
656 if (fit != this->m_doc->footnotesMap().cend()) {
657 this->onFootnote(fit->second.get());
658
659 if (!hrefForRefBackImage.isEmpty()) {
660 typename Trait::String backRef;
661 long long int backRefPos = m_html.endsWith(Trait::latin1ToString("</p>")) ? 4 : 0;
662
663 for (long long int i = 1; i <= id.m_count; ++i) {
664 backRef.push_back(Trait::latin1ToString("<a href=\"#ref-"));
665 backRef.push_back(id.m_id);
666 backRef.push_back(Trait::latin1ToString("-"));
667 backRef.push_back(Trait::latin1ToString(std::to_string(i).c_str()));
668 backRef.push_back(Trait::latin1ToString("\"><img src=\""));
669 backRef.push_back(hrefForRefBackImage);
670 backRef.push_back(Trait::latin1ToString("\" /></a>"));
671 }
672
673 m_html.insert(m_html.length() - backRefPos, backRef);
674 }
675
676 m_html.push_back(Trait::latin1ToString("</li>"));
677 }
678 }
679
680 if (!m_fns.empty()) {
681 m_html.push_back(Trait::latin1ToString("</ol></section>\n"));
682 }
683 }
684
685 //! \return HTML content for heading's ID.
686 virtual typename Trait::String headingIdToHtml(Heading<Trait> *h)
687 {
688 typename Trait::String html;
689
690 if (h->isLabeled()) {
691 html.push_back(Trait::latin1ToString(" id=\""));
692 auto label = h->label();
693 if (label.startsWith(Trait::latin1ToString("#"))) {
694 label.remove(0, 1);
695 }
696 html.push_back(label);
697 html.push_back(Trait::latin1ToString("\""));
698 }
699
700 return html;
701 }
702
703 //! Prepare text to insert into HTML content.
704 virtual typename Trait::String prepareTextForHtml(const typename Trait::String &t)
705 {
706 auto tmp = t;
707 tmp.replace(Trait::latin1ToChar('&'), Trait::latin1ToString("&amp;"));
708 tmp.replace(Trait::latin1ToChar('<'), Trait::latin1ToString("&lt;"));
709 tmp.replace(Trait::latin1ToChar('>'), Trait::latin1ToString("&gt;"));
710
711 return tmp;
712 }
713
714 //! \return HTML content for table alignment.
715 virtual typename Trait::String tableAlignmentToHtml(typename Table<Trait>::Alignment a)
716 {
717 typename Trait::String html;
718
719 switch (a) {
721 html.push_back(Trait::latin1ToString(" align=\"left\""));
722 break;
723
725 html.push_back(Trait::latin1ToString(" align=\"center\""));
726 break;
727
729 html.push_back(Trait::latin1ToString(" align=\"right\""));
730 break;
731
732 default:
733 break;
734 }
735
736 return html;
737 }
738
739protected:
740 //! HTML content.
741 typename Trait::String m_html;
742 //! Just collect footnote references?
744 //! Just process footnote references and don't increment count number.
746 //! Is this HTML wrapped in artcile tag?
748
749 //! Auxiliary struct to process footnotes.
751 //! ID of footnote.
752 typename Trait::String m_id;
753 //! Count of references with this ID.
754 long long int m_count = 0;
755 //! Number of footnote reference with this ID.
756 long long int m_current = 0;
757 };
758
759 //! Vector of processed footnotes references.
760 typename Trait::template Vector<FootnoteRefStuff> m_fns;
761}; // class HtmlVisitor
762
763} /* namespace details */
764
765//! Convert Document to HTML.
766template<class Trait, class HtmlVisitor = details::HtmlVisitor<Trait>>
767typename Trait::String
769 //! Markdown document.
770 std::shared_ptr<Document<Trait>> doc,
771 //! Wrap HTML into <body> tag?
772 bool wrapInBodyTag = true,
773 //! String that will be applied as URL for image for back link from footnote.
774 const typename Trait::String &hrefForRefBackImage = {},
775 //! Wrap HTML with <article> tag?
776 bool wrapInArticle = true)
777{
778 typename Trait::String html;
779
780 if (wrapInBodyTag) {
781 html.push_back(Trait::latin1ToString("<!DOCTYPE html>\n<html><head></head><body>\n"));
782 }
783
784 if (wrapInArticle) {
785 html.push_back(Trait::latin1ToString("<article class=\"markdown-body\">"));
786 }
787
788 HtmlVisitor visitor;
789
790 html.push_back(visitor.toHtml(doc, hrefForRefBackImage, wrapInArticle));
791
792 if (wrapInArticle) {
793 html.push_back(Trait::latin1ToString("</article>\n"));
794 }
795
796 if (wrapInBodyTag) {
797 html.push_back(Trait::latin1ToString("</body></html>\n"));
798 }
799
800 return html;
801}
802
803} /* namespace MD */
804
805#endif // MD4QT_MD_HTML_HPP_INCLUDED
Just an anchor.
Definition doc.h:398
const Trait::String & label() const
Definition doc.h:422
const Items & items() const
Definition doc.h:630
Blockquote.
Definition doc.h:863
Code.
Definition doc.h:1296
const Trait::String & syntax() const
Definition doc.h:1365
const Trait::String & text() const
Definition doc.h:1341
bool isInline() const
Definition doc.h:1353
Document.
Definition doc.h:1801
Footnote reference.
Definition doc.h:1693
const Trait::String & id() const
Definition doc.h:1721
Heading.
Definition doc.h:711
ParagraphSharedPointer text() const
Definition doc.h:753
bool isLabeled() const
Definition doc.h:777
int level() const
Definition doc.h:765
const Trait::String & label() const
Definition doc.h:783
Horizontal line.
Definition doc.h:365
Image.
Definition doc.h:1210
const Styles & closeStyles() const
Definition doc.h:306
const Styles & openStyles() const
Definition doc.h:294
typename Trait::template Vector< StyleDelim > Styles
Type of list of emphasis.
Definition doc.h:279
Line break.
Definition doc.h:571
const Trait::String & text() const
Not parsed text of link's description.
Definition doc.h:1135
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
ListType listType() const
Definition doc.h:957
bool isChecked() const
Definition doc.h:1005
int startNumber() const
Definition doc.h:981
bool isTaskList() const
Definition doc.h:993
ListType
Type of the list.
Definition doc.h:941
@ Ordered
Ordered.
Definition doc.h:943
List.
Definition doc.h:1066
LaTeX math expression.
Definition doc.h:1450
const Trait::String & expr() const
Definition doc.h:1477
Paragraph.
Definition doc.h:680
Raw HTML.
Definition doc.h:441
const Trait::String & text() const
Definition doc.h:466
Table.
Definition doc.h:1591
bool isEmpty() const
Definition doc.h:1672
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
Alignment columnAlignment(int idx) const
Definition doc.h:1650
Text item in Paragraph.
Definition doc.h:514
const Trait::String & text() const
Definition doc.h:546
virtual void onFootnote(Footnote< Trait > *f)
Handle footnote.
Definition visitor.h:389
virtual void onListItem(ListItem< Trait > *i, bool first)
Handle list item.
Definition visitor.h:292
virtual void onBlockquote(Blockquote< Trait > *b)
Handle blockquote.
Definition visitor.h:203
virtual void onTableCell(TableCell< Trait > *c)
Handle table cell.
Definition visitor.h:345
Trait::template Vector< typename Trait::String > m_anchors
All available m_anchors in the document.
Definition visitor.h:439
std::shared_ptr< Document< Trait > > m_doc
Document.
Definition visitor.h:441
Visitor()=default
virtual void onParagraph(Paragraph< Trait > *p, bool wrap)
Handle paragraph.
Definition visitor.h:126
void process(std::shared_ptr< Document< Trait > > d)
Walk through the document.
Definition visitor.h:33
void onList(List< Trait > *l) override
Handle list.
Definition html.h:251
void onAddLineEnding() override
Handle new line in HTML.
Definition html.h:101
virtual void openStyle(const typename ItemWithOpts< Trait >::Styles &styles)
Insert into HTML tags for opening styles.
Definition html.h:55
Trait::template Vector< FootnoteRefStuff > m_fns
Vector of processed footnotes references.
Definition html.h:760
virtual Trait::String tableAlignmentToHtml(typename Table< Trait >::Alignment a)
Definition html.h:715
void onListItem(ListItem< Trait > *i, bool first) override
Handle list item.
Definition html.h:565
void onLineBreak(LineBreak< Trait > *) override
Handle line break.
Definition html.h:138
void onLink(Link< Trait > *l) override
Handle link.
Definition html.h:428
void onAnchor(Anchor< Trait > *a) override
Handle anchor.
Definition html.h:392
bool m_dontIncrementFootnoteCount
Just process footnote references and don't increment count number.
Definition html.h:745
Trait::String m_html
HTML content.
Definition html.h:741
void onBlockquote(Blockquote< Trait > *b) override
Handle blockquote.
Definition html.h:235
virtual void closeStyle(const typename ItemWithOpts< Trait >::Styles &styles)
Insert into HTML tags for closing styles.
Definition html.h:78
virtual Trait::String toHtml(std::shared_ptr< Document< Trait > > doc, const typename Trait::String &hrefForRefBackImage, bool wrappedInArticle=true)
Walk through the document.
Definition html.h:37
void onInlineCode(Code< Trait > *c) override
Handle inline code.
Definition html.h:217
void onImage(Image< Trait > *i) override
Handle image.
Definition html.h:488
bool m_justCollectFootnoteRefs
Just collect footnote references?
Definition html.h:743
void onText(Text< Trait > *t) override
Handle text item.
Definition html.h:108
virtual Trait::String prepareTextForHtml(const typename Trait::String &t)
Prepare text to insert into HTML content.
Definition html.h:704
virtual void onFootnotes(const typename Trait::String &hrefForRefBackImage)
Handle footnotes.
Definition html.h:626
void onTable(Table< Trait > *t) override
Handle table.
Definition html.h:310
bool m_isWrappedInArticle
Is this HTML wrapped in artcile tag?
Definition html.h:747
void onMath(Math< Trait > *m) override
Handle LaTeX math expression.
Definition html.h:122
~HtmlVisitor() override=default
void onCode(Code< Trait > *c) override
Handle code block.
Definition html.h:195
virtual Trait::String headingIdToHtml(Heading< Trait > *h)
Definition html.h:686
virtual void onHeading(Heading< Trait > *h, const typename Trait::String &ht)
Handle heading.
Definition html.h:601
void onRawHtml(RawHtml< Trait > *h) override
Handle raw HTML.
Definition html.h:404
void onFootnoteRef(FootnoteRef< Trait > *ref) override
Handle footnote reference.
Definition html.h:506
void onHeading(Heading< Trait > *h) override
Handle heading.
Definition html.h:167
void onParagraph(Paragraph< Trait > *p, bool wrap) override
Handle paragraph.
Definition html.h:148
void onHorizontalLine(HorizontalLine< Trait > *) override
Handle horizontal line.
Definition html.h:418
Definition algo.h:17
@ ItalicText
Italic text.
Definition doc.h:206
@ StrikethroughText
Strikethrough.
Definition doc.h:208
@ BoldText
Bold text.
Definition doc.h:204
@ ListItem
List item.
Definition doc.h:36
Trait::String toHtml(std::shared_ptr< Document< Trait > > doc, bool wrapInBodyTag=true, const typename Trait::String &hrefForRefBackImage={}, bool wrapInArticle=true)
Convert Document to HTML.
Definition html.h:768
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
qsizetype length() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
Auxiliary struct to process footnotes.
Definition html.h:750
Trait::String m_id
ID of footnote.
Definition html.h:752
long long int m_count
Count of references with this ID.
Definition html.h:754
long long int m_current
Number of footnote reference with this ID.
Definition html.h:756
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.