Skip to content

Commit

Permalink
in export to html and txt multiple files, append the node id to the f…
Browse files Browse the repository at this point in the history
…ile names to support multiple nodes with the same name
  • Loading branch information
giuspen committed Jun 7, 2022
1 parent 446f5cc commit e5aefb4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/ct/ct_export2html.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void CtExport2Html::node_export_to_html(CtTreeIter tree_iter, const CtExportOpti
}
std::vector<Glib::ustring> html_slots;
std::vector<CtAnchoredWidget*> widgets;
if (tree_iter.get_node_is_rich_text()) {
if (tree_iter.get_node_is_text()) {
Glib::ustring node_html_text;
_html_get_from_treestore_node(tree_iter, sel_start, sel_end, html_slots, widgets);
int images_count{0};
Expand Down Expand Up @@ -223,7 +223,7 @@ void CtExport2Html::nodes_all_export_to_single_html(bool all_tree, const CtExpor
html_text += "<h1 class='title level-" + std::to_string(node_level) + "'>" + tree_iter.get_node_name() + "</h1><br/>";
std::vector<Glib::ustring> html_slots;
std::vector<CtAnchoredWidget*> widgets;
if (tree_iter.get_node_is_rich_text()) {
if (tree_iter.get_node_is_text()) {
Glib::ustring node_html_text;
_html_get_from_treestore_node(tree_iter, -1, -1, html_slots, widgets);
int images_count = 0;
Expand Down Expand Up @@ -746,7 +746,8 @@ Glib::ustring CtExport2Html::_get_object_alignment_string(Glib::ustring alignmen
// Get the HTML page filename given the tree iter
Glib::ustring CtExport2Html::_get_html_filename(CtTreeIter tree_iter)
{
Glib::ustring name = CtMiscUtil::get_node_hierarchical_name(tree_iter, "--", true, true, ".html");
Glib::ustring name = CtMiscUtil::get_node_hierarchical_name(tree_iter, "--"/*separator*/,
true/*for_filename*/, true/*root_to_leaf*/, true/*trail_node_id*/, ".html"/*trailer*/);
return str::replace(name, "#", "~");
}

Expand Down
9 changes: 5 additions & 4 deletions src/ct/ct_export2txt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ void CtExport2Txt::nodes_all_export_to_txt(bool all_tree, fs::path export_dir, f
Glib::ustring tree_plain_text;
std::function<void(CtTreeIter)> traverseFunc;
traverseFunc = [this, &traverseFunc, &export_options, &tree_plain_text, &export_dir](CtTreeIter tree_iter) {
if (export_dir == "")
if (export_dir.empty()) {
tree_plain_text += node_export_to_txt(tree_iter, "", export_options, -1, -1);
else
{
fs::path filepath = export_dir / (CtMiscUtil::get_node_hierarchical_name(tree_iter) + ".txt");
}
else {
fs::path filepath = export_dir / CtMiscUtil::get_node_hierarchical_name(tree_iter, "--"/*separator*/,
true/*for_filename*/, true/*root_to_leaf*/, true/*trail_node_id*/, ".txt"/*trailer*/);
node_export_to_txt(tree_iter, filepath, export_options, -1, -1);
}
for (auto& child: tree_iter->children())
Expand Down
11 changes: 8 additions & 3 deletions src/ct/ct_misc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ bool CtMiscUtil::node_siblings_sort_iteration(Glib::RefPtr<Gtk::TreeStore> model
}

//"""Get the Node Hierarchical Name"""
std::string CtMiscUtil::get_node_hierarchical_name(CtTreeIter tree_iter, const char* separator/*="--"*/,
bool for_filename/*=true*/, bool root_to_leaf/*=true*/, const char* trailer/*=""*/)
std::string CtMiscUtil::get_node_hierarchical_name(const CtTreeIter tree_iter, const char* separator/*="--"*/,
const bool for_filename/*=true*/, const bool root_to_leaf/*=true*/,
const bool trail_node_id/*=false*/, const char* trailer/*=""*/)
{
std::string hierarchical_name = str::trim(tree_iter.get_node_name());
CtTreeIter father_iter = tree_iter.parent();
Expand All @@ -227,8 +228,12 @@ std::string CtMiscUtil::get_node_hierarchical_name(CtTreeIter tree_iter, const c
hierarchical_name = hierarchical_name + separator + father_name;
father_iter = father_iter.parent();
}
if (trailer)
if (trail_node_id) {
hierarchical_name += str::format("_{:d}", tree_iter.get_node_id());
}
if (trailer) {
hierarchical_name += trailer;
}
if (for_filename) {
hierarchical_name = clean_from_chars_not_for_filename(hierarchical_name);
if (hierarchical_name.size() > (size_t)CtConst::MAX_FILE_NAME_LEN)
Expand Down
5 changes: 3 additions & 2 deletions src/ct/ct_misc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ void filepath_extension_fix(const CtDocType ctDocType, const CtDocEncrypt ctDocE
bool node_siblings_sort_iteration(Glib::RefPtr<Gtk::TreeStore> model, const Gtk::TreeNodeChildren& children,
std::function<bool(Gtk::TreeIter&, Gtk::TreeIter&)> need_swap);

std::string get_node_hierarchical_name(CtTreeIter tree_iter, const char* separator="--",
bool for_filename=true, bool root_to_leaf=true, const char* trailer="");
std::string get_node_hierarchical_name(const CtTreeIter tree_iter, const char* separator="--",
const bool for_filename=true, const bool root_to_leaf=true,
const bool trail_node_id=false, const char* trailer="");

std::string clean_from_chars_not_for_filename(std::string filename);

Expand Down
2 changes: 1 addition & 1 deletion tests/data_данные/test.export.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<link rel="stylesheet" href="res/styles4.css" type="text/css" />
</head>
<body>
<div class='page'><h1 class='title level-1'>йцукенгшщз</h1><br/><pre>ciao plain<br />йцукенгшщз</pre></div><div class='page'><h1 class='title level-1'>b</h1><br/><p>ciao rich</p><p><span style="color:#ff0000;">fore</span></p><p><span style="background-color:#e6e6fa;">back</span></p><p><strong>bold</strong></p><p><em>italic</em></p><p><span style="text-decoration:underline;">under</span></p><p><span style="text-decoration:line-through;">strike</span></p><p><h1>h1</h1></p><p><h2>h2</h2></p><p><h3>h3</h3></p><p><h4>h4</h4></p><p><h5>h5</h5></p><p><h6>h6</h6></p><p><small>small</small></p><p><span style="indent:1;">a</span><sup><span style="indent:1;">super</span></sup></p><p><span style="indent:2;">a</span><sub><span style="indent:2;">sub</span></sub></p><p><code>mono</code></p></div><div class='page'><h1 class='title level-2'>c</h1><br/><pre><span style="color:#7f0044;font-weight:400">int</span> main(<span style="color:#7f0044;font-weight:400">int</span> argc, <span style="color:#7f0044;font-weight:400">char</span> *argv[])<br />{<br /> <span style="color:#ff9d00;font-weight:700">return</span> <span style="color:#ff0044;font-weight:400">0</span>;<br />}<br /></pre></div><div class='page'><h1 class='title level-2'>sh</h1><br/><pre><span style="color:#ff9d00;font-weight:700">echo</span> <span style="color:#3ad900;font-weight:400">&quot;ciao!&quot;</span></pre></div><div class='page'><h1 class='title level-3'>html</h1><br/><pre><span style="color:#7f0044;font-weight:400">&lt;head&gt;</span><br /><span style="color:#7f0044;font-weight:400">&lt;title&gt;</span>NO<span style="color:#7f0044;font-weight:400">&lt;/title&gt;</span><br /><span style="color:#7f0044;font-weight:400">&lt;/head&gt;</span></pre></div><div class='page'><h1 class='title level-3'>xml</h1><br/><pre>&lt;?xml <span style="color:#333333;font-weight:400">version=</span><span style="color:#3ad900;font-weight:400">&quot;1.0&quot;</span> <span style="color:#333333;font-weight:400">encoding=</span><span style="color:#3ad900;font-weight:400">&quot;UTF-8&quot;</span>?&gt;</pre></div><div class='page'><h1 class='title level-2'>py</h1><br/><pre><span style="color:#ff9d00;font-weight:700">print</span>(<span style="color:#3ad900;font-weight:400">&quot;ciao!&quot;</span>)</pre></div><div class='page'><h1 class='title level-1'>d</h1><br/><p>second rich</p></div><div class='page'><h1 class='title level-1'>e</h1><br/><p>anchored widgets:</p><p></p><p>codebox:</p><p><div class="codebox"><pre><span style="color:#ff9d00;font-weight:700">def</span> <span style="color:#333333;font-weight:400">test_function</span>:<br /> <span style="color:#ff9d00;font-weight:700">print</span> <span style="color:#3ad900;font-weight:400">&quot;hi there йцукенгшщз&quot;</span></pre></div></p><p></p><p>anchor:</p><p><a name="йцукенгшщз"></a></p><p></p><p>table:</p><p><table class="table"><tr><th>h1</th><th>h2</th></tr><tr><td>йцукенгшщз</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table></p><p></p><p>image:</p><p><a href="http://www.ansa.it"><img src="images/5-1.png" alt="images/5-1.png" /></a></p><p></p><p>embedded file:</p><p><table style="display:inline-table"><tr><td><a href="EmbeddedFiles/5-йцукенгшщз.txt">Linked file: йцукенгшщз.txt </a></td></tr></table></p><p></p><p>latex equation:</p><p><img src="images/5-2.png" alt="images/5-2.png" /></p><p></p><p><a href="http://www.ansa.it">link to web ansa.it</a></p><p><a href="d.html">link to node ‘d’</a></p><p><a href="e.html#йцукенгшщз">link to node ‘e’ + anchor</a></p><p><a href="file:///etc">link to folder /etc</a></p><p><a href="file:///etc/fstab">link to file /etc/fstab</a></p></div>
<div class='page'><h1 class='title level-1'>йцукенгшщз</h1><br/><p>ciao plain</p><p>йцукенгшщз</p></div><div class='page'><h1 class='title level-1'>b</h1><br/><p>ciao rich</p><p><span style="color:#ff0000;">fore</span></p><p><span style="background-color:#e6e6fa;">back</span></p><p><strong>bold</strong></p><p><em>italic</em></p><p><span style="text-decoration:underline;">under</span></p><p><span style="text-decoration:line-through;">strike</span></p><p><h1>h1</h1></p><p><h2>h2</h2></p><p><h3>h3</h3></p><p><h4>h4</h4></p><p><h5>h5</h5></p><p><h6>h6</h6></p><p><small>small</small></p><p><span style="indent:1;">a</span><sup><span style="indent:1;">super</span></sup></p><p><span style="indent:2;">a</span><sub><span style="indent:2;">sub</span></sub></p><p><code>mono</code></p></div><div class='page'><h1 class='title level-2'>c</h1><br/><pre><span style="color:#7f0044;font-weight:400">int</span> main(<span style="color:#7f0044;font-weight:400">int</span> argc, <span style="color:#7f0044;font-weight:400">char</span> *argv[])<br />{<br /> <span style="color:#ff9d00;font-weight:700">return</span> <span style="color:#ff0044;font-weight:400">0</span>;<br />}<br /></pre></div><div class='page'><h1 class='title level-2'>sh</h1><br/><pre><span style="color:#ff9d00;font-weight:700">echo</span> <span style="color:#3ad900;font-weight:400">&quot;ciao!&quot;</span></pre></div><div class='page'><h1 class='title level-3'>html</h1><br/><pre><span style="color:#7f0044;font-weight:400">&lt;head&gt;</span><br /><span style="color:#7f0044;font-weight:400">&lt;title&gt;</span>NO<span style="color:#7f0044;font-weight:400">&lt;/title&gt;</span><br /><span style="color:#7f0044;font-weight:400">&lt;/head&gt;</span></pre></div><div class='page'><h1 class='title level-3'>xml</h1><br/><pre>&lt;?xml <span style="color:#333333;font-weight:400">version=</span><span style="color:#3ad900;font-weight:400">&quot;1.0&quot;</span> <span style="color:#333333;font-weight:400">encoding=</span><span style="color:#3ad900;font-weight:400">&quot;UTF-8&quot;</span>?&gt;</pre></div><div class='page'><h1 class='title level-2'>py</h1><br/><pre><span style="color:#ff9d00;font-weight:700">print</span>(<span style="color:#3ad900;font-weight:400">&quot;ciao!&quot;</span>)</pre></div><div class='page'><h1 class='title level-1'>d</h1><br/><p>second rich</p></div><div class='page'><h1 class='title level-1'>e</h1><br/><p>anchored widgets:</p><p></p><p>codebox:</p><p><div class="codebox"><pre><span style="color:#ff9d00;font-weight:700">def</span> <span style="color:#333333;font-weight:400">test_function</span>:<br /> <span style="color:#ff9d00;font-weight:700">print</span> <span style="color:#3ad900;font-weight:400">&quot;hi there йцукенгшщз&quot;</span></pre></div></p><p></p><p>anchor:</p><p><a name="йцукенгшщз"></a></p><p></p><p>table:</p><p><table class="table"><tr><th>h1</th><th>h2</th></tr><tr><td>йцукенгшщз</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table></p><p></p><p>image:</p><p><a href="http://www.ansa.it"><img src="images/5-1.png" alt="images/5-1.png" /></a></p><p></p><p>embedded file:</p><p><table style="display:inline-table"><tr><td><a href="EmbeddedFiles/5-йцукенгшщз.txt">Linked file: йцукенгшщз.txt </a></td></tr></table></p><p></p><p>latex equation:</p><p><img src="images/5-2.png" alt="images/5-2.png" /></p><p></p><p><a href="http://www.ansa.it">link to web ansa.it</a></p><p><a href="d_4.html">link to node ‘d’</a></p><p><a href="e_5.html#йцукенгшщз">link to node ‘e’ + anchor</a></p><p><a href="file:///etc">link to folder /etc</a></p><p><a href="file:///etc/fstab">link to file /etc/fstab</a></p></div>
</body>
</html>

0 comments on commit e5aefb4

Please sign in to comment.