Simple markdown converter.

This commit is contained in:
James Grogan 2022-12-01 18:38:46 +00:00
parent ec11529b9a
commit 650cfa5c6f
5 changed files with 410 additions and 9 deletions

View file

@ -43,9 +43,35 @@ std::unique_ptr<HtmlDocument> MarkdownConverter::convert(MarkdownDocument* markd
html_text->setText(child->getTextContent());
html_p_element->addChild(std::move(html_text));
}
else if(child->getType() == MarkdownElement::Type::LINK)
{
auto link_element = dynamic_cast<MarkdownLink*>(child);
auto html_text = std::make_unique<HtmlHyperlinkElement>(link_element->getTarget());
html_text->setText(link_element->getTextContent());
html_p_element->addChild(std::move(html_text));
}
else if(child->getType() == MarkdownElement::Type::IMAGE)
{
auto link_element = dynamic_cast<MarkdownImage*>(child);
auto html_text = std::make_unique<HtmlImageElement>(link_element->getSource(), link_element->getAlt());
html_p_element->addChild(std::move(html_text));
}
}
html_doc->addElementToBody(std::move(html_p_element));
}
else if(md_element->getType() == MarkdownElement::Type::BULLET_LIST)
{
auto list_element = dynamic_cast<MarkdownBulletList*>(md_element);
auto html_list = std::make_unique<HtmlUnorderedList>();
for(unsigned idx=0; idx< list_element->getNumChildren(); idx++)
{
auto child = list_element->getChild(idx);
auto html_list_item = std::make_unique<HtmlListItem>();
html_list_item->setText(child->getTextContent());
html_list->addChild(std::move(html_list_item));
}
html_doc->addElementToBody(std::move(html_list));
}
else if(md_element->getType() == MarkdownElement::Type::MULTILINE_QUOTE)
{
auto html_quote = std::make_unique<HtmlCodeElement>();