X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=src%2Fexport-ascii.cpp;h=fa4019ee973d42274103abc5074915755fe5d5b2;hb=HEAD;hp=d26f31edb8bc75e54da5866146625478a4afb742;hpb=91d5bdcaff9c6ccbf8a4e2154bfda353e382d057;p=sven%2Fvym.git diff --git a/src/export-ascii.cpp b/src/export-ascii.cpp index d26f31e..fa4019e 100644 --- a/src/export-ascii.cpp +++ b/src/export-ascii.cpp @@ -47,8 +47,8 @@ void ExportASCII::doExport() // "<getHeadingPlain().toStdString(); // Insert newline after previous list - if (cur->depth() < lastDepth) - out += "\n"; + //if (cur->depth() < lastDepth) + // out += "\n"; // Make indentstring curIndent = ""; @@ -58,24 +58,32 @@ void ExportASCII::doExport() dashIndent = ""; switch (cur->depth()) { case 0: + if (!out.isEmpty()) + // Add extra line breaks for 2nd, 3rd, ... MapCenter + ensureEmptyLines(out, 2); out += underline(cur->getHeadingPlain(), QString("=")); - out += "\n"; + + // Empty line below "====" of MapCenters + ensureEmptyLines(out, 1); + dashIndent = ""; // No indention for notes in MapCenter break; case 1: - out += "\n"; + ensureNewLine(out); out += (underline(getSectionString(cur) + - cur->getHeadingPlain(), - QString("-"))); - out += "\n"; + cur->getHeadingPlain(), + QString("-"))); + // Empty line below "----" of MainBranches + ensureEmptyLines(out, 1); + dashIndent = ""; // No indention for notes in MainBranch break; - case 3: - out += (curIndent + "- " + cur->getHeadingPlain()); - out += "\n"; + case 2: + ensureNewLine(out); + out += (curIndent + "* " + cur->getHeadingPlain()); dashIndent = " "; break; default: + ensureNewLine(out); out += (curIndent + "- " + cur->getHeadingPlain()); - out += "\n"; dashIndent = " "; break; } @@ -88,21 +96,27 @@ void ExportASCII::doExport() } // If necessary, write URL - if (!cur->getURL().isEmpty()) + if (!cur->getURL().isEmpty()) { + ensureNewLine(out); out += (curIndent + dashIndent + cur->getURL()) + "\n"; + } // If necessary, write vymlink - if (!cur->getVymLink().isEmpty()) + if (!cur->getVymLink().isEmpty()) { + ensureNewLine(out); out += (curIndent + dashIndent + cur->getVymLink()) + " (vym mindmap)\n"; + } // If necessary, write note if (!cur->isNoteEmpty()) { - // curIndent +=" | "; - // Only indent for bullet points - if (cur->depth() > 2) - curIndent += " "; - out += '\n' + cur->getNoteASCII(curIndent, 80); + // Add at least one empty line before note + ensureEmptyLines(out, 1); + + // Add note and empty line after note + out += cur->getNoteASCII(curIndent + dashIndent, 80); + + ensureEmptyLines(out, 1); } lastDepth = cur->depth(); } @@ -146,3 +160,31 @@ QString ExportASCII::underline(const QString &text, const QString &line) r += line; return r; } + +QString ExportASCII::ensureEmptyLines(QString &text, int n) +{ + // Ensure at least n empty lines at the end of text + + // First count trailing line breaks + int j = 0; + int i = text.count() - 1; + while (i > -1 && text.at(i) == "\n") { + i--; + j++; + } + + while (j < n + 1) { + text = text + "\n"; + j++; + } + + return text; +} + +QString ExportASCII::ensureNewLine(QString &text) +{ + // Add one line break, if not already there yet e.g. from empty line + if (!text.endsWith("\n")) + text += "\n"; + return text; +}