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 = "Markdown (*.md);;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()) {
70 out += ("# " + curHeading);
75 out += ("## " + curHeading);
80 out += ("### " + curHeading);
85 out += ("#### " + curHeading);
90 out += ("##### " + curHeading);
95 out += ("###### " + curHeading);
100 out += (curIndent + "- " + curHeading);
106 // If there is a task, save it for potential later display
107 if (listTasks && cur->getTask()) {
108 tasks.append(QString("[%1]: %2")
109 .arg(cur->getTask()->getStatusString())
113 // If necessary, write vymlink
114 if (!cur->getVymLink().isEmpty())
115 out += (curIndent + dashIndent + cur->getVymLink()) +
118 // If necessary, write note
119 if (!cur->isNoteEmpty()) {
120 // curIndent +=" | ";
121 // Only indent for bullet points
122 if (cur->depth() > 2)
124 out += '\n' + cur->getNoteASCII(curIndent, 80);
126 lastDepth = cur->depth();
129 model->nextBranch(cur, prev);
133 out += "\n\nTasks\n-----\n\n";
135 foreach (QString t, tasks) {
136 out += " - " + t + "\n";
139 QTextStream ts(&file);
140 ts.setCodec("UTF-8");
144 QClipboard *clipboard = QGuiApplication::clipboard();
145 clipboard->setText(out);
147 QString listTasksString = listTasks ? "true" : "false";
149 displayedDestination = filePath;
151 result = ExportBase::Success;
155 args << listTasksString;
157 completeExport(args);
160 QString ExportMarkdown::underline(const QString &text, const QString &line)
162 QString r = text + "\n";
163 for (int j = 0; j < text.length(); j++)