Compare commits

...

2 Commits

Author SHA1 Message Date
codeboss 81db04b444 输出端构成 2024-04-04 13:18:44 +08:00
codeboss 77aa450258 2html 构建 2024-04-03 17:09:26 +08:00
6 changed files with 129 additions and 36 deletions

View File

@ -5,9 +5,9 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-04-02T15:18:58.9876786Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-04T04:12:24.0605703Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-04-02T15:18:59.1749926Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-04T04:12:24.5356632Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>

View File

@ -80,8 +80,52 @@ 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()));
dom_volume.appendChild(dom_title);
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() + u8"{"));
article_group.appendChild(article_head);
rich_refer_build(article_group, child->children());
article_group.appendChild(doc_ins.createTextNode(u8"}"));
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,13 +141,14 @@ 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();
auto dom_reference = doc.createElement(u8"div");
dom_reference.setAttribute("id", QString::number((qulonglong)refer_element.get()));
dom_parent.appendChild(dom_reference);
auto dom_title = doc.createElement(u8"h2");
@ -111,18 +156,38 @@ void FragmentRef::buildSliceHTML(QDomElement& dom_parent) const {
auto dom_href = doc.createElement(u8"a");
dom_href.appendChild(doc.createTextNode(refer_element->referSignature()));
dom_href.setAttribute("href", jump_to_host);
dom_href.setAttribute("href", u8"file:///"+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() + u8"{"));
article_group.appendChild(article_head);
rich_refer_build(article_group, child->children());
article_group.appendChild(doc_ins.createTextNode(u8"}"));
parent_element.appendChild(article_group);
}break;
default:
break;
}
}
};
rich_refer_build(dom_reference, syntax_access->children());
}
void FragmentRef::buildPageHTML(QDomElement& parent) const {
@ -138,7 +203,7 @@ void FragmentRef::buildPageHTML(QDomElement& parent) const {
refers_dom.appendChild(title_block);
auto title_refer = doc.createElement(u8"a");
title_refer.appendChild(doc.createTextNode(refer_element->signature()));
title_refer.setAttribute("href", this->sliceRefers());
title_refer.setAttribute("href", u8"file:///"+this->sliceRefers());
title_block.appendChild(title_refer);
std::function<void(QList<std::shared_ptr<const ast_gen::ElementAccess>>)> build_cascade =
@ -176,6 +241,7 @@ void Fragment::buildSliceHTML(QDomElement& parent) const {
auto doc = parent.ownerDocument();
auto dom_fragment = doc.createElement("div");
dom_fragment.setAttribute("id", QString::number((qulonglong)fragment_inst.get()));
parent.appendChild(dom_fragment);
auto dom_title = doc.createElement("h2");
@ -183,7 +249,7 @@ void Fragment::buildSliceHTML(QDomElement& parent) const {
auto dom_href = doc.createElement("a");
dom_href.appendChild(doc.createTextNode(fragment_inst->name()));
dom_href.setAttribute("href", this->pageRefers());
dom_href.setAttribute("href", u8"file:///"+this->pageRefers());
dom_title.appendChild(dom_href);
for (auto& inst_c : syntax_access->children()) {
@ -210,7 +276,7 @@ void Fragment::buildPageHTML(QDomElement& parent) const {
auto dom_href = doc.createElement("a");
dom_href.appendChild(doc.createTextNode(fragment_inst->signature()));
dom_href.setAttribute("href", this->pageRefers());
dom_href.setAttribute("href", u8"file:///" + this->sliceRefers());
dom_title.appendChild(dom_href);
for (auto& inst_c : syntax_access->children()) {
@ -225,7 +291,6 @@ void Fragment::buildPageHTML(QDomElement& parent) const {
for (auto& it : this->additionals()) {
it->buildPageHTML(dom_fragment);
}
}
#include <ast_novel.h>
@ -327,7 +392,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");

View File

@ -8,6 +8,7 @@
#include <syntax_novel.h>
#include <tokens_novel.h>
#include <QDir>
#include <QTextStream>
#include "novelparser.h"
#include "htmlprint.h"
@ -32,6 +33,33 @@ int main(int argc, char* argv[]) {
tool.storylines_anchors_define(tool.storyline_defines.values(), QDir::current());
tool.volumes_anchors_define(tool.volume_defines.values(), QDir::current());
std::function<void(std::shared_ptr<const printer::Access>)> html_output =
[](std::shared_ptr<const printer::Access> inst) {
auto target_path = inst->pageRefers();
QFile tfile(target_path);
if (tfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QDomDocument doc_inst(QDomImplementation().createDocumentType(u8"html", QString(), QString()));
auto html = doc_inst.createElement(u8"html");
doc_inst.appendChild(html);
auto body = doc_inst.createElement(u8"body");
html.appendChild(body);
inst->buildPageHTML(body);
QTextStream tout(&tfile);
doc_inst.save(tout, 2);
tout.flush();
}
};
for (auto& node : tool.fragment_defines)
html_output(node);
for (auto& node : tool.storyline_defines)
html_output(node);
for (auto& node : tool.volume_defines)
html_output(node);
std::function<void(std::shared_ptr<const ast_gen::ElementAccess>, int)> tnode_print =
[&](std::shared_ptr<const ast_gen::ElementAccess> node, int intend) {
auto name = node->element()->signature();

View File

@ -5,9 +5,9 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-04-02T15:18:59.4171377Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-04T04:12:25.1970080Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-04-02T15:18:59.5628515Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-04T04:12:25.4349434Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>

View File

@ -5,9 +5,9 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-04-02T15:18:59.2348615Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-04T04:12:24.7411048Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-04-02T15:18:59.3520172Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-04T04:12:25.0903609Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>

View File

@ -2,9 +2,9 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-04-02T15:18:59.6245932Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-04T04:12:25.4971632Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-04-02T15:18:59.7760855Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2024-04-04T04:12:25.6489839Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>