1 #include "export-markdown.h"
3 #include "mainwindow.h"
6 extern QString vymName;
7 extern Main *mainWindow;
9 ExportMarkdown::ExportMarkdown()
11 exportName = "Markdown";
12 filter = "TXT (*.txt);;All (* *.*)";
13 caption = vymName + " -" + QObject::tr("Export as Markdown");
16 void ExportMarkdown::doExport()
19 if (!file.open(QIODevice::WriteOnly)) {
20 QMessageBox::critical(
21 0, QObject::tr("Critical Export Error"),
22 QObject::tr("Could not export as Markdown to %1").arg(filePath));
23 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
29 // Main loop over all branches
34 BranchItem *cur = NULL;
35 BranchItem *prev = NULL;
43 model->nextBranch(cur, prev);
45 if (cur->getType() == TreeItem::Branch ||
46 cur->getType() == TreeItem::MapCenter) {
47 // Insert newline after previous list
48 if (cur->depth() < lastDepth)
53 for (i = 1; i < cur->depth() - 1; i++)
54 curIndent += indentPerDepth;
56 curHeading = cur->getHeadingText();
58 // If necessary, write heading as URL
59 if (!cur->getURL().isEmpty())
60 curHeading = "[" + curHeading + "](" + cur->getURL() + ")";
62 if (!cur->hasHiddenExportParent()) {
63 // qDebug() << "ExportMarkdown::
64 // "<<curIndent.toStdString()<<cur->curHeading.toStdString();
67 switch (cur->depth()) {
69 out += underline(curHeading, QString("="));
74 out += (underline(curHeading, QString("-")));
79 out += (curIndent + "### " + curHeading);
84 out += (curIndent + "- " + curHeading);
89 out += (curIndent + "- " + curHeading);
95 // If there is a task, save it for potential later display
96 if (listTasks && cur->getTask()) {
97 tasks.append(QString("[%1]: %2")
98 .arg(cur->getTask()->getStatusString())
102 // If necessary, write vymlink
103 if (!cur->getVymLink().isEmpty())
104 out += (curIndent + dashIndent + cur->getVymLink()) +
107 // If necessary, write note
108 if (!cur->isNoteEmpty()) {
109 // curIndent +=" | ";
110 // Only indent for bullet points
111 if (cur->depth() > 2)
113 out += '\n' + cur->getNoteASCII(curIndent, 80);
115 lastDepth = cur->depth();
118 model->nextBranch(cur, prev);
122 out += "\n\nTasks\n-----\n\n";
124 foreach (QString t, tasks) {
125 out += " - " + t + "\n";
128 QTextStream ts(&file);
129 ts.setCodec("UTF-8");
133 QClipboard *clipboard = QGuiApplication::clipboard();
134 clipboard->setText(out);
136 QString listTasksString = listTasks ? "true" : "false";
138 displayedDestination = filePath;
140 result = ExportBase::Success;
144 args << listTasksString;
146 completeExport(args);
149 QString ExportMarkdown::underline(const QString &text, const QString &line)
151 QString r = text + "\n";
152 for (int j = 0; j < text.length(); j++)