From 81db04b444929dd63b9e233fd727e7ee98c03d02 Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Thu, 4 Apr 2024 13:18:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=AB=AF=E6=9E=84=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WsNovelParser/WsNovelParser.vcxproj.user | 4 ++-- WsNovelParser/htmlprint.cpp | 17 +++++++++----- WsNovelParser/main.cpp | 28 ++++++++++++++++++++++++ libParse/libParse.vcxproj.user | 4 ++-- libSyntax/libSyntax.vcxproj.user | 4 ++-- libToken/libToken.vcxproj.user | 4 ++-- 6 files changed, 47 insertions(+), 14 deletions(-) diff --git a/WsNovelParser/WsNovelParser.vcxproj.user b/WsNovelParser/WsNovelParser.vcxproj.user index 81916ac..b1eb8ad 100644 --- a/WsNovelParser/WsNovelParser.vcxproj.user +++ b/WsNovelParser/WsNovelParser.vcxproj.user @@ -5,9 +5,9 @@ WindowsLocalDebugger - 2024-04-02T15:18:58.9876786Z + 2024-04-04T04:12:24.0605703Z - 2024-04-02T15:18:59.1749926Z + 2024-04-04T04:12:24.5356632Z \ No newline at end of file diff --git a/WsNovelParser/htmlprint.cpp b/WsNovelParser/htmlprint.cpp index a5c0f2f..2f028f9 100644 --- a/WsNovelParser/htmlprint.cpp +++ b/WsNovelParser/htmlprint.cpp @@ -90,6 +90,7 @@ void StoryVolume::buildPageHTML(QDomElement& parent) const { auto dom_title = doc_inst.createElement("h1"); dom_title.appendChild(doc_inst.createTextNode(volume_inst->name())); + dom_volume.appendChild(dom_title); std::function>&)> rich_refer_build = [&](QDomElement& parent_element, const QList> children) { @@ -107,9 +108,10 @@ void StoryVolume::buildPageHTML(QDomElement& parent) const { auto article_inst = std::dynamic_pointer_cast(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_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:{ @@ -146,6 +148,7 @@ void FragmentRef::buildSliceHTML(QDomElement& dom_parent) const { 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"); @@ -153,7 +156,7 @@ 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); std::function>&)> rich_refer_build = @@ -172,9 +175,10 @@ void FragmentRef::buildSliceHTML(QDomElement& dom_parent) const { auto article_inst = std::dynamic_pointer_cast(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_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: @@ -199,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>)> build_cascade = @@ -237,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"); @@ -244,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()) { @@ -271,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()) { diff --git a/WsNovelParser/main.cpp b/WsNovelParser/main.cpp index 27077dd..d72234c 100644 --- a/WsNovelParser/main.cpp +++ b/WsNovelParser/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #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)> html_output = + [](std::shared_ptr 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, int)> tnode_print = [&](std::shared_ptr node, int intend) { auto name = node->element()->signature(); diff --git a/libParse/libParse.vcxproj.user b/libParse/libParse.vcxproj.user index 2634bf7..ca45415 100644 --- a/libParse/libParse.vcxproj.user +++ b/libParse/libParse.vcxproj.user @@ -5,9 +5,9 @@ WindowsLocalDebugger - 2024-04-02T15:18:59.4171377Z + 2024-04-04T04:12:25.1970080Z - 2024-04-02T15:18:59.5628515Z + 2024-04-04T04:12:25.4349434Z \ No newline at end of file diff --git a/libSyntax/libSyntax.vcxproj.user b/libSyntax/libSyntax.vcxproj.user index 0bde9e8..688b412 100644 --- a/libSyntax/libSyntax.vcxproj.user +++ b/libSyntax/libSyntax.vcxproj.user @@ -5,9 +5,9 @@ WindowsLocalDebugger - 2024-04-02T15:18:59.2348615Z + 2024-04-04T04:12:24.7411048Z - 2024-04-02T15:18:59.3520172Z + 2024-04-04T04:12:25.0903609Z \ No newline at end of file diff --git a/libToken/libToken.vcxproj.user b/libToken/libToken.vcxproj.user index e7f4f9c..216f2b5 100644 --- a/libToken/libToken.vcxproj.user +++ b/libToken/libToken.vcxproj.user @@ -2,9 +2,9 @@ - 2024-04-02T15:18:59.6245932Z + 2024-04-04T04:12:25.4971632Z - 2024-04-02T15:18:59.7760855Z + 2024-04-04T04:12:25.6489839Z \ No newline at end of file