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

KDE's Doxygen guidelines are available online.