2html 构建
This commit is contained in:
parent
781ef50253
commit
77aa450258
|
@ -80,8 +80,50 @@ void StoryLine::buildPageHTML(QDomElement& parent) const {
|
|||
|
||||
StoryVolume::StoryVolume(std::shared_ptr<const ast_gen::ElementAccess> handle) : Group(handle) {}
|
||||
|
||||
void StoryVolume::buildPageHTML(QDomElement& doc) const
|
||||
{
|
||||
void StoryVolume::buildPageHTML(QDomElement& parent) const {
|
||||
auto syntax_access = this->accessPeers();
|
||||
auto volume_inst = std::dynamic_pointer_cast<const VolumeDefine>(syntax_access->element());
|
||||
|
||||
auto doc_inst = parent.ownerDocument();
|
||||
auto dom_volume = doc_inst.createElement("div");
|
||||
parent.appendChild(dom_volume);
|
||||
|
||||
auto dom_title = doc_inst.createElement("h1");
|
||||
dom_title.appendChild(doc_inst.createTextNode(volume_inst->name()));
|
||||
|
||||
std::function<void(QDomElement&, const QList<std::shared_ptr<const ast_gen::ElementAccess>>&)> rich_refer_build =
|
||||
[&](QDomElement& parent_element, const QList<std::shared_ptr<const ast_gen::ElementAccess>> children) {
|
||||
for (auto& child : children) {
|
||||
auto doc_ins = parent_element.ownerDocument();
|
||||
switch ((NovelNode)child->element()->typeMark())
|
||||
{
|
||||
case NovelNode::TextSection: {
|
||||
auto text_inst = std::dynamic_pointer_cast<const TextSection>(child->element());
|
||||
auto dom_p = doc_ins.createElement("p");
|
||||
dom_p.appendChild(doc_ins.createTextNode(text_inst->content()));
|
||||
parent_element.appendChild(dom_p);
|
||||
}break;
|
||||
case NovelNode::ArticleDefine: {
|
||||
auto article_inst = std::dynamic_pointer_cast<const ArticleDefine>(child->element());
|
||||
auto article_group = doc_ins.createElement("div");
|
||||
auto article_head = doc_ins.createElement("h2");
|
||||
article_head.appendChild(doc_ins.createTextNode(article_inst->name()));
|
||||
article_group.appendChild(article_head);
|
||||
rich_refer_build(article_group, child->children());
|
||||
parent_element.appendChild(article_group);
|
||||
}break;
|
||||
case NovelNode::FragmentRefer:{
|
||||
auto fragment_inst = std::dynamic_pointer_cast<const FragmentRefers>(child->element());
|
||||
auto refer_inst = this->getElement(fragment_inst->signature());
|
||||
refer_inst->buildSliceHTML(parent_element);
|
||||
}break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
rich_refer_build(dom_volume, syntax_access->children());
|
||||
}
|
||||
|
||||
FragmentRef::FragmentRef(std::shared_ptr<const ast_gen::ElementAccess> handle) : Element(handle) {}
|
||||
|
@ -97,8 +139,8 @@ std::shared_ptr<Fragment> printer::FragmentRef::hostFragment() const
|
|||
}
|
||||
|
||||
void FragmentRef::buildSliceHTML(QDomElement& dom_parent) const {
|
||||
auto syntax_element = this->accessPeers()->element();
|
||||
auto refer_element = std::dynamic_pointer_cast<const FragmentRefers>(syntax_element);
|
||||
auto syntax_access = this->accessPeers();
|
||||
auto refer_element = std::dynamic_pointer_cast<const FragmentRefers>(syntax_access->element());
|
||||
|
||||
auto jump_to_host = this->hostFragment()->pageRefers();
|
||||
auto doc = dom_parent.ownerDocument();
|
||||
|
@ -114,15 +156,34 @@ void FragmentRef::buildSliceHTML(QDomElement& dom_parent) const {
|
|||
dom_href.setAttribute("href", jump_to_host);
|
||||
dom_title.appendChild(dom_href);
|
||||
|
||||
for (auto child : this->accessPeers()->children()) {
|
||||
if (child->element()->typeMark() == (int)NovelNode::TextSection) {
|
||||
std::function<void(QDomElement&, const QList<std::shared_ptr<const ast_gen::ElementAccess>>&)> rich_refer_build =
|
||||
[&](QDomElement& parent_element, const QList<std::shared_ptr<const ast_gen::ElementAccess>> children) {
|
||||
for (auto& child : children) {
|
||||
auto doc_ins = parent_element.ownerDocument();
|
||||
switch ((NovelNode)child->element()->typeMark())
|
||||
{
|
||||
case NovelNode::TextSection: {
|
||||
auto text_inst = std::dynamic_pointer_cast<const TextSection>(child->element());
|
||||
auto dom_p = doc.createElement("p");
|
||||
dom_p.appendChild(doc.createTextNode(text_inst->content()));
|
||||
dom_reference.appendChild(dom_p);
|
||||
auto dom_p = doc_ins.createElement("p");
|
||||
dom_p.appendChild(doc_ins.createTextNode(text_inst->content()));
|
||||
parent_element.appendChild(dom_p);
|
||||
}break;
|
||||
case NovelNode::ArticleDefine: {
|
||||
auto article_inst = std::dynamic_pointer_cast<const ArticleDefine>(child->element());
|
||||
auto article_group = doc_ins.createElement("div");
|
||||
auto article_head = doc_ins.createElement("h2");
|
||||
article_head.appendChild(doc_ins.createTextNode(article_inst->name()));
|
||||
article_group.appendChild(article_head);
|
||||
rich_refer_build(article_group, child->children());
|
||||
parent_element.appendChild(article_group);
|
||||
}break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
rich_refer_build(dom_reference, syntax_access->children());
|
||||
}
|
||||
|
||||
void FragmentRef::buildPageHTML(QDomElement& parent) const {
|
||||
|
@ -225,7 +286,6 @@ void Fragment::buildPageHTML(QDomElement& parent) const {
|
|||
for (auto& it : this->additionals()) {
|
||||
it->buildPageHTML(dom_fragment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <ast_novel.h>
|
||||
|
@ -327,7 +387,7 @@ std::function<void(const QList<std::shared_ptr<Element>>&, const QString&)> refe
|
|||
auto element_addr = QString::number((qulonglong)item->accessPeers()->element().get());
|
||||
item->setSliceRefer(summary_href + u8"#" + element_addr);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
void tools_printer::storylines_anchors_define(const QList<std::shared_ptr<StoryLine>>& list, const QDir& root_dir) {
|
||||
auto path = root_dir.filePath("storylines");
|
||||
|
|
Loading…
Reference in New Issue