Md4qt

html.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_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 this->m_doc->labeledHeadings().find(url) == this->m_doc->labeledHeadings().cend()) {
444 auto path = static_cast<Anchor<Trait> *>(this->m_doc->items().at(0).get())->label();
445 const auto sp = path.lastIndexOf(Trait::latin1ToString("/"));
446 path.remove(sp, path.length() - sp);
447 const auto p = url.indexOf(path) - 1;
448 url.remove(p, url.length() - p);
449 }
450
452 openStyle(l->openStyles());
453
454 m_html.push_back(Trait::latin1ToString("<a href=\""));
455 m_html.push_back(url);
456 m_html.push_back(Trait::latin1ToString("\">"));
457 }
458
459 if (l->p() && !l->p()->isEmpty()) {
460 onParagraph(l->p().get(), false);
461 } else if (!l->img()->isEmpty()) {
463 onImage(l->img().get());
464 }
465 } else if (!l->text().isEmpty()) {
467 m_html.push_back(prepareTextForHtml(l->text()));
468 }
469 } else {
471 m_html.push_back(prepareTextForHtml(l->url()));
472 }
473 }
474
476 m_html.push_back(Trait::latin1ToString("</a>"));
477
479 }
480 }
481
482 //! Handle image.
484 //! Image.
485 Image<Trait> *i) override
486 {
488 openStyle(i->openStyles());
489
490 m_html.push_back(Trait::latin1ToString("<img src=\""));
491 m_html.push_back(i->url());
492 m_html.push_back(Trait::latin1ToString("\" alt=\""));
493 m_html.push_back(prepareTextForHtml(i->text()));
494 m_html.push_back(Trait::latin1ToString("\" style=\"max-width:100%;\" />"));
495
497 }
498 }
499
500 //! Handle footnote reference.
502 //! Footnote reference.
503 FootnoteRef<Trait> *ref) override
504 {
505 const auto fit = this->m_doc->footnotesMap().find(ref->id());
506
507 if (fit != this->m_doc->footnotesMap().cend()) {
508 const auto r = std::find_if(m_fns.begin(), m_fns.end(), [&ref](const auto &stuff) {
509 return ref->id() == stuff.m_id;
510 });
511
513 openStyle(ref->openStyles());
514
515 m_html.push_back(Trait::latin1ToString("<sup>"));
516 m_html.push_back(Trait::latin1ToString("<a href=\"#"));
517 m_html.push_back(ref->id());
518 m_html.push_back(Trait::latin1ToString("\" id=\"ref-"));
519 m_html.push_back(ref->id());
520 m_html.push_back(Trait::latin1ToString("-"));
521 }
522
523 if (r == m_fns.end()) {
525 m_html.push_back(Trait::latin1ToString("1"));
526 }
527 } else {
529 m_html.push_back(Trait::latin1ToString(std::to_string(++(r->m_current)).c_str()));
530 }
531
533 ++(r->m_count);
534 }
535 }
536
538 m_html.push_back(Trait::latin1ToString("\">"));
539 }
540
541 if (r == m_fns.end()) {
543 m_html.push_back(Trait::latin1ToString(std::to_string(m_fns.size() + 1).c_str()));
544 }
545
546 m_fns.push_back({ref->id(), 1, 0});
547 } else if (!m_justCollectFootnoteRefs)
548 m_html.push_back(Trait::latin1ToString(std::to_string(std::distance(m_fns.begin(), r) + 1).c_str()));
549
551 m_html.push_back(Trait::latin1ToString("</a></sup>"));
552
553 closeStyle(ref->closeStyles());
554 }
555 } else
556 onText(static_cast<Text<Trait> *>(ref));
557 }
558
559 //! Handle list item.
561 //! List item.
563 //! Is this item first in the list?
564 bool first) override
565 {
567 m_html.push_back(Trait::latin1ToString("<li"));
568
569 if (i->isTaskList()) {
570 m_html.push_back(
571 Trait::latin1ToString(" class=\"task-list-item\"><input "
572 "type=\"checkbox\" id=\"\" disabled=\"\" class=\"task-list-item-checkbox\""));
573
574 if (i->isChecked()) {
575 m_html.push_back(Trait::latin1ToString(" checked=\"\""));
576 }
577 }
578
579 if (i->listType() == ListItem<Trait>::Ordered && first) {
580 m_html.push_back(Trait::latin1ToString(" value=\""));
581 m_html.push_back(Trait::latin1ToString(std::to_string(i->startNumber()).c_str()));
582 m_html.push_back(Trait::latin1ToString("\""));
583 }
584
585 m_html.push_back(Trait::latin1ToString(">\n"));
586 }
587
589
591 m_html.push_back(Trait::latin1ToString("</li>\n"));
592 }
593 }
594
595 //! Handle heading.
596 virtual void onHeading(
597 //! Heading.
599 //! Heading tag.
600 const typename Trait::String &ht)
601 {
603 m_html.push_back(Trait::latin1ToString("<"));
604 m_html.push_back(ht);
605 m_html.push_back(headingIdToHtml(h));
606 m_html.push_back(Trait::latin1ToString(" dir=\"auto\">"));
607 }
608
609 if (h->text().get()) {
610 onParagraph(h->text().get(), false);
611 }
612
614 m_html.push_back(Trait::latin1ToString("</"));
615 m_html.push_back(ht);
616 m_html.push_back(Trait::latin1ToString(">"));
617 }
618 }
619
620 //! Handle footnotes.
621 virtual void onFootnotes(const typename Trait::String &hrefForRefBackImage)
622 {
623 if (!m_fns.empty()) {
624 m_html.push_back(Trait::latin1ToString("<section class=\"footnotes\"><ol dir=\"auto\">"));
625 }
626
627 int i = 1;
628
629 const auto tmpm_fns = m_fns;
631
632 for (const auto &id : tmpm_fns) {
633 const auto fit = this->m_doc->footnotesMap().find(id.m_id);
634
635 if (fit != this->m_doc->footnotesMap().cend()) {
636 this->onFootnote(fit->second.get());
637 }
638 }
639
642
643 for (const auto &id : m_fns) {
644 m_html.push_back(Trait::latin1ToString("<li id=\""));
645 m_html.push_back(id.m_id);
646 m_html.push_back(Trait::latin1ToString("\">"));
647 ++i;
648
649 const auto fit = this->m_doc->footnotesMap().find(id.m_id);
650
651 if (fit != this->m_doc->footnotesMap().cend()) {
652 this->onFootnote(fit->second.get());
653
654 if (!hrefForRefBackImage.isEmpty()) {
655 typename Trait::String backRef;
656 long long int backRefPos = m_html.endsWith(Trait::latin1ToString("</p>")) ? 4 : 0;
657
658 for (long long int i = 1; i <= id.m_count; ++i) {
659 backRef.push_back(Trait::latin1ToString("<a href=\"#ref-"));
660 backRef.push_back(id.m_id);
661 backRef.push_back(Trait::latin1ToString("-"));
662 backRef.push_back(Trait::latin1ToString(std::to_string(i).c_str()));
663 backRef.push_back(Trait::latin1ToString("\"><img src=\""));
664 backRef.push_back(hrefForRefBackImage);
665 backRef.push_back(Trait::latin1ToString("\" /></a>"));
666 }
667
668 m_html.insert(m_html.length() - backRefPos, backRef);
669 }
670
671 m_html.push_back(Trait::latin1ToString("</li>"));
672 }
673 }
674
675 if (!m_fns.empty()) {
676 m_html.push_back(Trait::latin1ToString("</ol></section>\n"));
677 }
678 }
679
680 //! \return HTML content for heading's ID.
681 virtual typename Trait::String headingIdToHtml(Heading<Trait> *h)
682 {
683 typename Trait::String html;
684
685 if (h->isLabeled()) {
686 html.push_back(Trait::latin1ToString(" id=\""));
687 auto label = h->label();
688 if (label.startsWith(Trait::latin1ToString("#"))) {
689 label.remove(0, 1);
690 }
691 html.push_back(label);
692 html.push_back(Trait::latin1ToString("\""));
693 }
694
695 return html;
696 }
697
698 //! Prepare text to insert into HTML content.
699 virtual typename Trait::String prepareTextForHtml(const typename Trait::String &t)
700 {
701 auto tmp = t;
702 tmp.replace(Trait::latin1ToChar('&'), Trait::latin1ToString("&amp;"));
703 tmp.replace(Trait::latin1ToChar('<'), Trait::latin1ToString("&lt;"));
704 tmp.replace(Trait::latin1ToChar('>'), Trait::latin1ToString("&gt;"));
705
706 return tmp;
707 }
708
709 //! \return HTML content for table alignment.
710 virtual typename Trait::String tableAlignmentToHtml(typename Table<Trait>::Alignment a)
711 {
712 typename Trait::String html;
713
714 switch (a) {
716 html.push_back(Trait::latin1ToString(" align=\"left\""));
717 break;
718
720 html.push_back(Trait::latin1ToString(" align=\"center\""));
721 break;
722
724 html.push_back(Trait::latin1ToString(" align=\"right\""));
725 break;
726
727 default:
728 break;
729 }
730
731 return html;
732 }
733
734protected:
735 //! HTML content.
736 typename Trait::String m_html;
737 //! Just collect footnote references?
739 //! Just process footnote references and don't increment count number.
741 //! Is this HTML wrapped in artcile tag?
743
744 //! Auxiliary struct to process footnotes.
746 //! ID of footnote.
747 typename Trait::String m_id;
748 //! Count of references with this ID.
749 long long int m_count = 0;
750 //! Number of footnote reference with this ID.
751 long long int m_current = 0;
752 };
753
754 //! Vector of processed footnotes references.
755 typename Trait::template Vector<FootnoteRefStuff> m_fns;
756}; // class HtmlVisitor
757
758} /* namespace details */
759
760//! Convert Document to HTML.
761template<class Trait, class HtmlVisitor = details::HtmlVisitor<Trait>>
762typename Trait::String
764 //! Markdown document.
765 std::shared_ptr<Document<Trait>> doc,
766 //! Wrap HTML into <body> tag?
767 bool wrapInBodyTag = true,
768 //! String that will be applied as URL for image for back link from footnote.
769 const typename Trait::String &hrefForRefBackImage = {},
770 //! Wrap HTML with <article> tag?
771 bool wrapInArticle = true)
772{
773 typename Trait::String html;
774
775 if (wrapInBodyTag) {
776 html.push_back(Trait::latin1ToString("<!DOCTYPE html>\n<html><head></head><body>\n"));
777 }
778
779 if (wrapInArticle) {
780 html.push_back(Trait::latin1ToString("<article class=\"markdown-body\">"));
781 }
782
783 HtmlVisitor visitor;
784
785 html.push_back(visitor.toHtml(doc, hrefForRefBackImage, wrapInArticle));
786
787 if (wrapInArticle) {
788 html.push_back(Trait::latin1ToString("</article>\n"));
789 }
790
791 if (wrapInBodyTag) {
792 html.push_back(Trait::latin1ToString("</body></html>\n"));
793 }
794
795 return html;
796}
797
798} /* namespace MD */
799
800#endif // MD4QT_MD_HTML_HPP_INCLUDED
Just an anchor.
Definition doc.h:397
const Trait::String & label() const
Definition doc.h:421
const Items & items() const
Definition doc.h:629
Blockquote.
Definition doc.h:836
Code.
Definition doc.h:1269
const Trait::String & syntax() const
Definition doc.h:1338
const Trait::String & text() const
Definition doc.h:1314
bool isInline() const
Definition doc.h:1326
Document.
Definition doc.h:1774
Footnote reference.
Definition doc.h:1666
const Trait::String & id() const
Definition doc.h:1694
Heading.
Definition doc.h:710
ParagraphSharedPointer text() const
Definition doc.h:749
bool isLabeled() const
Definition doc.h:773
int level() const
Definition doc.h:761
const Trait::String & label() const
Definition doc.h:779
Horizontal line.
Definition doc.h:364
Image.
Definition doc.h:1183
const Styles & closeStyles() const
Definition doc.h:305
const Styles & openStyles() const
Definition doc.h:293
typename Trait::template Vector< StyleDelim > Styles
Type of list of emphasis.
Definition doc.h:278
Line break.
Definition doc.h:570
const Trait::String & text() const
Not parsed text of link's description.
Definition doc.h:1108
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
ListType listType() const
Definition doc.h:930
bool isChecked() const
Definition doc.h:978
int startNumber() const
Definition doc.h:954
bool isTaskList() const
Definition doc.h:966
ListType
Type of the list.
Definition doc.h:914
List.
Definition doc.h:1039
LaTeX math expression.
Definition doc.h:1423
const Trait::String & expr() const
Definition doc.h:1450
Paragraph.
Definition doc.h:679
Raw HTML.
Definition doc.h:440
const Trait::String & text() const
Definition doc.h:465
Table.
Definition doc.h:1564
bool isEmpty() const
Definition doc.h:1645
Alignment
Alignment.
Definition doc.h:1610
const Rows & rows() const
Definition doc.h:1598
Alignment columnAlignment(int idx) const
Definition doc.h:1623
Text item in Paragraph.
Definition doc.h:513
const Trait::String & text() const
Definition doc.h:545
Visitor interface to walk through Document.
Definition visitor.h:27
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
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
HTML visitor interface to walk through Document.
Definition html.h:31
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:755
virtual Trait::String tableAlignmentToHtml(typename Table< Trait >::Alignment a)
Definition html.h:710
void onListItem(ListItem< Trait > *i, bool first) override
Handle list item.
Definition html.h:560
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:740
Trait::String m_html
HTML content.
Definition html.h:736
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:483
bool m_justCollectFootnoteRefs
Just collect footnote references?
Definition html.h:738
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:699
virtual void onFootnotes(const typename Trait::String &hrefForRefBackImage)
Handle footnotes.
Definition html.h:621
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:742
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:681
virtual void onHeading(Heading< Trait > *h, const typename Trait::String &ht)
Handle heading.
Definition html.h:596
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:501
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:205
@ StrikethroughText
Strikethrough.
Definition doc.h:207
@ BoldText
Bold text.
Definition doc.h:203
@ ListItem
List item.
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:763
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:745
Trait::String m_id
ID of footnote.
Definition html.h:747
long long int m_count
Count of references with this ID.
Definition html.h:749
long long int m_current
Number of footnote reference with this ID.
Definition html.h:751
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:36 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.