MD::details::HtmlVisitor Class
template <typename Trait> class MD::details::HtmlVisitorHTML visitor interface to walk through the MD:Document. More...
| Header: | #include <md4qt/html.h> |
| CMake: | find_package(md4qt REQUIRED COMPONENTS md4qt)target_link_libraries(mytarget PRIVATE md4qt::md4qt) |
| Inherits: | MD::Visitor |
Public Functions
| HtmlVisitor() | |
| virtual typename Trait::String | toHtml(std::shared_ptr<MD::Document<Trait>> doc, const typename Trait::String &footnoteBackLinkContent, bool wrappedInArticle = true, const MD::details::IdsMap<Trait> *idsMap = nullptr) |
Protected Types
| struct | FootnoteRefStuff |
Protected Functions
| virtual void | closeStyle(const typename ItemWithOpts<Trait>::Styles &styles) |
| virtual typename Trait::String | getId(MD::Item<Trait> *item) const |
| virtual typename Trait::String | headingIdToHtml(MD::Heading<Trait> *h) |
| void | onAddLineEnding() override |
| void | onAnchor(MD::Anchor<Trait> *a) override |
| void | onBlockquote(MD::Blockquote<Trait> *b) override |
| void | onCode(MD::Code<Trait> *c) override |
| void | onFootnoteRef(MD::FootnoteRef<Trait> *ref) override |
| virtual void | onFootnotes(const typename Trait::String &footnoteBackLinkContent) |
| void | onHeading(MD::Heading<Trait> *h) override |
| virtual void | onHeading(MD::Heading<Trait> *h, const typename Trait::String &ht) |
| void | onHorizontalLine(MD::HorizontalLine<Trait> *) override |
| void | onImage(MD::Image<Trait> *i) override |
| void | onInlineCode(MD::Code<Trait> *c) override |
| void | onLineBreak(MD::LineBreak<Trait> *) override |
| void | onLink(MD::Link<Trait> *l) override |
| void | onList(MD::List<Trait> *l) override |
| void | onListItem(MD::ListItem<Trait> *i, bool first, bool skipOpeningWrap = false) override |
| void | onMath(MD::Math<Trait> *m) override |
| void | onParagraph(MD::Paragraph<Trait> *p, bool wrap, bool skipOpeningWrap = false) override |
| void | onRawHtml(MD::RawHtml<Trait> *h) override |
| void | onTable(MD::Table<Trait> *t) override |
| void | onText(MD::Text<Trait> *t) override |
| virtual void | openStyle(const typename ItemWithOpts<Trait>::Styles &styles) |
| virtual typename Trait::String | prepareTextForHtml(const typename Trait::String &t) |
| virtual void | printId(MD::Item<Trait> *item) |
| virtual typename Trait::String | tableAlignmentToHtml(typename Table<Trait>::Alignment a) |
Protected Variables
| bool | m_dontIncrementFootnoteCount |
| typename Trait::template Vector<FootnoteRefStuff> | m_fns |
| typename Trait::String | m_html |
| const MD::details::IdsMap<Trait> * | m_idsMap |
| bool | m_isWrappedInArticle |
| bool | m_justCollectFootnoteRefs |
Detailed Description
This is visitor to convert Markdown document to HTML string. This class is highly customizable, absolutelly everything may be overriden, all data members are protected so a developer won't have problems with customizaion.
As example of customization have a look at the following code.
class HtmlVisitor : public MD::details::HtmlVisitor<MD::QStringTrait> { protected: QString prepareTextForHtml(const QString &t) override { auto tmp = MD::details::HtmlVisitor<MD::QStringTrait>::prepareTextForHtml(t); tmp.replace(QLatin1Char('$'), QStringLiteral("<span>$</span>")); return tmp; } };
In this example we convert $ character to <span>$</span> when inserting string to HTML. This is needed to disable processing of $ character in HTML as start/end of LaTeX equation by some JavaScript, like KaTeX, to prevent wrong rendering of standalone $ character.
MD::details::HtmlVisitor doesn't do this protection, so if in your case you use rendering of LaTeX math equation and enframe them by $ character in HTML, you will need something like the above example.
Member Function Documentation
HtmlVisitor::HtmlVisitor()
Default constructor.
[virtual protected] void HtmlVisitor::closeStyle(const typename ItemWithOpts<Trait>::Styles &styles)
Insert into HTML tags for closing styles.
styles Styles.
[virtual protected] typename Trait::String HtmlVisitor::getId(MD::Item<Trait> *item) const
Returns ID of item if it's set.
item Item.
[virtual protected] typename Trait::String HtmlVisitor::headingIdToHtml(MD::Heading<Trait> *h)
Returns HTML content for heading's ID.
h Heading.
[protected] void HtmlVisitor::onAddLineEnding()
Handle new line in HTML.
[protected] void HtmlVisitor::onAnchor(MD::Anchor<Trait> *a)
Handle anchor.
a Anchor.
[protected] void HtmlVisitor::onBlockquote(MD::Blockquote<Trait> *b)
Handle blockquote.
b Blockquote.
[protected] void HtmlVisitor::onCode(MD::Code<Trait> *c)
Handle code block.
c Code.
[protected] void HtmlVisitor::onFootnoteRef(MD::FootnoteRef<Trait> *ref)
Handle footnote reference.
ref Footnote reference.
[virtual protected] void HtmlVisitor::onFootnotes(const typename Trait::String &footnoteBackLinkContent)
Handle footnotes.
footnoteBackLinkContent String that will be applied as content of back link from footnote. As an example, you can use "<img src="..." />".
[protected] void HtmlVisitor::onHeading(MD::Heading<Trait> *h)
Handle heading.
h Heading.
[virtual protected] void HtmlVisitor::onHeading(MD::Heading<Trait> *h, const typename Trait::String &ht)
Handle heading.
h Heading.
ht Heading tag.
[protected] void HtmlVisitor::onHorizontalLine(MD::HorizontalLine<Trait> *)
Handle horizontal line.
[protected] void HtmlVisitor::onImage(MD::Image<Trait> *i)
Handle image.
i Image.
[protected] void HtmlVisitor::onInlineCode(MD::Code<Trait> *c)
Handle inline code.
c Code.
[protected] void HtmlVisitor::onLineBreak(MD::LineBreak<Trait> *)
Handle line break.
[protected] void HtmlVisitor::onLink(MD::Link<Trait> *l)
Handle link.
l Link.
[protected] void HtmlVisitor::onList(MD::List<Trait> *l)
Handle list.
l List.
[protected] void HtmlVisitor::onListItem(MD::ListItem<Trait> *i, bool first, bool skipOpeningWrap = false)
Handle list item.
i List item.
first Is this item first in the list?
skipOpeningWrap Indicates that opening wrap should be added or no.
[protected] void HtmlVisitor::onMath(MD::Math<Trait> *m)
Handle LaTeX math expression.
m Math.
[protected] void HtmlVisitor::onParagraph(MD::Paragraph<Trait> *p, bool wrap, bool skipOpeningWrap = false)
Handle paragraph.
p Paragraph.
wrap Wrap this paragraph with something or no? It's useful to not wrap standalone paragraph in list item, for example.
skipOpeningWrap Indicates that opening wrap should be added or no.
[protected] void HtmlVisitor::onRawHtml(MD::RawHtml<Trait> *h)
Handle raw HTML.
h Raw HTML.
[protected] void HtmlVisitor::onTable(MD::Table<Trait> *t)
Handle table.
t Table.
[protected] void HtmlVisitor::onText(MD::Text<Trait> *t)
Handle text item.
t Text.
[virtual protected] void HtmlVisitor::openStyle(const typename ItemWithOpts<Trait>::Styles &styles)
Insert into HTML tags for opening styles.
styles Styles.
[virtual protected] typename Trait::String HtmlVisitor::prepareTextForHtml(const typename Trait::String &t)
Prepare text to insert into HTML content.
t String.
[virtual protected] void HtmlVisitor::printId(MD::Item<Trait> *item)
Append ID into HTML.
item Item.
[virtual protected] typename Trait::String HtmlVisitor::tableAlignmentToHtml(typename Table<Trait>::Alignment a)
Returns HTML content for table alignment.
a Alignment.
[virtual] typename Trait::String HtmlVisitor::toHtml(std::shared_ptr<MD::Document<Trait>> doc, const typename Trait::String &footnoteBackLinkContent, bool wrappedInArticle = true, const MD::details::IdsMap<Trait> *idsMap = nullptr)
Walk through the document.
doc Document.
footnoteBackLinkContent String that will be applied as content of back link from footnote. As an example, you can use "<img src="..." />".
wrappedInArticle Wrap HTML with <article> tag?
idsMap Map of IDs to set to corresonding items.
Member Variable Documentation
bool HtmlVisitor::m_dontIncrementFootnoteCount
Just process footnote references and don't increment count number.
typename Trait::template Vector<FootnoteRefStuff> HtmlVisitor::m_fns
Vector of processed footnotes references.
typename Trait::String HtmlVisitor::m_html
HTML content.
const MD::details::IdsMap<Trait> *HtmlVisitor::m_idsMap
Map of IDs to set to corresponding items.
bool HtmlVisitor::m_isWrappedInArticle
Is this HTML wrapped in artcile tag?
bool HtmlVisitor::m_justCollectFootnoteRefs
Just collect footnote references?